From 6076e0c8e36ef6ef32e1f6b1679929e7e8416018 Mon Sep 17 00:00:00 2001 From: Palash Tyagi <23239946+Magnus167@users.noreply.github.com> Date: Sun, 4 May 2025 00:29:06 +0100 Subject: [PATCH] Implement runner fallback mechanism for docs and unit test workflows --- .github/workflows/docs-and-testcov.yml | 49 +++++++++++++++----------- .github/workflows/run-unit-tests.yml | 16 +++++++-- 2 files changed, 43 insertions(+), 22 deletions(-) diff --git a/.github/workflows/docs-and-testcov.yml b/.github/workflows/docs-and-testcov.yml index 917259b..2929b6c 100644 --- a/.github/workflows/docs-and-testcov.yml +++ b/.github/workflows/docs-and-testcov.yml @@ -17,10 +17,21 @@ permissions: pages: write jobs: - docs-and-testcov: - # runs-on: ubuntu-latest - runs-on: [self-hosted, ubuntu-latest] + pick-runner: + runs-on: 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: - uses: actions/checkout@v4 @@ -30,10 +41,10 @@ jobs: with: toolchain: stable override: true - + - name: Build documentation run: cargo doc --no-deps --release - + - name: Prepare documentation for Pages run: | @@ -47,28 +58,26 @@ jobs: run: | mkdir -p testcov cargo tarpaulin --engine llvm --out Html --out Json - + - name: Check for tarpaulin-report.html run: | if [ ! -f tarpaulin-report.html ]; then echo "tarpaulin-report.html not found!" exit 1 fi - + - name: Export tarpaulin coverage badge JSON + # extract raw coverage and round to 2 decimal places run: | - # extract raw coverage - coverage=$(jq '.coverage' tarpaulin-report.json) - # round to 2 decimal places - formatted=$(printf "%.2f" "$coverage") - # build the badge JSON using the pre-formatted string - jq --arg message "$formatted" \ - '{schemaVersion:1, - label:"tarpaulin-report", - message:$message, - color:"blue"}' \ - tarpaulin-report.json \ - > tarpaulin-badge.json + coverage=$(jq '.coverage' tarpaulin-report.json) + formatted=$(printf "%.2f" "$coverage") + jq --arg message "$formatted" \ + '{schemaVersion:1, + label:"tarpaulin-report", + message:$message, + color:"blue"}' \ + tarpaulin-report.json \ + > tarpaulin-badge.json - name: Save last commit date JSON run: | @@ -80,7 +89,7 @@ jobs: color:"blue"}' \ <(echo '{}') \ > last-commit-date.json - + - name: Copy files to output directory run: | mkdir output diff --git a/.github/workflows/run-unit-tests.yml b/.github/workflows/run-unit-tests.yml index 87512a0..0483f69 100644 --- a/.github/workflows/run-unit-tests.yml +++ b/.github/workflows/run-unit-tests.yml @@ -11,11 +11,23 @@ concurrency: cancel-in-progress: true 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: + needs: pick-runner if: github.event.pull_request.draft == false name: run-unit-tests - # runs-on: ubuntu-latest - runs-on: [self-hosted, ubuntu-latest] + runs-on: ${{ fromJson(needs.pick-runner.outputs.runner) }} env: CARGO_TERM_COLOR: always