Files
OrcaSlicer/.github/workflows/build_check_cache.yml
T
HanifKoh a4de8cb891 Build the Flatpak, macOS x86_64 and Windows arm64 for Pull Requests on Request (#17202)
* Move the Flatpak Jobs Into a Reusable Workflow

build_flatpak.yml holds the Flatpak build and its two sandbox unit-test jobs, moved verbatim, so a second workflow can call them. Build all calls it for every event it built the Flatpak for before.

* Build the Flatpak, macOS x86_64 and Windows arm64 for Pull Requests on Request

Build all no longer builds them for a pull request: the Flatpak is the slowest
Linux leg, a macOS x86_64 build holds one of the few hosted macOS runners for
an hour, and Windows arm64 doubles the Windows legs. Pushes, the nightly and
dispatches still build everything, and a pull request's macOS arm64 build ships
as its own DMG in place of the universal one.

The new build_optional.yml builds them on a label (build-flatpak,
build-macos-x86_64, build-windows-arm64), from when it is added and on every
later push, and builds the Flatpak and Windows arm64 without a label when the
pull request changes anything outside the sources, tests, profiles,
translations and docs, which is where what breaks only those legs lives. Each
build keeps its own concurrency group, which cancel_closed_pr_builds.yml joins.

The macOS admission script now counts the macOS jobs of both workflows, and
build_check_cache.yml names the workflows in its env instead of deriving one
from the caller. The label bot lets a contributor ask for the Flatpak.

* Run the Windows Build Script Tests Only When a Pull Request Changes Them

The three suites build their own fixtures and read nothing else from the
tree, so on a pull request a short Linux job looks for a change to the scripts
or the suites first, and the Windows builds accept the skipped job. Pushes and
the nightly still run them every time.

* Read WORKFLOW Through a Checked Expansion

Shellcheck's SC2153 takes a bare uppercase reference next to the lowercase variable for a misspelling.

* Let the Pull Request Author Ask for Any Optional Build Through the Bot

GitHub starts no workflow from an event the job's own token causes, so the
label bot mints a GitHub App installation token when the app's secrets exist
and adds the build-* labels with it; without them the build starts with the
next push. The run a label starts is an ordinary pull_request run, so a first
pull request's waits for a maintainer's approval as Build all does.

* Build Everything the Labels Ask for in Every Optional Builds Run

Each label added starts a run of its own, and the pull request's checks show
the newest run only, so a run that built its own label's leg alone left the
others looking skipped. Every run now builds everything the labels and the
changed files ask for; the concurrency group of each build cancels the one an
earlier run of the commit started, so the newest run ends with them all.

* Filter Optional Builds Like Build All and Add a build-all Label

The workflow takes Build all's pull_request paths plus the Flatpak packaging,
so a pull request Build all skips, one that only changes an unrelated
workflow or script, gets no optional build and starts none on a label. The
build-all label asks for every optional build at once.

* Keep the Flatpak on Every Pull Request

flatpak-builder compiles with the GNOME SDK's default flags, which include
-D_GLIBCXX_ASSERTIONS, so the Flatpak's unit tests are the only pull request
check that aborts on an out-of-range vector access where the other legs'
Release builds read garbage and pass. Since August that caught four bugs
that changed only src/, tests/ or resources/, which the infra rule would not
have built, and the leg runs on hosted Linux runners, so gating it freed no
macOS runner. Build all calls build_flatpak.yml on pull requests again; the
optional builds are the macOS x86_64 and Windows arm64 ones, and build-all
means those two.

* Revert "Keep the Flatpak on Every Pull Request"

This reverts commit 998e31a99b.

The Flatpak stays behind the build-flatpak label and the infra rule, as
the maintainers prefer.

* Build the Linux Legs With libstdc++'s Assertions

flatpak-builder compiles with the GNOME SDK's default flags, which include
-D_GLIBCXX_ASSERTIONS, so the Flatpak's unit tests were the only pull
request check that aborts on an out-of-range vector access where the other
legs' Release builds read garbage and pass. Pull requests build the Flatpak
on request only now. SLIC3R_GLIBCXX_ASSERTIONS defines the macro for the
OrcaSlicer build, and the Linux legs turn it on, so every pull request keeps
those checks on a leg that always runs. The checks are libstdc++'s
lightweight subset: no class changes layout, so the prebuilt deps link as
they are.
2026-11-12 14:29:26 +08:00

202 lines
8.5 KiB
YAML

name: Check Cache
on:
workflow_call:
inputs:
os:
required: true
type: string
arch:
required: false
type: string
compiler:
required: false
type: string
default: msvc
build-deps-only:
required: false
type: boolean
force-build:
required: false
type: boolean
# Read by scripts/ci_deps_cache.sh and scripts/ci_macos_admission.py.
env:
REPO: ${{ github.repository }}
# The workflow whose push and nightly builds save the deps caches.
WORKFLOW: build_all.yml
# Every workflow with macOS builds, the first of them the one above.
MACOS_WORKFLOWS: build_all.yml build_optional.yml
BASE_REF: ${{ github.base_ref }}
jobs:
check_cache: # determines if there is a cache and outputs variables used in caching process
name: Check Cache
# Hosted macOS runners are scarce, so their lookup runs on Linux.
runs-on: ${{ startsWith(inputs.os, 'macos-') && 'ubuntu-24.04' || inputs.os }}
outputs:
cache-key: ${{ steps.set_outputs.outputs.cache-key }}
cache-path: ${{ steps.set_outputs.outputs.cache-path }}
valid-cache: ${{ steps.cache_deps.outputs.cache-hit }}
macos-path: ${{ steps.macos_path.outputs.path }}
key-inputs: ${{ steps.wait_check.outputs.key-inputs }}
wait-for: ${{ steps.wait_check.outputs.wait-for }}
wait-since: ${{ steps.wait_check.outputs.wait-since }}
steps:
- name: Checkout
uses: actions/checkout@v7
with:
lfs: 'false'
# The wait check compares the merge commit with its first parent.
fetch-depth: ${{ startsWith(inputs.os, 'macos-') && 2 || 1 }}
# Fetches only deps/, which the key hashes, and the wait script.
sparse-checkout: |
/deps/
/scripts/ci_deps_cache.sh
sparse-checkout-cone-mode: false
- name: set outputs
id: set_outputs
env:
# Anything that changes how the tree is built belongs in the key, or a job
# restores one it cannot use. Linux amd64 passes no arch deliberately, so
# 'linux-clang' keeps the cache it already has.
cache-os: ${{ (runner.os == 'macOS' || startsWith(inputs.os, 'macos-')) && format('{0}-{1}', inputs.os, inputs.arch) || (runner.os == 'Windows' && format('windows-{0}-{1}', inputs.arch, inputs.compiler) || format('linux-clang{0}', inputs.arch && format('-{0}', inputs.arch) || '')) }}
# The Windows ARM64 deps build in build-arm64, all others under build;
# build_deps.yml and build_orca.yml pass the Windows directory to build_win.bat.
dep-folder-name: ${{ (runner.os == 'macOS' || startsWith(inputs.os, 'macos-')) && format('/{0}', inputs.arch) || (runner.os == 'Windows' && inputs.arch == 'arm64') && '-arm64/OrcaSlicer_dep' || '/OrcaSlicer_dep' }}
output-cmd: ${{ runner.os == 'Windows' && '$env:GITHUB_OUTPUT' || '"$GITHUB_OUTPUT"'}}
run: |
echo cache-key=${{ env.cache-os }}-cache-orcaslicer_deps-build-${{ hashFiles('deps/**') }} >> ${{ env.output-cmd }}
# Relative to the workspace, which differs from the build's when this job runs on Linux.
echo cache-path=deps/build${{ env.dep-folder-name }} >> ${{ env.output-cmd }}
# actions/cache matches the path too, so a Linux lookup for macOS uses the
# workspace of a hosted macOS job.
- name: macOS cache path
id: macos_path
if: ${{ startsWith(inputs.os, 'macos-') }}
run: echo "path=/Users/runner/work/${GITHUB_REPOSITORY#*/}/${GITHUB_REPOSITORY#*/}/${{ steps.set_outputs.outputs.cache-path }}" >> "$GITHUB_OUTPUT"
- name: load cache
id: cache_deps
uses: actions/cache@v6
with:
path: ${{ steps.macos_path.outputs.path || format('{0}/{1}', github.workspace, steps.set_outputs.outputs.cache-path) }}
key: ${{ steps.set_outputs.outputs.cache-key }}
lookup-only: true
# A pull request that misses the cache can wait for a base branch build of the same deps.
- name: check for a base branch build to wait for
id: wait_check
if: ${{ startsWith(inputs.os, 'macos-') && github.event_name == 'pull_request' && steps.cache_deps.outputs.cache-hit != 'true' }}
env:
GH_TOKEN: ${{ github.token }}
run: bash scripts/ci_deps_cache.sh check
wait_for_deps:
name: Wait for base branch deps
needs: [check_cache]
if: ${{ needs.check_cache.outputs.wait-for != '' }}
runs-on: ubuntu-24.04
env:
WAIT_MINUTES: 120
# Must exceed WAIT_MINUTES.
timeout-minutes: 130
# Waiting runs queue here, and only the first one holds a runner.
concurrency:
group: deps-wait-${{ github.base_ref }}-${{ needs.check_cache.outputs.cache-key }}
queue: max
outputs:
hit: ${{ steps.lookup.outputs.cache-hit }}
steps:
- name: Checkout
uses: actions/checkout@v7
with:
sparse-checkout: scripts/ci_deps_cache.sh
sparse-checkout-cone-mode: false
- name: wait for the deps cache
env:
GH_TOKEN: ${{ github.token }}
KEY: ${{ needs.check_cache.outputs.cache-key }}
KEY_INPUTS: ${{ needs.check_cache.outputs.key-inputs }}
WAIT_FOR: ${{ needs.check_cache.outputs.wait-for }}
WAIT_SINCE: ${{ needs.check_cache.outputs.wait-since }}
ARCH: ${{ inputs.arch }}
run: bash scripts/ci_deps_cache.sh wait
- name: load cache
id: lookup
uses: actions/cache@v6
with:
path: ${{ needs.check_cache.outputs.macos-path }}
key: ${{ needs.check_cache.outputs.cache-key }}
lookup-only: true
# Hosted macOS runners are scarce, so a pull request's macOS build waits until
# one is free that push and nightly builds do not need. See the script.
macos_admission:
name: Wait for a macOS runner
needs: [check_cache, wait_for_deps]
if: ${{ !cancelled() && needs.check_cache.result == 'success' && startsWith(inputs.os, 'macos-') && github.event_name == 'pull_request' && !contains(github.event.pull_request.labels.*.name, 'macos-priority') }}
runs-on: ubuntu-24.04
env:
WAIT_MINUTES: 240
PRIORITY: false
# Must exceed WAIT_MINUTES.
timeout-minutes: 250
# One line for every arch of every pull request, and only its first job polls.
concurrency:
group: macos-admission
queue: max
steps: &macos_admission_steps
- name: Checkout
uses: actions/checkout@v7
with:
sparse-checkout: scripts/ci_macos_admission.py
sparse-checkout-cone-mode: false
- name: wait for a macOS runner
env:
GH_TOKEN: ${{ github.token }}
MACOS_RUNNER_LIMIT: ${{ vars.MACOS_RUNNER_LIMIT }}
# -u, or the log shows nothing until the wait ends.
run: python3 -u scripts/ci_macos_admission.py
# The macos-priority label, when the run starts, puts a pull request in its own
# line, which the normal one yields to. The names are fixed, because a skipped
# job is listed under its unevaluated name, and the script matches both.
macos_admission_priority:
name: Wait for a macOS runner (priority)
needs: [check_cache, wait_for_deps]
if: ${{ !cancelled() && needs.check_cache.result == 'success' && startsWith(inputs.os, 'macos-') && github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'macos-priority') }}
runs-on: ubuntu-24.04
env:
WAIT_MINUTES: 240
PRIORITY: true
# Must exceed WAIT_MINUTES.
timeout-minutes: 250
concurrency:
group: macos-admission-priority
queue: max
steps: *macos_admission_steps
build_deps: # call next step
name: Build Deps
needs: [check_cache, wait_for_deps, macos_admission, macos_admission_priority]
# A failed wait counts as no cache, so the deps are built here. A failed
# admission still builds rather than skip macOS.
if: ${{ !cancelled() && needs.check_cache.result == 'success' }}
uses: ./.github/workflows/build_deps.yml
with:
cache-key: ${{ needs.check_cache.outputs.cache-key }}
cache-path: ${{ needs.check_cache.outputs.cache-path }}
valid-cache: ${{ needs.check_cache.outputs.valid-cache == 'true' || needs.wait_for_deps.outputs.hit == 'true' }}
os: ${{ inputs.os }}
arch: ${{ inputs.arch }}
compiler: ${{ inputs.compiler }}
build-deps-only: ${{ inputs.build-deps-only }}
force-build: ${{ inputs.force-build }}
secrets: inherit