|
| 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-wheels.outputs.commit }} |
| 29 | + branch: |
| 30 | + description: "The branch that has been checked out" |
| 31 | + value: ${{ jobs.build-wheels.outputs.branch }} |
| 32 | + attestation-url: |
| 33 | + description: "The url to the attestations" |
| 34 | + value: ${{ jobs.attest-wheels.outputs.attestation-url }} |
| 35 | + version: |
| 36 | + description: "The version actually built" |
| 37 | + value: ${{ jobs.build-wheels.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: Find workspace |
| 88 | + shell: bash |
| 89 | + run: | |
| 90 | + case ${{ runner.os }} in |
| 91 | + Linux) _workspace="/project";; |
| 92 | + Windows) _workspace=$(cygpath -u $GITHUB_WORKSPACE);; |
| 93 | + macOS) _workspace="$GITHUB_WORKSPACE";; |
| 94 | + *) echo "Unhandled os ${{ runner.os }}";exit 64;; |
| 95 | + esac |
| 96 | + echo "WORKSPACE=${_workspace}" >> $GITHUB_ENV |
| 97 | +
|
| 98 | + - name: Set Conan parameters |
| 99 | + shell: bash |
| 100 | + run: | |
| 101 | + _build_type=$(echo "${{ env.BUILD_TYPE }}" | tr '[:upper:]' '[:lower:]') |
| 102 | + _conan_home="${{ env.WORKSPACE }}/.conan2" |
| 103 | + echo "CONAN_PRESET=conan-${_build_type}" >> $GITHUB_ENV |
| 104 | + echo "CONAN_HOME=${_conan_home}" >> $GITHUB_ENV |
| 105 | +
|
| 106 | + - name: Configure ccache |
| 107 | + uses: actions/github-script@v7 |
| 108 | + with: |
| 109 | + script: | |
| 110 | + const workspace = String.raw`${{ github.workspace }}`; |
| 111 | +
|
| 112 | + const envVariables = { |
| 113 | + 'cache-variant': String.raw`ccache`, |
| 114 | + 'CMAKE_CXX_COMPILER_LAUNCHER': String.raw`ccache`, |
| 115 | + 'CMAKE_C_COMPILER_LAUNCHER': String.raw`ccache`, |
| 116 | + 'CCACHE_CONFIGPATH': String.raw`${workspace}/ccache.conf`, |
| 117 | + 'CCACHE_DIR': String.raw`${workspace}/.ccache`, |
| 118 | + 'CCACHE_DEBUGDIR': String.raw`${workspace}/ccache-debug`, |
| 119 | + 'CCACHE_LOGFILE': String.raw`${workspace}/ccache.log` |
| 120 | + }; |
| 121 | +
|
| 122 | + for (const [key, value] of Object.entries(envVariables)) { |
| 123 | + core.exportVariable(key, value); |
| 124 | + } |
| 125 | +
|
| 126 | + # TODO |
| 127 | + ## Update apt: needed to install ccache |
| 128 | + #- name: Update apt (Linux) |
| 129 | + #if: runner.os == 'Linux' |
| 130 | + #shell: bash |
| 131 | + #run: | |
| 132 | + #sudo apt-get update -y |
| 133 | + |
| 134 | + - uses: actions/setup-python@v5 |
| 135 | + with: |
| 136 | + python-version: 3.13 |
| 137 | + - name: Install GH CLI |
| 138 | + uses: dev-hanz-ops/install-gh-cli-action@v0.2.1 |
| 139 | + with: |
| 140 | + gh-cli-version: 2.67.0 |
| 141 | + |
| 142 | + # Update apt: needed to install ccache-action |
| 143 | + - name: Update apt (Linux) |
| 144 | + if: runner.os == 'Linux' |
| 145 | + shell: bash |
| 146 | + run: | |
| 147 | + sudo apt-get update -y |
| 148 | +
|
| 149 | + - name: ccache |
| 150 | + uses: hendrikmuhs/ccache-action@v1.2 |
| 151 | + with: |
| 152 | + create-symlink: false |
| 153 | + variant: ${{ env.cache-variant }} |
| 154 | + key: samples-${{ matrix.os }}- |
| 155 | + restore-keys: samples-${{ matrix.os }}- |
| 156 | + max-size: 5G |
| 157 | + verbose: 1 |
| 158 | + |
| 159 | + - name: Prepare msvc |
| 160 | + if: runner.os == 'Windows' |
| 161 | + uses: ilammy/msvc-dev-cmd@v1 |
| 162 | + |
| 163 | + - name: Set MacOS deployment target |
| 164 | + if: runner.os == 'macOS' |
| 165 | + uses: actions/github-script@v7 |
| 166 | + with: |
| 167 | + script: | |
| 168 | + if ('${{ runner.arch }}' == 'X64') { |
| 169 | + target = '10.15'; |
| 170 | + arch='x86_64'; |
| 171 | + } |
| 172 | + else if ('${{ env.PYTHON_MINOR }}' != '8') { |
| 173 | + target = '11.0'; |
| 174 | + arch='armv8'; |
| 175 | + } |
| 176 | + else { |
| 177 | + target = '12.0'; |
| 178 | + arch='armv8'; |
| 179 | + } |
| 180 | + core.exportVariable('MACOSX_DEPLOYMENT_TARGET', target); |
| 181 | + core.exportVariable('PKG_ARCH', arch); |
| 182 | +
|
| 183 | + - name: Export version |
| 184 | + shell: python |
| 185 | + run: | |
| 186 | + import json |
| 187 | + if (input_version := "${{ inputs.release-version }}"): |
| 188 | + result = input_version |
| 189 | + else: |
| 190 | + with open("luxcore.json") as in_file: |
| 191 | + default_version = json.load(in_file)["DefaultVersion"] |
| 192 | + result = ".".join(default_version[i] for i in ("major", "minor", "patch")) |
| 193 | + if (prerelease := default_version["prerelease"]): |
| 194 | + result = f"{result}-{prerelease}" |
| 195 | +
|
| 196 | + print(f"Version: {result}") |
| 197 | +
|
| 198 | + with open("SKVERSION", "w+") as out_file: |
| 199 | + out_file.write(result) |
| 200 | +
|
| 201 | + - name: Output version |
| 202 | + id: output-version |
| 203 | + shell: bash |
| 204 | + run: | |
| 205 | + _version=$(cat SKVERSION) |
| 206 | + echo "version=${_version}" >> "$GITHUB_OUTPUT" |
| 207 | +
|
| 208 | + - name: Build (Windows/MacOS) |
| 209 | + if: ${{ ! runner.os == 'Linux' }} |
| 210 | + shell: bash -el {0} |
| 211 | + run: | |
| 212 | + pip install conan |
| 213 | + make deps |
| 214 | + make |
| 215 | + make package |
| 216 | +
|
| 217 | + # Build for Linux is containerized in manylinux_2_28_x86_64 |
| 218 | + - name: Build (Linux) |
| 219 | + if: runner.os == 'Linux' |
| 220 | + shell: bash |
| 221 | + env: |
| 222 | + # COMMAND contains code that'll be executed in container |
| 223 | + COMMAND: | |
| 224 | + # Set Python |
| 225 | + manylinux-interpreters ensure cp313-cp313 |
| 226 | + PATH=/opt/python/cp313-cp313/bin:$PATH |
| 227 | + which python |
| 228 | + python -m pip install conan |
| 229 | +
|
| 230 | + # Install toolchain (gcc, ccache...) |
| 231 | + #dnf install -y epel-release |
| 232 | + #dnf install -y almalinux-release-devel |
| 233 | + #dnf install -y perl-IPC-Cmd perl-Digest-SHA |
| 234 | + CC=/opt/rh/gcc-toolset-14/root/usr/bin/gcc |
| 235 | + CXX=/opt/rh/gcc-toolset-14/root/usr/bin/g++ |
| 236 | + export CMAKE_C_COMPILER_LAUNCHER=ccache |
| 237 | + export CMAKE_CXX_COMPILER_LAUNCHER=ccache |
| 238 | + export VERBOSE=1 |
| 239 | + #export CLICOLOR_FORCE=1 |
| 240 | +
|
| 241 | + # Install conda |
| 242 | + dnf install -y wget |
| 243 | + mkdir -p miniconda3 |
| 244 | + wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh \ |
| 245 | + -O miniconda3/miniconda.sh |
| 246 | + bash miniconda3/miniconda.sh -b -u -p miniconda3 |
| 247 | + rm miniconda3/miniconda.sh |
| 248 | + source miniconda3/bin/activate |
| 249 | + conda init --all |
| 250 | +
|
| 251 | + # Install gh |
| 252 | + conda install conda-forge::gh --channel conda-forge -y |
| 253 | + echo ${{ secrets.GITHUB_TOKEN }} | gh auth login --with-token |
| 254 | +
|
| 255 | + # Install ccache |
| 256 | + conda install conda-forge::ccache -y |
| 257 | + export CCACHE_CONFIGPATH=/project/ccache.conf |
| 258 | + ccache -o cache_dir=/project/.ccache |
| 259 | + ccache -o depend_mode=false |
| 260 | + echo "ccache configuration:" |
| 261 | + ccache -p |
| 262 | +
|
| 263 | + # Build |
| 264 | + make deps |
| 265 | + make luxcoreui |
| 266 | + make luxcoreconsole |
| 267 | + make package |
| 268 | +
|
| 269 | + # Re-inspect ccache |
| 270 | + echo "ccache results:" |
| 271 | + ccache -sv |
| 272 | +
|
| 273 | + # run contains code that'll be executed on host side |
| 274 | + run: | |
| 275 | + # Clean (remove container if it exists) |
| 276 | + CONTAINER=manylinux |
| 277 | + CONTAINER_LIST=$(docker container ps -a) |
| 278 | + if [[ ${CONTAINER_LIST} == *${CONTAINER}* ]]; then |
| 279 | + echo "Removing existing container '${CONTAINER}'" |
| 280 | + docker rm --force ${CONTAINER} |
| 281 | + fi |
| 282 | +
|
| 283 | + # Start |
| 284 | + echo "" |
| 285 | + echo "******** LAUCHING MANYLINUX CONTAINER ********" |
| 286 | + echo "" |
| 287 | + docker create \ |
| 288 | + -t \ |
| 289 | + --name ${CONTAINER} \ |
| 290 | + quay.io/pypa/manylinux_2_28_x86_64 |
| 291 | + docker start ${CONTAINER} |
| 292 | + docker exec ${CONTAINER} env |
| 293 | +
|
| 294 | + # Copy source tree |
| 295 | + docker exec ${CONTAINER} sh -c "echo Copying source tree" |
| 296 | + docker cp ${{ github.workspace }} ${CONTAINER}:/project |
| 297 | +
|
| 298 | + # Copy ccache |
| 299 | + echo "Copying ${{ env.CCACHE_DIR }} to container" |
| 300 | + docker cp ${{ env.CCACHE_DIR }}/. ${CONTAINER}:/root/.ccache |
| 301 | +
|
| 302 | + # Execute COMMAND in container |
| 303 | + docker exec --workdir=/project ${CONTAINER} sh -c '${{ env.COMMAND }}' |
| 304 | +
|
| 305 | + # Copy ccache back |
| 306 | + docker cp ${CONTAINER}:/root/.ccache/. ${{ env.CCACHE_DIR }} |
| 307 | +
|
| 308 | + # Get artifact |
| 309 | + mkdir -p ${{ github.workspace }}/out/build |
| 310 | + docker cp ${CONTAINER}:/project/out ${{ github.workspace }} |
| 311 | +
|
| 312 | + # Stop container |
| 313 | + docker stop ${CONTAINER} |
| 314 | +
|
| 315 | + #- name: Setup tmate session (debug) |
| 316 | + #if: ${{ failure() }} |
| 317 | + #uses: mxschmitt/action-tmate@v3 |
| 318 | + |
| 319 | + # Upload artifacts |
| 320 | + - uses: actions/upload-artifact@v4 |
| 321 | + id: upload |
| 322 | + with: |
| 323 | + path: ${{ github.workspace }}/out/build/LuxCore-*.zip |
| 324 | + |
| 325 | + attest-samples: |
| 326 | + needs: [build-wheels] |
| 327 | + runs-on: ubuntu-latest |
| 328 | + permissions: |
| 329 | + attestations: write |
| 330 | + id-token: write |
| 331 | + outputs: |
| 332 | + attestation-url: ${{ steps.attestation-step.outputs.attestation-url }} |
| 333 | + |
| 334 | + steps: |
| 335 | + - uses: actions/download-artifact@v4 |
| 336 | + if: ${{ !env.ACT }} |
| 337 | + with: |
| 338 | + pattern: LuxCore-* |
| 339 | + path: ${{ github.workspace }}/dist |
| 340 | + merge-multiple: false |
| 341 | + |
| 342 | + - name: Generate artifact attestations |
| 343 | + id: attestation-step |
| 344 | + if: ${{ !env.ACT }} |
| 345 | + uses: actions/attest-build-provenance@v2 |
| 346 | + with: |
| 347 | + subject-path: ${{ github.workspace }}/dist/* |
0 commit comments