mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-11-22 21:50:51 -05:00
* 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.
153 lines
5.9 KiB
Bash
153 lines
5.9 KiB
Bash
#!/usr/bin/env bash
|
|
# Lets a pull request's macOS deps build, or its clang-tidy job, wait for a
|
|
# build that saves the deps cache it needs, from a Linux job. `check` runs after
|
|
# a cache miss and names a queued or running push build of the base branch with
|
|
# the same deps/ and .github/ to wait for, unless the pull request changes either.
|
|
# `own` names the pull request's own build instead, for clang-tidy when the pull
|
|
# request changes deps/. `wait` waits until that build saves KEY under CACHE_REF,
|
|
# or its deps job fails. actions/cache then confirms the entry can be restored.
|
|
#
|
|
# Environment: GH_TOKEN, REPO, WORKFLOW (the build workflow's file name) and
|
|
# BASE_REF, plus HEAD_SHA for `own`, and KEY_INPUTS, WAIT_FOR,
|
|
# WAIT_SINCE, WAIT_MINUTES, KEY, CACHE_REF (default the base branch) and ARCH
|
|
# (or JOB, the matrix job's name) for `wait`.
|
|
# Writes key-inputs, wait-for and wait-since to $GITHUB_OUTPUT.
|
|
set -uo pipefail
|
|
|
|
workflow=${WORKFLOW:?}
|
|
|
|
# Must match the job names in build_all.yml, build_check_cache.yml and build_deps.yml.
|
|
job=${JOB:-build_macos_arch (${ARCH:-})}
|
|
check_job_name="$job / Check Cache"
|
|
deps_job_name="$job / Build Deps / Build Deps"
|
|
|
|
out() { echo "$1" >> "${GITHUB_OUTPUT:-/dev/stdout}"; }
|
|
|
|
# The cache key depends on deps/ and on the workflows under .github/.
|
|
local_key_inputs() { echo "$(git rev-parse "$1:.github") $(git rev-parse "$1:deps")"; }
|
|
remote_key_inputs() {
|
|
gh api "repos/$REPO/git/trees/$1" < /dev/null \
|
|
--jq '[.tree[] | select(.path == ".github" or .path == "deps") | {key: .path, value: .sha}] | from_entries | "\(.[".github"]) \(.deps)"'
|
|
}
|
|
|
|
# Prints the id of a push build of the base branch that has not finished, is not
|
|
# one of the ids in $1, and has KEY_INPUTS.
|
|
matching_base_build() {
|
|
local status runs id sha
|
|
runs=$(for status in in_progress queued pending waiting requested; do
|
|
gh api -X GET "repos/$REPO/actions/workflows/$workflow/runs" \
|
|
-f branch="$BASE_REF" -f event=push -f status="$status" -f per_page=10 < /dev/null \
|
|
| jq -r '.workflow_runs[] | "\(.id) \(.head_sha)"'
|
|
done)
|
|
while read -r id sha; do
|
|
[ -n "$id" ] || continue
|
|
[[ " ${1:-} " == *" $id "* ]] && continue
|
|
if [ "$(remote_key_inputs "$sha")" = "$KEY_INPUTS" ]; then
|
|
echo "$id"
|
|
return
|
|
fi
|
|
done <<< "$runs"
|
|
}
|
|
|
|
check() {
|
|
KEY_INPUTS=$(local_key_inputs HEAD)
|
|
out "key-inputs=$KEY_INPUTS"
|
|
if [ "$KEY_INPUTS" != "$(local_key_inputs HEAD^1)" ]; then
|
|
echo "This pull request changes deps/ or .github/, so it builds its own deps."
|
|
return
|
|
fi
|
|
local id
|
|
id=$(matching_base_build)
|
|
if [ -n "$id" ]; then
|
|
echo "Build $id of $BASE_REF has the same deps/ and .github/. Waiting for its cache."
|
|
out "wait-for=$id"
|
|
out "wait-since=$(date +%s)"
|
|
else
|
|
echo "No build of $BASE_REF is building these deps."
|
|
fi
|
|
}
|
|
|
|
own() {
|
|
out "key-inputs=$(local_key_inputs HEAD)"
|
|
local id
|
|
# The build can be created a moment after this job.
|
|
for _ in 1 2 3 4 5; do
|
|
id=$(gh api -X GET "repos/$REPO/actions/workflows/$workflow/runs" \
|
|
-f head_sha="$HEAD_SHA" -f event=pull_request -f per_page=1 --jq '.workflow_runs[0].id // empty' < /dev/null)
|
|
[ -n "$id" ] && break
|
|
sleep 30
|
|
done
|
|
if [ -n "$id" ]; then
|
|
echo "Waiting for the deps cache of build $id of this pull request."
|
|
out "wait-for=$id"
|
|
out "wait-since=$(date +%s)"
|
|
else
|
|
echo "No build of this pull request is building its deps."
|
|
fi
|
|
}
|
|
|
|
key_saved() {
|
|
gh cache list -R "$REPO" --ref "${CACHE_REF:-refs/heads/$BASE_REF}" --key "$KEY" --json key < /dev/null \
|
|
| jq -e --arg key "$KEY" 'any(.[]; .key == $key)' > /dev/null
|
|
}
|
|
|
|
wait_for() {
|
|
# Counts the limit from the check, including time queued behind other waiting
|
|
# pull requests.
|
|
local id=$WAIT_FOR seen=$WAIT_FOR deadline=$((${WAIT_SINCE:-$(date +%s)} + WAIT_MINUTES * 60)) jobs job check warned=
|
|
while [ "$(date +%s)" -lt "$deadline" ]; do
|
|
if key_saved; then
|
|
echo "Found $KEY."
|
|
return
|
|
fi
|
|
jobs=$(gh api -X GET "repos/$REPO/actions/runs/$id/jobs" -f filter=latest -f per_page=100 < /dev/null)
|
|
job=$(jq -r --arg name "$deps_job_name" 'first(.jobs[] | select(.name == $name) | "\(.status) \(.conclusion)") // ""' <<< "$jobs")
|
|
case "$job" in
|
|
"completed success" | "completed skipped")
|
|
# The new entry can take a moment to be listed, and a skipped job means
|
|
# the build found the cache, possibly under the default branch.
|
|
for _ in 1 2 3; do
|
|
key_saved && { echo "Found $KEY."; return; }
|
|
sleep 20
|
|
done
|
|
echo "Build $id finished its deps without saving $KEY."
|
|
return ;;
|
|
"completed cancelled") ;;
|
|
completed*)
|
|
echo "The deps job of build $id did not succeed."
|
|
return ;;
|
|
# The deps job exists only once the build's cache check has succeeded.
|
|
"")
|
|
case "$(gh api "repos/$REPO/actions/runs/$id" --jq '"\(.status) \(.conclusion)"' < /dev/null)" in
|
|
"completed cancelled") ;;
|
|
completed*)
|
|
check=$(jq -r --arg name "$check_job_name" 'first(.jobs[] | select(.name == $name) | .conclusion) // ""' <<< "$jobs")
|
|
if [ -z "$warned" ] && { [ -z "$check" ] || [ "$check" = success ]; }; then
|
|
echo "::warning title=Deps wait::Build $id has no job named \"$deps_job_name\". If the build jobs were renamed, update scripts/ci_deps_cache.sh. This does not affect this pull request."
|
|
warned=1
|
|
fi ;;
|
|
*)
|
|
sleep 120
|
|
continue ;;
|
|
esac ;;
|
|
*)
|
|
sleep 120
|
|
continue ;;
|
|
esac
|
|
# Follows another unfinished build with the same key inputs, such as the
|
|
# push that replaced a cancelled one.
|
|
id=$(matching_base_build "$seen")
|
|
[ -n "$id" ] || break
|
|
seen="$seen $id"
|
|
echo "Following build $id of $BASE_REF."
|
|
done
|
|
echo "No build saved $KEY."
|
|
}
|
|
|
|
case "${1:-}" in
|
|
check) check ;;
|
|
own) own ;;
|
|
wait) wait_for ;;
|
|
*) echo "usage: $0 check|own|wait" >&2; exit 2 ;;
|
|
esac
|