Implement runner fallback mechanism for docs and unit test workflows

This commit is contained in:
Palash Tyagi 2025-05-04 00:29:06 +01:00
parent d15aaf437f
commit 6076e0c8e3
2 changed files with 43 additions and 22 deletions

View File

@ -17,10 +17,21 @@ permissions:
pages: write pages: write
jobs: jobs:
docs-and-testcov: pick-runner:
# runs-on: ubuntu-latest runs-on: ubuntu-latest
runs-on: [self-hosted, ubuntu-latest] outputs:
runner: ${{ steps.choose.outputs.use-runner }}
steps:
- id: choose
uses: ./.github/actions/runner-fallback@v1 # or your-org/runner-fallback@v1
with:
primary-runner: "self-hosted,ubuntu-latest"
fallback-runner: "ubuntu-latest"
github-token: ${{ secrets.GITHUB_TOKEN }}
docs-and-testcov:
needs: pick-runner
runs-on: ${{ fromJson(needs.pick-runner.outputs.runner) }}
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
@ -56,12 +67,10 @@ jobs:
fi fi
- name: Export tarpaulin coverage badge JSON - name: Export tarpaulin coverage badge JSON
# extract raw coverage and round to 2 decimal places
run: | run: |
# extract raw coverage
coverage=$(jq '.coverage' tarpaulin-report.json) coverage=$(jq '.coverage' tarpaulin-report.json)
# round to 2 decimal places
formatted=$(printf "%.2f" "$coverage") formatted=$(printf "%.2f" "$coverage")
# build the badge JSON using the pre-formatted string
jq --arg message "$formatted" \ jq --arg message "$formatted" \
'{schemaVersion:1, '{schemaVersion:1,
label:"tarpaulin-report", label:"tarpaulin-report",

View File

@ -11,11 +11,23 @@ concurrency:
cancel-in-progress: true cancel-in-progress: true
jobs: jobs:
pick-runner:
runs-on: ubuntu-latest
outputs:
runner: ${{ steps.choose.outputs.use-runner }}
steps:
- id: choose
uses: ./.github/actions/runner-fallback@v1
with:
primary-runner: "self-hosted,ubuntu-latest"
fallback-runner: "ubuntu-latest"
github-token: ${{ secrets.GITHUB_TOKEN }}
run-unit-tests: run-unit-tests:
needs: pick-runner
if: github.event.pull_request.draft == false if: github.event.pull_request.draft == false
name: run-unit-tests name: run-unit-tests
# runs-on: ubuntu-latest runs-on: ${{ fromJson(needs.pick-runner.outputs.runner) }}
runs-on: [self-hosted, ubuntu-latest]
env: env:
CARGO_TERM_COLOR: always CARGO_TERM_COLOR: always