|
| 1 | +name: Baseline diff |
| 2 | + |
| 3 | +# Report artifacts expire after 90 days and the baseline branch never |
| 4 | +# changes, so the baseline is re-run weekly. |
| 5 | + |
| 6 | +on: |
| 7 | + workflow_run: |
| 8 | + workflows: ["Engine verify", "Verify recording (real capture)"] |
| 9 | + types: [completed] |
| 10 | + branches: [main] |
| 11 | + schedule: |
| 12 | + - cron: "17 2 * * 1" |
| 13 | + workflow_dispatch: |
| 14 | + inputs: |
| 15 | + main-run: |
| 16 | + description: "Run id on main to compare (Engine verify or real capture)" |
| 17 | + required: true |
| 18 | + baseline-run: |
| 19 | + description: "Baseline run id (default: the latest of the same workflow on scratch/prod-baseline)" |
| 20 | + default: "" |
| 21 | + |
| 22 | +permissions: |
| 23 | + contents: read |
| 24 | + |
| 25 | +concurrency: |
| 26 | + group: baseline-diff-${{ github.event.workflow_run.id || inputs.main-run || 'refresh' }} |
| 27 | + cancel-in-progress: false |
| 28 | + |
| 29 | +env: |
| 30 | + BASELINE_BRANCH: scratch/prod-baseline |
| 31 | + |
| 32 | +jobs: |
| 33 | + refresh: |
| 34 | + if: github.event_name == 'schedule' |
| 35 | + runs-on: blacksmith-2vcpu-ubuntu-2404 |
| 36 | + permissions: |
| 37 | + actions: write |
| 38 | + steps: |
| 39 | + - name: Re-run the baseline |
| 40 | + env: |
| 41 | + GH_TOKEN: ${{ github.token }} |
| 42 | + run: | |
| 43 | + gh workflow run engine-verify.yml --repo "$GITHUB_REPOSITORY" --ref "$BASELINE_BRANCH" --raw-field tier=full |
| 44 | + gh workflow run verify-recording.yml --repo "$GITHUB_REPOSITORY" --ref "$BASELINE_BRANCH" \ |
| 45 | + --raw-field tier=full --raw-field repeat=3 --raw-field runners=both |
| 46 | +
|
| 47 | + diff: |
| 48 | + permissions: |
| 49 | + contents: read |
| 50 | + actions: read |
| 51 | + if: >- |
| 52 | + github.event_name == 'workflow_dispatch' || |
| 53 | + (github.event_name == 'workflow_run' && github.event.workflow_run.event == 'schedule') |
| 54 | + runs-on: blacksmith-2vcpu-ubuntu-2404 |
| 55 | + steps: |
| 56 | + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 |
| 57 | + with: |
| 58 | + persist-credentials: false |
| 59 | + |
| 60 | + - name: Runs |
| 61 | + id: runs |
| 62 | + env: |
| 63 | + GH_TOKEN: ${{ github.token }} |
| 64 | + MAIN_RUN: ${{ github.event.workflow_run.id || inputs.main-run }} |
| 65 | + BASELINE_INPUT: ${{ inputs.baseline-run }} |
| 66 | + run: | |
| 67 | + set -euo pipefail |
| 68 | + workflow=$(gh run view "$MAIN_RUN" --repo "$GITHUB_REPOSITORY" --json workflowDatabaseId --jq .workflowDatabaseId) |
| 69 | + baseline="$BASELINE_INPUT" |
| 70 | + if [[ -z "$baseline" ]]; then |
| 71 | + # Baseline runs fail (0.6.0 has known bugs), but a run with a |
| 72 | + # cancelled or timed-out job stopped before reporting every case. |
| 73 | + for candidate in $(gh run list --repo "$GITHUB_REPOSITORY" --workflow "$workflow" --branch "$BASELINE_BRANCH" \ |
| 74 | + --limit 20 --json databaseId,conclusion \ |
| 75 | + --jq '.[] | select(.conclusion == "success" or .conclusion == "failure") | .databaseId'); do |
| 76 | + stopped=$(gh run view "$candidate" --repo "$GITHUB_REPOSITORY" --json conclusion,jobs \ |
| 77 | + --jq '[.conclusion, .jobs[].conclusion] | map(select(. == "cancelled" or . == "timed_out")) | length') |
| 78 | + if [[ "$stopped" == 0 ]]; then |
| 79 | + baseline="$candidate" |
| 80 | + break |
| 81 | + fi |
| 82 | + done |
| 83 | + fi |
| 84 | + if [[ -z "$baseline" ]]; then |
| 85 | + echo "::error::no completed baseline run of workflow $workflow on $BASELINE_BRANCH" |
| 86 | + exit 1 |
| 87 | + fi |
| 88 | + echo "main=$MAIN_RUN" >> "$GITHUB_OUTPUT" |
| 89 | + echo "baseline=$baseline" >> "$GITHUB_OUTPUT" |
| 90 | + echo "Comparing main run $MAIN_RUN with baseline run $baseline" | tee -a "$GITHUB_STEP_SUMMARY" |
| 91 | +
|
| 92 | + - name: Download reports |
| 93 | + env: |
| 94 | + GH_TOKEN: ${{ github.token }} |
| 95 | + MAIN_RUN: ${{ steps.runs.outputs.main }} |
| 96 | + BASELINE_RUN: ${{ steps.runs.outputs.baseline }} |
| 97 | + run: | |
| 98 | + set -euo pipefail |
| 99 | + for side in main baseline; do |
| 100 | + run=$([[ $side == main ]] && echo "$MAIN_RUN" || echo "$BASELINE_RUN") |
| 101 | + dest="$RUNNER_TEMP/reports/$side" |
| 102 | + mkdir -p "$dest" |
| 103 | + # Real capture also uploads its reports alone; runs from before |
| 104 | + # that only have the artifact with the recordings. |
| 105 | + names=$(gh api "repos/$GITHUB_REPOSITORY/actions/runs/$run/artifacts" --paginate --jq '.artifacts[].name') |
| 106 | + if grep -q '^verify-report-' <<< "$names"; then |
| 107 | + pattern='verify-report-*' |
| 108 | + elif grep -q '^verify-recording-report-' <<< "$names"; then |
| 109 | + pattern='verify-recording-report-*' |
| 110 | + elif grep -q '^verify-recording-' <<< "$names"; then |
| 111 | + pattern='verify-recording-*' |
| 112 | + else |
| 113 | + echo "::error::run $run has no verification reports" |
| 114 | + exit 1 |
| 115 | + fi |
| 116 | + gh run download "$run" --repo "$GITHUB_REPOSITORY" --dir "$dest" --pattern "$pattern" |
| 117 | + find "$dest" -type d -name verify-scratch -prune -exec rm -r {} + |
| 118 | + echo "$side: $(find "$dest" -name '*.jsonl' | wc -l) report files" |
| 119 | + done |
| 120 | +
|
| 121 | + - name: Baseline covers main's runners |
| 122 | + shell: bash |
| 123 | + run: | |
| 124 | + set -euo pipefail |
| 125 | + # Lanes as diff.py names them: shard numbers and tiers dropped. |
| 126 | + lanes() { |
| 127 | + local dir |
| 128 | + for dir in "$1"/verify-*/; do |
| 129 | + if [[ -d "$dir" ]]; then basename "$dir"; fi |
| 130 | + done | sed -E 's/^verify-recording-report-/verify-recording-/; s/-(fast|full)(-[0-9]+)?$//' | sort -u |
| 131 | + } |
| 132 | + main_lanes=$(lanes "$RUNNER_TEMP/reports/main") |
| 133 | + baseline_lanes=$(lanes "$RUNNER_TEMP/reports/baseline") |
| 134 | + if [[ -z "$main_lanes" ]]; then |
| 135 | + echo "::error::main's run has no report directories" |
| 136 | + exit 1 |
| 137 | + fi |
| 138 | + missing=$(comm -23 <(echo "$main_lanes") <(echo "$baseline_lanes")) |
| 139 | + if [[ -n "$missing" ]]; then |
| 140 | + echo "::error::the baseline run has no reports for: $(echo $missing)" |
| 141 | + exit 1 |
| 142 | + fi |
| 143 | +
|
| 144 | + - name: Diff |
| 145 | + run: | |
| 146 | + python3 scripts/verify/diff.py \ |
| 147 | + "$RUNNER_TEMP/reports/baseline" "$RUNNER_TEMP/reports/main" \ |
| 148 | + --na scripts/verify/baseline-na.tsv \ |
| 149 | + --title "cap-v0.6.0 baseline vs main" \ |
| 150 | + --fail-on-worse > "$RUNNER_TEMP/baseline-diff.md" |
| 151 | + status=$? |
| 152 | + cat "$RUNNER_TEMP/baseline-diff.md" >> "$GITHUB_STEP_SUMMARY" |
| 153 | + exit "$status" |
| 154 | + shell: bash {0} |
| 155 | + |
| 156 | + - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 |
| 157 | + if: always() |
| 158 | + with: |
| 159 | + name: baseline-diff |
| 160 | + path: ${{ runner.temp }}/baseline-diff.md |
| 161 | + if-no-files-found: ignore |
0 commit comments