Prefer a self-hosted Apple Silicon runner for GitHub releases

Select the macOS runner before creating the release build matrix. Default to a self-hosted ARM64 Mac. With a repository runner-status credential, choose GitHub-hosted macOS when no matching runner is online and idle or when the lookup fails. MACOS_USE_HOSTED can force the hosted pool. Limit build jobs to read-only contents.

Validated the workflow with actionlint (its bundled label list predates the existing Ubuntu 26.04 jobs) and exercised the online, offline, busy, mismatched-label, missing-token, API-error and hosted-override cases.
This commit is contained in:
Aleksandr Bogomiakov committed 2026-11-24 21:17:47 +02:00
1 parent 04b5ebc1a0
commit 42c25f29ec
1 file changed
+41 -1
+41 -1
View File
@@ -20,8 +20,46 @@ env:
CARGO_NET_RETRY: "10"
jobs:
macos-runner:
name: Select macOS runner
if: github.server_url == 'https://github.com'
runs-on: ubuntu-latest
permissions: {}
outputs:
labels: ${{ steps.select.outputs.labels }}
steps:
- id: select
shell: bash
env:
GH_TOKEN: ${{ secrets.MACOS_RUNNER_STATUS_TOKEN }}
USE_HOSTED: ${{ vars.MACOS_USE_HOSTED }}
run: |
set -euo pipefail
labels='["self-hosted","macOS","ARM64"]'
if [[ "$USE_HOSTED" == "true" ]]; then
labels='["macos-latest"]'
elif [[ -n "$GH_TOKEN" ]]; then
# Listing repository runners requires Administration: read.
if ! available=$(gh api --paginate "repos/$GITHUB_REPOSITORY/actions/runners?per_page=100" \
--jq '.runners[] | select(.status == "online" and .busy == false) |
select((["self-hosted","macos","arm64"] - [.labels[].name | ascii_downcase]) == []) | .id'); then
echo "::warning::Unable to check self-hosted runners; using GitHub-hosted macOS"
available=""
fi
if [[ -z "$available" ]]; then
labels='["macos-latest"]'
fi
else
echo "::notice::Using self-hosted macOS. Set MACOS_RUNNER_STATUS_TOKEN for automatic fallback."
fi
echo "Selected $labels"
echo "labels=$labels" >> "$GITHUB_OUTPUT"
build:
name: ${{ matrix.asset }}
needs: macos-runner
permissions:
contents: read
if: ${{ github.server_url == 'https://github.com' }}
runs-on: ${{ matrix.os }}
strategy:
@@ -55,7 +93,7 @@ jobs:
deb: true
deb_arch: armhf
pkg_arch: armv7h
- os: macos-latest
- os: ${{ fromJSON(needs.macos-runner.outputs.labels) }}
target: aarch64-apple-darwin
asset: tsunagi-macos-aarch64
archive: tar.gz
@@ -68,6 +106,8 @@ jobs:
steps:
- uses: actions/checkout@v5
with:
persist-credentials: false
- uses: dtolnay/rust-toolchain@stable
with: