|
| 1 | +# SPDX-FileCopyrightText: 2025 Howetuft |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | + |
| 6 | +name: LuxCore Samples Builder |
| 7 | + |
| 8 | +on: |
| 9 | + workflow_dispatch: |
| 10 | + workflow_call: |
| 11 | + inputs: |
| 12 | + repository: |
| 13 | + description: 'Repository to check out' |
| 14 | + required: false |
| 15 | + default: '' |
| 16 | + type: string |
| 17 | + ref: |
| 18 | + description: 'The branch, tag or SHA to checkout.' |
| 19 | + required: false |
| 20 | + default: '' |
| 21 | + type: string |
| 22 | + version: |
| 23 | + description: 'The version to build - must comply to semver, or blank for default' |
| 24 | + type: string |
| 25 | + outputs: |
| 26 | + commit: |
| 27 | + description: "The commit that has been checked out" |
| 28 | + value: ${{ jobs.build-samples.outputs.commit }} |
| 29 | + branch: |
| 30 | + description: "The branch that has been checked out" |
| 31 | + value: ${{ jobs.build-samples.outputs.branch }} |
| 32 | + attestation-url: |
| 33 | + description: "The url to the attestations" |
| 34 | + value: ${{ jobs.attest-samples.outputs.attestation-url }} |
| 35 | + version: |
| 36 | + description: "The version actually built" |
| 37 | + value: ${{ jobs.build-samples.outputs.version }} |
| 38 | + |
| 39 | +jobs: |
| 40 | + build-samples: |
| 41 | + name: Build samples ${{ matrix.os }} |
| 42 | + runs-on: ${{ matrix.os }} |
| 43 | + strategy: |
| 44 | + fail-fast: false |
| 45 | + matrix: |
| 46 | + os: [ubuntu-latest, windows-latest, macos-13, macos-14] |
| 47 | + env: |
| 48 | + BUILD_TYPE: Release |
| 49 | + #CXX_VERSION: 20 |
| 50 | + #GCC_VERSION: 14 |
| 51 | + #GLIBC_VERSION: 2_28 |
| 52 | + PYTHON_MINOR: ${{ matrix.python-minor }} |
| 53 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 54 | + OWNER: ${{ github.repository_owner }} |
| 55 | + REPO: ${{ github.event.repository.name }} |
| 56 | + outputs: |
| 57 | + commit: ${{ steps.current-commit.outputs.commit }} |
| 58 | + branch: ${{ steps.current-commit.outputs.branch }} |
| 59 | + version: ${{ steps.output-version.outputs.version }} |
| 60 | + |
| 61 | + steps: |
| 62 | + |
| 63 | + - name: Configure git for long paths |
| 64 | + shell: bash |
| 65 | + if: runner.os == 'Windows' |
| 66 | + run: git config --system core.longpaths true |
| 67 | + |
| 68 | + - name: Checkout main repository (standard context) |
| 69 | + if: ${{ !env.ACT }} |
| 70 | + uses: actions/checkout@v4 |
| 71 | + with: |
| 72 | + repository: ${{ inputs.repository }} |
| 73 | + ref: ${{ inputs.ref }} |
| 74 | + |
| 75 | + - name: Checkout main repository (act context) |
| 76 | + if: env.ACT |
| 77 | + uses: actions/checkout@v4 |
| 78 | + |
| 79 | + - name: Get current commit |
| 80 | + id: current-commit |
| 81 | + run: | |
| 82 | + echo "commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT |
| 83 | + echo "branch=$(git symbolic-ref HEAD)" >> $GITHUB_OUTPUT |
| 84 | + echo "commit=$(git rev-parse HEAD)" |
| 85 | + echo "branch=$(git symbolic-ref HEAD)" |
| 86 | +
|
| 87 | + - name: Output version |
| 88 | + id: output-version |
| 89 | + shell: python |
| 90 | + run: | |
| 91 | + import os |
| 92 | + import json |
| 93 | + from pathlib import Path |
| 94 | +
|
| 95 | + if (input_version := "${{ inputs.release-version }}"): |
| 96 | + version = input_version |
| 97 | + else: |
| 98 | + # Fall back to default |
| 99 | + build_settings_file = Path("build-system", "build-settings.json") |
| 100 | + with open(build_settings_file) as in_file: |
| 101 | + default_version = json.load(in_file)["DefaultVersion"] |
| 102 | + version = ".".join(default_version[i] for i in ("major", "minor", "patch")) |
| 103 | + if (prerelease := default_version["prerelease"]): |
| 104 | + version = f"{version}-{prerelease}" |
| 105 | +
|
| 106 | + print(f"Version: {version}") |
| 107 | +
|
| 108 | + with open(os.environ["GITHUB_OUTPUT"], "a") as output_file: |
| 109 | + output_file.write(f"version={version}\n") |
| 110 | +
|
| 111 | + - name: Find workspace |
| 112 | + shell: bash |
| 113 | + run: | |
| 114 | + case ${{ runner.os }} in |
| 115 | + Linux) _workspace="/project";; |
| 116 | + Windows) _workspace=$(cygpath -u $GITHUB_WORKSPACE);; |
| 117 | + macOS) _workspace="$GITHUB_WORKSPACE";; |
| 118 | + *) echo "Unhandled os ${{ runner.os }}";exit 64;; |
| 119 | + esac |
| 120 | + echo "WORKSPACE=${_workspace}" >> $GITHUB_ENV |
| 121 | +
|
| 122 | + - name: Set Conan parameters |
| 123 | + shell: bash |
| 124 | + run: | |
| 125 | + _build_type=$(echo "${{ env.BUILD_TYPE }}" | tr '[:upper:]' '[:lower:]') |
| 126 | + _conan_home="${{ env.WORKSPACE }}/.conan2" |
| 127 | + echo "CONAN_PRESET=conan-${_build_type}" >> $GITHUB_ENV |
| 128 | + echo "CONAN_HOME=${_conan_home}" >> $GITHUB_ENV |
| 129 | +
|
| 130 | + - name: Configure ccache |
| 131 | + uses: actions/github-script@v7 |
| 132 | + with: |
| 133 | + script: | |
| 134 | + const workspace = String.raw`${{ github.workspace }}`; |
| 135 | +
|
| 136 | + const envVariables = { |
| 137 | + 'cache-variant': String.raw`ccache`, |
| 138 | + 'CMAKE_CXX_COMPILER_LAUNCHER': String.raw`ccache`, |
| 139 | + 'CMAKE_C_COMPILER_LAUNCHER': String.raw`ccache`, |
| 140 | + 'CCACHE_CONFIGPATH': String.raw`${workspace}/ccache.conf`, |
| 141 | + 'CCACHE_DIR': String.raw`${workspace}/.ccache`, |
| 142 | + 'CCACHE_DEBUGDIR': String.raw`${workspace}/ccache-debug`, |
| 143 | + 'CCACHE_LOGFILE': String.raw`${workspace}/ccache.log` |
| 144 | + }; |
| 145 | +
|
| 146 | + for (const [key, value] of Object.entries(envVariables)) { |
| 147 | + core.exportVariable(key, value); |
| 148 | + } |
| 149 | +
|
| 150 | + - uses: actions/setup-python@v5 |
| 151 | + with: |
| 152 | + python-version: 3.13 |
| 153 | + |
| 154 | + # Update apt: needed to install ccache-action |
| 155 | + - name: Update apt (Linux) |
| 156 | + if: runner.os == 'Linux' |
| 157 | + shell: bash |
| 158 | + run: | |
| 159 | + sudo apt-get update -y |
| 160 | +
|
| 161 | + - name: ccache |
| 162 | + uses: hendrikmuhs/ccache-action@v1.2 |
| 163 | + with: |
| 164 | + create-symlink: false |
| 165 | + variant: ${{ env.cache-variant }} |
| 166 | + key: samples-${{ matrix.os }} |
| 167 | + max-size: 5G |
| 168 | + verbose: 1 |
| 169 | + |
| 170 | + - name: Prepare msvc |
| 171 | + if: runner.os == 'Windows' |
| 172 | + uses: ilammy/msvc-dev-cmd@v1 |
| 173 | + |
| 174 | + - name: Set MacOS deployment target |
| 175 | + if: runner.os == 'macOS' |
| 176 | + uses: actions/github-script@v7 |
| 177 | + with: |
| 178 | + script: | |
| 179 | + if ('${{ runner.arch }}' == 'X64') { |
| 180 | + target = '10.15'; |
| 181 | + arch='x86_64'; |
| 182 | + } |
| 183 | + else if ('${{ env.PYTHON_MINOR }}' != '8') { |
| 184 | + target = '11.0'; |
| 185 | + arch='armv8'; |
| 186 | + } |
| 187 | + else { |
| 188 | + target = '12.0'; |
| 189 | + arch='armv8'; |
| 190 | + } |
| 191 | + core.exportVariable('MACOSX_DEPLOYMENT_TARGET', target); |
| 192 | + core.exportVariable('PKG_ARCH', arch); |
| 193 | +
|
| 194 | + - name: Build (Windows) |
| 195 | + if: runner.os == 'Windows' |
| 196 | + shell: cmd |
| 197 | + env: |
| 198 | + CONAN_HOME: ${{ github.workspace }}\.conan2 |
| 199 | + run: | |
| 200 | + pip install conan && make deps && make luxcore && make luxcoreui && make luxcoreconsole |
| 201 | +
|
| 202 | + - name: Build (MacOS) |
| 203 | + if: runner.os == 'macOS' |
| 204 | + shell: bash |
| 205 | + run: | |
| 206 | + pip install conan |
| 207 | + make deps |
| 208 | + make luxcore |
| 209 | + make luxcoreui |
| 210 | + make luxcoreconsole |
| 211 | +
|
| 212 | + # Build for Linux is containerized in manylinux_2_28_x86_64 |
| 213 | + - name: Build (Linux) |
| 214 | + if: runner.os == 'Linux' |
| 215 | + shell: bash |
| 216 | + env: |
| 217 | + CONTAINER: manylinux |
| 218 | + # COMMAND contains code that'll be executed in container |
| 219 | + COMMAND: | |
| 220 | + # Set Python |
| 221 | + manylinux-interpreters ensure cp313-cp313 |
| 222 | + PATH=/opt/python/cp313-cp313/bin:$PATH |
| 223 | + which python |
| 224 | + python -m pip install conan |
| 225 | +
|
| 226 | + # Install toolchain (gcc, ccache...) |
| 227 | + CC=/opt/rh/gcc-toolset-14/root/usr/bin/gcc |
| 228 | + CXX=/opt/rh/gcc-toolset-14/root/usr/bin/g++ |
| 229 | + export CMAKE_C_COMPILER_LAUNCHER=ccache |
| 230 | + export CMAKE_CXX_COMPILER_LAUNCHER=ccache |
| 231 | + export VERBOSE=1 |
| 232 | + #export CLICOLOR_FORCE=1 |
| 233 | +
|
| 234 | + # Install conda |
| 235 | + dnf install -y wget |
| 236 | + mkdir -p miniconda3 |
| 237 | + wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh \ |
| 238 | + -O miniconda3/miniconda.sh |
| 239 | + bash miniconda3/miniconda.sh -b -u -p miniconda3 |
| 240 | + rm miniconda3/miniconda.sh |
| 241 | + source miniconda3/bin/activate |
| 242 | + conda init --all |
| 243 | +
|
| 244 | + # Install gh |
| 245 | + conda install conda-forge::gh --channel conda-forge -y |
| 246 | + echo ${{ secrets.GITHUB_TOKEN }} | gh auth login --with-token |
| 247 | +
|
| 248 | + # Install ccache |
| 249 | + conda install conda-forge::ccache -y |
| 250 | + export CCACHE_CONFIGPATH=/project/ccache.conf |
| 251 | + ccache -o cache_dir=/project/.ccache |
| 252 | + ccache -o depend_mode=false |
| 253 | + echo "ccache configuration:" |
| 254 | + ccache -p |
| 255 | +
|
| 256 | + # Build |
| 257 | + make deps |
| 258 | + make luxcore |
| 259 | + make luxcoreui |
| 260 | + make luxcoreconsole |
| 261 | +
|
| 262 | + # Re-inspect ccache |
| 263 | + echo "ccache results:" |
| 264 | + ccache -sv |
| 265 | +
|
| 266 | + # run contains code that'll be executed on host side |
| 267 | + run: | |
| 268 | + # Clean (remove container if it exists) |
| 269 | + CONTAINER_LIST=$(docker container ps -a) |
| 270 | + if [[ ${CONTAINER_LIST} == *${{ env.CONTAINER }}* ]]; then |
| 271 | + echo "Removing existing container '${{ env.CONTAINER }}'" |
| 272 | + docker rm --force ${{ env.CONTAINER }} |
| 273 | + fi |
| 274 | +
|
| 275 | + # Start |
| 276 | + echo "" |
| 277 | + echo "******** LAUCHING MANYLINUX CONTAINER ********" |
| 278 | + echo "" |
| 279 | + docker create \ |
| 280 | + -t \ |
| 281 | + --name ${{ env.CONTAINER }} \ |
| 282 | + quay.io/pypa/manylinux_2_28_x86_64 |
| 283 | + docker start ${{ env.CONTAINER }} |
| 284 | + docker exec ${{ env.CONTAINER }} env |
| 285 | +
|
| 286 | + # Copy source tree |
| 287 | + docker exec ${{ env.CONTAINER }} sh -c "echo Copying source tree" |
| 288 | + docker cp ${{ github.workspace }} ${{ env.CONTAINER }}:/project |
| 289 | +
|
| 290 | + # Copy ccache |
| 291 | + echo "Copying ${{ env.CCACHE_DIR }} to container" |
| 292 | + docker cp ${{ env.CCACHE_DIR }}/. ${{ env.CONTAINER }}:/root/.ccache |
| 293 | +
|
| 294 | + # Execute COMMAND in container |
| 295 | + docker exec --workdir=/project ${{ env.CONTAINER }} sh -c '${{ env.COMMAND }}' |
| 296 | +
|
| 297 | + # Copy ccache back |
| 298 | + docker cp ${{ env.CONTAINER }}:/root/.ccache/. ${{ env.CCACHE_DIR }} |
| 299 | +
|
| 300 | + # Get artifact |
| 301 | + mkdir -p ${{ github.workspace }}/out/build |
| 302 | + docker cp ${{ env.CONTAINER }}:/project/out ${{ github.workspace }} |
| 303 | +
|
| 304 | + # Stop container |
| 305 | + docker stop ${{ env.CONTAINER }} |
| 306 | +
|
| 307 | + # Remove superfluous files (hack) |
| 308 | + rm ${{ github.workspace }}/out/install/Release/lib/libnvrtc*.alt.* |
| 309 | +
|
| 310 | + #- name: Setup tmate session (debug) |
| 311 | + #if: ${{ failure() }} |
| 312 | + #uses: mxschmitt/action-tmate@v3 |
| 313 | + |
| 314 | + - name: Install 7zip (act) |
| 315 | + if: ${{ env.ACT }} |
| 316 | + shell: bash |
| 317 | + run: | |
| 318 | + apt install -y p7zip-full |
| 319 | +
|
| 320 | + - name: Bundle artifacts |
| 321 | + working-directory: ${{ github.workspace }}/out/install |
| 322 | + shell: bash |
| 323 | + run: | |
| 324 | + mv Release LuxCore |
| 325 | + 7z a -snl ../../LuxCoreSamples-${{ runner.os }}-${{ runner.arch }}.zip LuxCore/ |
| 326 | +
|
| 327 | + # Upload artifacts |
| 328 | + - uses: actions/upload-artifact@v4 |
| 329 | + id: upload |
| 330 | + with: |
| 331 | + name: LuxCore-Samples-${{ runner.os }}-${{ runner.arch }} |
| 332 | + path: ${{ github.workspace }}/LuxCoreSamples-${{ runner.os }}-${{ runner.arch }}.zip |
| 333 | + #path: ${{ github.workspace }}/out/install/Release |
| 334 | + |
| 335 | + attest-samples: |
| 336 | + needs: [build-samples] |
| 337 | + runs-on: ubuntu-latest |
| 338 | + permissions: |
| 339 | + attestations: write |
| 340 | + id-token: write |
| 341 | + outputs: |
| 342 | + attestation-url: ${{ steps.attestation-step.outputs.attestation-url }} |
| 343 | + |
| 344 | + steps: |
| 345 | + - uses: actions/download-artifact@v4 |
| 346 | + if: ${{ !env.ACT }} |
| 347 | + with: |
| 348 | + pattern: LuxCore-* |
| 349 | + path: ${{ github.workspace }}/dist |
| 350 | + merge-multiple: false |
| 351 | + |
| 352 | + - name: Generate artifact attestations |
| 353 | + id: attestation-step |
| 354 | + if: ${{ !env.ACT }} |
| 355 | + uses: actions/attest-build-provenance@v2 |
| 356 | + with: |
| 357 | + subject-path: ${{ github.workspace }}/dist/* |
0 commit comments