From 041c3b1b5593f736f2687c223169959d336d37bb Mon Sep 17 00:00:00 2001 From: MaxsTechReview Date: Sat, 7 Nov 2026 15:00:39 -0500 Subject: [PATCH] ci: run compile jobs on the org workstation runner when it is idle (#2234) * ci: run compile jobs on the org workstation runner when it is idle * ci: pick the compile runner right before each heavy job * ci: cover the runner picks in the job dependency test --- .github/workflows/build.yml | 24 +++++++++++++++---- .github/workflows/pick-runner.yml | 38 +++++++++++++++++++++++++++++++ tools/tests/test_ci_checks.py | 6 +++-- 3 files changed, 61 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/pick-runner.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fcb30d8ac1..3f52953697 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -136,11 +136,18 @@ jobs: if-no-files-found: error retention-days: 14 - components: - name: Prepare verified components + components-runner: needs: source if: ${{ github.event_name != 'pull_request' || !github.event.pull_request.draft }} - runs-on: ubuntu-24.04 + uses: ./.github/workflows/pick-runner.yml + secrets: + RUNNER_STATUS_TOKEN: ${{ secrets.RUNNER_STATUS_TOKEN }} + + components: + name: Prepare verified components + needs: [source, components-runner] + if: ${{ github.event_name != 'pull_request' || !github.event.pull_request.draft }} + runs-on: ${{ fromJSON(needs.components-runner.outputs.labels) }} timeout-minutes: 40 steps: - uses: actions/checkout@v4 @@ -318,11 +325,18 @@ jobs: compression-level: 0 retention-days: 14 + build-runner: + needs: [components] + if: ${{ github.event_name != 'pull_request' || !github.event.pull_request.draft }} + uses: ./.github/workflows/pick-runner.yml + secrets: + RUNNER_STATUS_TOKEN: ${{ secrets.RUNNER_STATUS_TOKEN }} + build: - needs: [source, components, xbox] + needs: [source, components, xbox, build-runner] name: Compile APK and Android tests if: ${{ github.event_name != 'pull_request' || !github.event.pull_request.draft }} - runs-on: ubuntu-24.04 + runs-on: ${{ fromJSON(needs.build-runner.outputs.labels) }} timeout-minutes: 45 outputs: variants: ${{ steps.variants.outputs.list }} diff --git a/.github/workflows/pick-runner.yml b/.github/workflows/pick-runner.yml new file mode 100644 index 0000000000..5eee6bc57c --- /dev/null +++ b/.github/workflows/pick-runner.yml @@ -0,0 +1,38 @@ +name: Pick runner + +on: + workflow_call: + outputs: + labels: + value: ${{ jobs.pick.outputs.labels }} + secrets: + RUNNER_STATUS_TOKEN: + required: false + +permissions: {} + +jobs: + pick: + name: Pick runner + runs-on: ubuntu-24.04 + timeout-minutes: 2 + outputs: + labels: ${{ steps.runner.outputs.labels || '"ubuntu-24.04"' }} + steps: + - name: Pick the compile runner + id: runner + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository + continue-on-error: true + env: + GH_TOKEN: ${{ secrets.RUNNER_STATUS_TOKEN }} + run: | + set -euo pipefail + labels='"ubuntu-24.04"' + if [ -n "$GH_TOKEN" ]; then + idle=$(gh api "orgs/${GITHUB_REPOSITORY_OWNER}/actions/runners" --jq '[.runners[] | select(.status == "online" and .busy == false and any(.labels[]; .name == "droiddeck-ws"))] | length' 2>/dev/null || echo 0) + if [ "${idle:-0}" -gt 0 ]; then + labels='["self-hosted","droiddeck-ws"]' + fi + fi + echo "labels=$labels" >> "$GITHUB_OUTPUT" + echo "Compile runner: \`$labels\`" >> "$GITHUB_STEP_SUMMARY" diff --git a/tools/tests/test_ci_checks.py b/tools/tests/test_ci_checks.py index 52c1607aad..2dc65164a9 100644 --- a/tools/tests/test_ci_checks.py +++ b/tools/tests/test_ci_checks.py @@ -48,9 +48,11 @@ class CiChecksTest(unittest.TestCase): def test_independent_jobs_wait_only_for_the_pinned_source(self): jobs = yaml.safe_load((ROOT / '.github/workflows/build.yml').read_text())['jobs'] - for name in ('xbox', 'components', 'python-tests'): + for name in ('xbox', 'python-tests', 'components-runner'): self.assertEqual(jobs[name]['needs'], 'source') - self.assertEqual(set(jobs['build']['needs']), {'source', 'components', 'xbox'}) + self.assertEqual(set(jobs['components']['needs']), {'source', 'components-runner'}) + self.assertEqual(jobs['build-runner']['needs'], ['components']) + self.assertEqual(set(jobs['build']['needs']), {'source', 'components', 'xbox', 'build-runner'}) def test_dependency_update_errors_block_installation(self): with tempfile.TemporaryDirectory() as directory: