Record unictest history #416
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: unictest-history | |
| run-name: Record unictest history | |
| # Runs after brgen-build finishes and appends that run's unictest results to the | |
| # append-only `unictest-history` orphan branch (one snapshot per commit). It also | |
| # writes a regression diff vs the previous recorded run into the job summary. | |
| # Kept as a standalone workflow so the write token is isolated to this tiny | |
| # recorder and the existing build/test jobs stay read-only. See ADR 0036. | |
| # | |
| # Note: the push below uses GITHUB_TOKEN, so it does NOT trigger build/test | |
| # (GitHub suppresses workflow runs from GITHUB_TOKEN pushes) - no build loop. | |
| on: | |
| workflow_run: | |
| workflows: ["brgen-build"] | |
| types: [completed] | |
| permissions: | |
| contents: write # push to the unictest-history branch | |
| actions: read # download the triggering run's artifact | |
| # Serialize recorders so pushes to the single history branch never race. | |
| concurrency: | |
| group: unictest-history | |
| cancel-in-progress: false | |
| jobs: | |
| record: | |
| # Only record main pushes (the branch whose trend we track). Record even when | |
| # tests failed - failures are exactly what we want in the history. | |
| if: > | |
| github.event.workflow_run.head_branch == 'main' && | |
| github.event.workflow_run.event == 'push' | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| steps: | |
| - name: Checkout tested commit | |
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 | |
| with: | |
| ref: ${{ github.event.workflow_run.head_sha }} | |
| fetch-depth: 0 | |
| - name: Download unictest results from triggering run | |
| id: dl | |
| continue-on-error: true | |
| uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 | |
| with: | |
| name: unictest-results | |
| run-id: ${{ github.event.workflow_run.id }} | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| path: unictest-results | |
| - name: Prepare history branch | |
| if: steps.dl.outcome == 'success' && hashFiles('unictest-results/test_results.json') != '' | |
| run: | | |
| set -euo pipefail | |
| # Check out (or create) the orphan history branch in a worktree. `hist` | |
| # then holds the PREVIOUS runs - the diff baseline - until the current | |
| # run is recorded into it by the last step. | |
| git fetch origin unictest-history || true | |
| if git ls-remote --exit-code --heads origin unictest-history >/dev/null 2>&1; then | |
| git worktree add -B unictest-history hist origin/unictest-history | |
| else | |
| git worktree add --detach hist | |
| git -C hist switch --orphan unictest-history | |
| fi | |
| - name: Regression diff (job summary) | |
| if: steps.dl.outcome == 'success' && hashFiles('unictest-results/test_results.json') != '' | |
| run: | | |
| set -euo pipefail | |
| python3 rebrgen/script/diff_unictest_history.py \ | |
| --current unictest-results/test_results.json \ | |
| --history-dir hist \ | |
| --out "$GITHUB_STEP_SUMMARY" | |
| - name: Record and push | |
| if: steps.dl.outcome == 'success' && hashFiles('unictest-results/test_results.json') != '' | |
| env: | |
| SHA: ${{ github.event.workflow_run.head_sha }} | |
| DATE: ${{ github.event.workflow_run.head_commit.timestamp }} | |
| run: | | |
| set -euo pipefail | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| record() { | |
| python3 rebrgen/script/record_unictest_history.py \ | |
| --results unictest-results/test_results.json \ | |
| --sha "$SHA" --date "$DATE" --out-dir hist | |
| git -C hist add -A | |
| } | |
| record | |
| if git -C hist diff --cached --quiet; then | |
| echo "no changes to record" | |
| exit 0 | |
| fi | |
| git -C hist commit -m "unictest: record ${SHA}" | |
| # Serialized by the concurrency group, so this normally succeeds first | |
| # try. On the rare race (e.g. a manual push), sync to remote and | |
| # re-record: summary.jsonl is regenerated from runs/, so the union is | |
| # conflict-free (no rebase needed). | |
| for attempt in 1 2 3 4 5; do | |
| if git -C hist push origin unictest-history; then | |
| exit 0 | |
| fi | |
| echo "push rejected (attempt ${attempt}); syncing with remote and re-recording" | |
| git -C hist fetch origin unictest-history | |
| git -C hist reset --hard origin/unictest-history | |
| record | |
| git -C hist commit -m "unictest: record ${SHA}" | |
| done | |
| echo "failed to push history after retries" >&2 | |
| exit 1 |