|
| 1 | +name: producer differential |
| 2 | + |
| 3 | +# The SHORT contour: two jobs that answer in minutes and gate every PR that |
| 4 | +# touches the producer. |
| 5 | +# |
| 6 | +# producer-contract fixture-scale unit tests on synthetic facts. No .NET, no |
| 7 | +# corpus, no network. Seconds. |
| 8 | +# mini-corpus-diff own-check at the PR's merge base AND at its head over the |
| 9 | +# frozen corpus/mini, compared through OwnAudit's projections. |
| 10 | +# Minutes. |
| 11 | +# |
| 12 | +# The long contour — a real corpus, hours — is OwnAudit's `corpus-differential.yml`, |
| 13 | +# run manually and nightly. Keeping it off the PR path is the whole point: a job |
| 14 | +# people wait hours for is a job people learn to bypass, and a seven-hour red X |
| 15 | +# holds the change hostage to the hardware rather than to its own correctness. |
| 16 | +# |
| 17 | +# WHY THIS IS PATH-FILTERED |
| 18 | +# A README typo cannot change what the producer says about C#, so it does not get a |
| 19 | +# .NET build and two extractor runs. Compute spent proving something that could not |
| 20 | +# have changed is not thoroughness; it is a slower queue for everyone else. |
| 21 | +# |
| 22 | +# WHY THE COMPARATOR IS CHECKED OUT INSTEAD OF VENDORED |
| 23 | +# Own.NET produces SARIF; OwnAudit compares corpora. Copying the projections here |
| 24 | +# would put a second implementation of finding identity in the repository that emits |
| 25 | +# the findings — and the two would drift, quietly, in the direction that made CI |
| 26 | +# green. The cost is a cross-repo checkout; the alternative is a checker that grades |
| 27 | +# its own homework. |
| 28 | + |
| 29 | +permissions: |
| 30 | + contents: read |
| 31 | + |
| 32 | +on: |
| 33 | + pull_request: |
| 34 | + paths: |
| 35 | + - "frontend/roslyn/**" |
| 36 | + - "ownlang/ownir.py" |
| 37 | + - "ownlang/diag_sarif.py" |
| 38 | + - "ownlang/diagnostics.py" |
| 39 | + - "spec/ownir*" |
| 40 | + - "scripts/own-check*" |
| 41 | + - "corpus/mini/**" |
| 42 | + - "tests/test_ownir*.py" |
| 43 | + - "tests/test_diag_sarif.py" |
| 44 | + - ".github/workflows/producer-differential.yml" |
| 45 | + push: |
| 46 | + branches: ["**"] |
| 47 | + paths: |
| 48 | + - "frontend/roslyn/**" |
| 49 | + - "ownlang/ownir.py" |
| 50 | + - "ownlang/diag_sarif.py" |
| 51 | + - "ownlang/diagnostics.py" |
| 52 | + - "spec/ownir*" |
| 53 | + - "scripts/own-check*" |
| 54 | + - "corpus/mini/**" |
| 55 | + - "tests/test_ownir*.py" |
| 56 | + - "tests/test_diag_sarif.py" |
| 57 | + - ".github/workflows/producer-differential.yml" |
| 58 | + workflow_dispatch: |
| 59 | + |
| 60 | +concurrency: |
| 61 | + group: producer-differential-${{ github.ref }} |
| 62 | + cancel-in-progress: true |
| 63 | + |
| 64 | +jobs: |
| 65 | + # The fixture-scale contract. Fast enough to run on a push as well as a PR, so a |
| 66 | + # branch that has not opened a PR yet still gets the answer. |
| 67 | + producer-contract: |
| 68 | + name: producer contract (fixtures, no .NET) |
| 69 | + runs-on: ubuntu-latest |
| 70 | + steps: |
| 71 | + - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 |
| 72 | + - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5 |
| 73 | + with: |
| 74 | + python-version: "3.11" |
| 75 | + |
| 76 | + # The physical-anchor contract: an old column-less fact still works and emits |
| 77 | + # no startColumn; a column reaches Finding.column and SARIF; an INVALID column |
| 78 | + # fails loud at load() while degrading on the tolerant door; the old and new |
| 79 | + # producers agree on every pattern-level field over one fixture; and the |
| 80 | + # renderer's caret heuristic is nowhere on the path. |
| 81 | + - name: physical-anchor column contract |
| 82 | + run: python tests/test_ownir_column.py |
| 83 | + |
| 84 | + # The bridge and both SARIF projections around it. A column change that broke |
| 85 | + # the OwnIR fact vocabulary or the SARIF log shape would land here first. |
| 86 | + - name: OwnIR bridge + SARIF projections |
| 87 | + run: | |
| 88 | + set -euo pipefail |
| 89 | + python tests/test_ownir.py |
| 90 | + python tests/test_diag_sarif.py |
| 91 | +
|
| 92 | + # The frozen corpus is an input, and an input with a broken file is a run that |
| 93 | + # measures nothing. This does not compile C# (that is the next job's .NET |
| 94 | + # build); it checks the corpus is present and its inventory has not silently |
| 95 | + # shrunk, which is the failure a path filter cannot catch. |
| 96 | + - name: frozen mini corpus is intact |
| 97 | + run: | |
| 98 | + set -euo pipefail |
| 99 | + n=$(find corpus/mini -maxdepth 1 -name '*.cs' | wc -l) |
| 100 | + [ "$n" -ge 10 ] \ |
| 101 | + || { echo "FAIL: corpus/mini has $n .cs files, expected at least 10 — a frozen corpus that shrank is a corpus change, not a producer change (see corpus/mini/README.md)"; exit 1; } |
| 102 | + test -f corpus/mini/README.md \ |
| 103 | + || { echo "FAIL: corpus/mini/README.md is missing — the freeze policy is part of the corpus"; exit 1; } |
| 104 | + echo "corpus/mini: $n .cs files" |
| 105 | +
|
| 106 | + # base-vs-head over the frozen corpus. PR and manual only: the comparison is |
| 107 | + # defined against a MERGE BASE, and a bare push has no target branch to take one |
| 108 | + # against. (`HEAD~1` would answer a different question — "did the last commit |
| 109 | + # change anything" — and would pass trivially on any branch that rebases.) |
| 110 | + mini-corpus-diff: |
| 111 | + name: mini corpus diff (merge-base vs head) |
| 112 | + if: github.event_name != 'push' |
| 113 | + runs-on: ubuntu-latest |
| 114 | + timeout-minutes: 30 |
| 115 | + steps: |
| 116 | + - name: Check out Own.NET (the producer) |
| 117 | + uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 |
| 118 | + with: |
| 119 | + # Full history: the runner takes a merge base and checks out two commits |
| 120 | + # as git worktrees. A shallow clone has neither. |
| 121 | + fetch-depth: 0 |
| 122 | + |
| 123 | + - name: Check out OwnAudit (the comparator) |
| 124 | + uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 |
| 125 | + with: |
| 126 | + repository: PhysShell/OwnAudit |
| 127 | + path: ownaudit |
| 128 | + persist-credentials: false |
| 129 | + |
| 130 | + - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5 |
| 131 | + with: |
| 132 | + python-version: "3.11" |
| 133 | + |
| 134 | + - uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # v4 |
| 135 | + with: |
| 136 | + dotnet-version: "8.0.x" |
| 137 | + |
| 138 | + # The extractor is built twice (once per worktree), so restoring from cache is |
| 139 | + # most of the difference between "a few minutes" and "long enough to be |
| 140 | + # skipped". |
| 141 | + - name: Cache NuGet packages |
| 142 | + uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4 |
| 143 | + with: |
| 144 | + path: ~/.nuget/packages |
| 145 | + key: nuget-${{ runner.os }}-${{ hashFiles('frontend/roslyn/**/*.csproj') }} |
| 146 | + restore-keys: nuget-${{ runner.os }}- |
| 147 | + |
| 148 | + - name: Resolve the baseline |
| 149 | + id: base |
| 150 | + env: |
| 151 | + BASE_SHA: ${{ github.event.pull_request.base.sha }} |
| 152 | + run: | |
| 153 | + set -euo pipefail |
| 154 | + # workflow_dispatch has no PR context; fall back to the default branch. |
| 155 | + if [ -z "${BASE_SHA:-}" ]; then |
| 156 | + git fetch --quiet origin main |
| 157 | + BASE_SHA=$(git rev-parse origin/main) |
| 158 | + fi |
| 159 | + merge_base=$(git merge-base "$BASE_SHA" HEAD) |
| 160 | + echo "sha=$merge_base" >> "$GITHUB_OUTPUT" |
| 161 | + # BOOTSTRAP: the very first PR to add corpus/mini has no corpus on the base |
| 162 | + # side. own-check would then be handed a path that does not exist, exit in |
| 163 | + # its hard-error tier, and abort the run — a confusing red X on the one PR |
| 164 | + # that cannot possibly have regressed anything. Detect it and say so |
| 165 | + # instead. This is NOT a fallback to an empty baseline: an absent corpus and |
| 166 | + # a corpus that produced no findings are different claims, and diffing |
| 167 | + # against the second when you have the first is how a whole corpus silently |
| 168 | + # reads as "removed". |
| 169 | + if git ls-tree -d --name-only "$merge_base" -- corpus/mini | grep -q .; then |
| 170 | + echo "have_baseline=true" >> "$GITHUB_OUTPUT" |
| 171 | + else |
| 172 | + echo "have_baseline=false" >> "$GITHUB_OUTPUT" |
| 173 | + fi |
| 174 | + echo "merge base: $merge_base" |
| 175 | +
|
| 176 | + - name: No baseline corpus yet |
| 177 | + if: steps.base.outputs.have_baseline != 'true' |
| 178 | + run: | |
| 179 | + { |
| 180 | + echo "## Mini corpus diff: SKIPPED" |
| 181 | + echo |
| 182 | + echo "\`corpus/mini\` does not exist at the merge base" |
| 183 | + echo "(\`${{ steps.base.outputs.sha }}\`), so there is no baseline to compare" |
| 184 | + echo "against. This is expected on the PR that introduces the corpus, and on" |
| 185 | + echo "no other PR." |
| 186 | + echo |
| 187 | + echo "The job is skipped rather than run against an empty baseline: an absent" |
| 188 | + echo "corpus and a corpus that produced no findings are different claims, and" |
| 189 | + echo "treating the first as the second would report the entire corpus as newly" |
| 190 | + echo "appeared." |
| 191 | + } >> "$GITHUB_STEP_SUMMARY" |
| 192 | +
|
| 193 | + - name: Run the differential |
| 194 | + id: diff |
| 195 | + if: steps.base.outputs.have_baseline == 'true' |
| 196 | + working-directory: ownaudit |
| 197 | + run: | |
| 198 | + set -euo pipefail |
| 199 | + PYTHONUTF8=1 PYTHONPATH=. python3 -m corpusdiff.run_differential \ |
| 200 | + --repo .. \ |
| 201 | + --base "${{ steps.base.outputs.sha }}" \ |
| 202 | + --head HEAD \ |
| 203 | + --corpus corpus/mini \ |
| 204 | + --out "$GITHUB_WORKSPACE/artifacts/mini-diff" \ |
| 205 | + --expect corpusdiff/expectations/own-check-start-column.json \ |
| 206 | + --run-label "pr-${{ github.run_id }}" |
| 207 | +
|
| 208 | + - name: Job summary |
| 209 | + if: always() && steps.base.outputs.have_baseline == 'true' |
| 210 | + run: | |
| 211 | + if [ -f artifacts/mini-diff/report.md ]; then |
| 212 | + cat artifacts/mini-diff/report.md >> "$GITHUB_STEP_SUMMARY" |
| 213 | + else |
| 214 | + echo "The differential produced no report - see the step log. Exit 2 means" \ |
| 215 | + >> "$GITHUB_STEP_SUMMARY" |
| 216 | + echo "UNDECIDED (bad input, a malformed expectation, or a producer that" \ |
| 217 | + >> "$GITHUB_STEP_SUMMARY" |
| 218 | + echo "failed to produce a verdict), not 'no differences'." >> "$GITHUB_STEP_SUMMARY" |
| 219 | + fi |
| 220 | +
|
| 221 | + # On failure too: a run that ended in violations is exactly the one whose |
| 222 | + # intermediates someone needs to read. Both sides' SARIF, both normalized |
| 223 | + # payloads, the provenance manifests, run.json and the report all travel. |
| 224 | + - name: Upload the differential artifacts |
| 225 | + if: always() && steps.base.outputs.have_baseline == 'true' |
| 226 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 |
| 227 | + with: |
| 228 | + name: mini-corpus-diff-${{ github.run_id }} |
| 229 | + path: artifacts/mini-diff/ |
| 230 | + if-no-files-found: warn |
| 231 | + retention-days: 14 |
0 commit comments