feat(runs-on-selector): add runs-on selector action #53
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| permissions: {} | |
| concurrency: | |
| group: ci-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| # The repository picks its own runner with the action it ships, so a change to | |
| # that action is exercised by the pull request that makes the change. | |
| runner: | |
| name: Runner | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| permissions: | |
| contents: read | |
| outputs: | |
| name: ${{ steps.pick.outputs.name }} | |
| steps: | |
| # Only because `uses: ./actions/runner-selector` reads the action itself | |
| # from the workspace. A consumer of the published action needs no | |
| # checkout, because the map is an input. | |
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| persist-credentials: false | |
| sparse-checkout: actions/runner-selector | |
| sparse-checkout-cone-mode: false | |
| - id: pick | |
| uses: ./actions/runner-selector | |
| with: | |
| default: github | |
| pools-json: | | |
| { | |
| "github": "ubuntu-24.04", | |
| "blacksmith": "blacksmith-2vcpu-ubuntu-2404" | |
| } | |
| check: | |
| name: Lint | |
| needs: runner | |
| runs-on: ${{ needs.runner.outputs.name }} | |
| permissions: | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| persist-credentials: false | |
| # Tool versions live in mise.toml and the task lives under | |
| # .config/mise/tasks, so a contributor runs exactly what CI runs. | |
| - uses: jdx/mise-action@c2a87611a18de5b3828c5652fe268e992400cb5c # v4.3.0 | |
| - run: mise run github:actions:ci:lint | |
| test: | |
| name: Test | |
| needs: runner | |
| runs-on: ${{ needs.runner.outputs.name }} | |
| permissions: | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| persist-credentials: false | |
| - uses: jdx/mise-action@c2a87611a18de5b3828c5652fe268e992400cb5c # v4.3.0 | |
| - run: mise run github:actions:tests:node | |
| # The unit tests assert what the runner is believed to do with an input | |
| # name and an output file. These assert what it actually does, which is | |
| # the half no test on this machine can reach. | |
| - id: labelled | |
| uses: ./actions/runner-selector | |
| with: | |
| default: github | |
| label: runs-on:blacksmith | |
| pools-json: '{"github":"ubuntu-24.04","blacksmith":"blacksmith-2vcpu-ubuntu-2404"}' | |
| - env: | |
| NAME: ${{ steps.labelled.outputs.name }} | |
| run: '[ "$NAME" = "blacksmith-2vcpu-ubuntu-2404" ]' | |
| # `label-prefix` is a dashed input name, which is the class of thing no | |
| # test on a developer machine can vouch for: the runner spells it | |
| # INPUT_LABEL-PREFIX, not INPUT_LABEL_PREFIX. | |
| - id: prefixed | |
| uses: ./actions/runner-selector | |
| with: | |
| default: github | |
| label-prefix: action-runner | |
| label: action-runner:blacksmith | |
| pools-json: '{"github":"ubuntu-24.04","blacksmith":"blacksmith-2vcpu-ubuntu-2404"}' | |
| - env: | |
| NAME: ${{ steps.prefixed.outputs.name }} | |
| run: '[ "$NAME" = "blacksmith-2vcpu-ubuntu-2404" ]' | |
| # Expected to fail, so it leaves an error annotation on a green run. That | |
| # annotation is the assertion: an unknown pool name must stop the run | |
| # rather than fall back to the default. | |
| - id: unknown | |
| continue-on-error: true | |
| uses: ./actions/runner-selector | |
| with: | |
| default: github | |
| label: runs-on:nope | |
| pools-json: '{"github":"ubuntu-24.04"}' | |
| - env: | |
| OUTCOME: ${{ steps.unknown.outcome }} | |
| run: '[ "$OUTCOME" = "failure" ]' |