|
| 1 | +name: "Beater Eval Gate" |
| 2 | +description: >- |
| 3 | + Run a Beater statistical eval gate in CI and post a pass / fail / |
| 4 | + INCONCLUSIVE verdict — with effect size, confidence interval, p-value, and |
| 5 | + (when underpowered) the minimum detectable effect and how many more cases |
| 6 | + would make the comparison conclusive — to the step summary and, optionally, |
| 7 | + a sticky PR comment. Runs entirely against the local `--data-dir` store: |
| 8 | + no Beater server, no API keys. |
| 9 | +author: "Beater" |
| 10 | +branding: |
| 11 | + icon: "check-circle" |
| 12 | + color: "green" |
| 13 | + |
| 14 | +inputs: |
| 15 | + data-dir: |
| 16 | + description: >- |
| 17 | + Beater data directory holding gates.sqlite / experiments.sqlite, |
| 18 | + produced by the eval steps earlier in the job (or by demo-fixture mode). |
| 19 | + required: false |
| 20 | + default: ".beater" |
| 21 | + tenant-id: |
| 22 | + description: "Tenant id the gate belongs to." |
| 23 | + required: false |
| 24 | + default: "demo" |
| 25 | + project-id: |
| 26 | + description: "Project id the gate belongs to." |
| 27 | + required: false |
| 28 | + default: "demo" |
| 29 | + gate-id: |
| 30 | + description: "Gate id to run." |
| 31 | + required: false |
| 32 | + default: "main" |
| 33 | + experiment-run-id: |
| 34 | + description: >- |
| 35 | + Specific experiment run to gate on. Empty = the gate's latest |
| 36 | + experiment run. |
| 37 | + required: false |
| 38 | + default: "" |
| 39 | + beaterctl-path: |
| 40 | + description: >- |
| 41 | + Path to a prebuilt beaterctl binary. Empty = build it from this |
| 42 | + action's checkout with cargo (requires a Rust toolchain on the runner; |
| 43 | + the first uncached build is slow — prefer a prebuilt binary or a cargo |
| 44 | + cache in latency-sensitive workflows). |
| 45 | + required: false |
| 46 | + default: "" |
| 47 | + demo-fixture: |
| 48 | + description: >- |
| 49 | + "true" seeds the deterministic demo gate + experiments |
| 50 | + (`beaterctl gate-run-fixture`) into data-dir before running. Zero-config |
| 51 | + demo/self-test mode; uses tenant/project/gate demo/demo/main. |
| 52 | + required: false |
| 53 | + default: "false" |
| 54 | + fail-on-gate-failure: |
| 55 | + description: >- |
| 56 | + "true" (default) fails the step when the gate does not pass, so the |
| 57 | + gate can be a required check. "false" always succeeds and only reports |
| 58 | + — the verdict is still available via outputs. |
| 59 | + required: false |
| 60 | + default: "true" |
| 61 | + github-token: |
| 62 | + description: >- |
| 63 | + Token used to upsert a sticky verdict comment on the pull request. |
| 64 | + Empty = no comment (the step summary is always written). Needs |
| 65 | + `pull-requests: write`. |
| 66 | + required: false |
| 67 | + default: "" |
| 68 | + comment-tag: |
| 69 | + description: >- |
| 70 | + Marker distinguishing this gate's sticky comment when a workflow runs |
| 71 | + several gates on one PR. |
| 72 | + required: false |
| 73 | + default: "default" |
| 74 | + |
| 75 | +outputs: |
| 76 | + verdict: |
| 77 | + description: "pass | fail | inconclusive" |
| 78 | + value: ${{ steps.render.outputs.verdict }} |
| 79 | + passed: |
| 80 | + description: "true when the gate passed under its inconclusive policy" |
| 81 | + value: ${{ steps.render.outputs.passed }} |
| 82 | + decision: |
| 83 | + description: "Raw GateDecision: pass | fail_regression | inconclusive" |
| 84 | + value: ${{ steps.render.outputs.decision }} |
| 85 | + reason: |
| 86 | + description: "The gate's human-readable reason string" |
| 87 | + value: ${{ steps.render.outputs.reason }} |
| 88 | + report-path: |
| 89 | + description: "Path to the raw gate-run JSON report" |
| 90 | + value: ${{ steps.gate.outputs.report-path }} |
| 91 | + |
| 92 | +# Every `${{ inputs.* }}` below is passed to bash via `env:`, never spliced |
| 93 | +# into the script text: interpolation into a `run:` body happens before bash |
| 94 | +# parses it, so a crafted input value could otherwise inject shell commands. |
| 95 | +runs: |
| 96 | + using: "composite" |
| 97 | + steps: |
| 98 | + - name: Resolve beaterctl |
| 99 | + id: resolve |
| 100 | + shell: bash |
| 101 | + env: |
| 102 | + BEATERCTL_INPUT: ${{ inputs.beaterctl-path }} |
| 103 | + run: | |
| 104 | + set -euo pipefail |
| 105 | + if [ -n "$BEATERCTL_INPUT" ]; then |
| 106 | + BEATERCTL="$BEATERCTL_INPUT" |
| 107 | + else |
| 108 | + echo "::group::Building beaterctl from ${GITHUB_ACTION_PATH}" |
| 109 | + # Pin --target-dir: a consumer job exporting CARGO_TARGET_DIR would |
| 110 | + # otherwise relocate the build and break the path below. |
| 111 | + cargo build --release -q -p beaterctl \ |
| 112 | + --manifest-path "${GITHUB_ACTION_PATH}/Cargo.toml" \ |
| 113 | + --target-dir "${GITHUB_ACTION_PATH}/target" |
| 114 | + echo "::endgroup::" |
| 115 | + BEATERCTL="${GITHUB_ACTION_PATH}/target/release/beaterctl" |
| 116 | + fi |
| 117 | + "$BEATERCTL" --help >/dev/null |
| 118 | + echo "beaterctl=$BEATERCTL" >> "$GITHUB_OUTPUT" |
| 119 | +
|
| 120 | + - name: Seed demo fixture |
| 121 | + if: ${{ inputs.demo-fixture == 'true' }} |
| 122 | + shell: bash |
| 123 | + env: |
| 124 | + BEATERCTL: ${{ steps.resolve.outputs.beaterctl }} |
| 125 | + DATA_DIR: ${{ inputs.data-dir }} |
| 126 | + run: | |
| 127 | + set -euo pipefail |
| 128 | + "$BEATERCTL" gate-run-fixture --data-dir "$DATA_DIR" >/dev/null |
| 129 | +
|
| 130 | + - name: Run the gate |
| 131 | + id: gate |
| 132 | + shell: bash |
| 133 | + env: |
| 134 | + BEATERCTL: ${{ steps.resolve.outputs.beaterctl }} |
| 135 | + DATA_DIR: ${{ inputs.data-dir }} |
| 136 | + TENANT_ID: ${{ inputs.tenant-id }} |
| 137 | + PROJECT_ID: ${{ inputs.project-id }} |
| 138 | + GATE_ID: ${{ inputs.gate-id }} |
| 139 | + EXPERIMENT_RUN_ID: ${{ inputs.experiment-run-id }} |
| 140 | + run: | |
| 141 | + set -euo pipefail |
| 142 | + REPORT="$(mktemp "${RUNNER_TEMP}/beater-gate-report.XXXXXX.json")" |
| 143 | + ARGS=(gate-run |
| 144 | + --data-dir "$DATA_DIR" |
| 145 | + --tenant-id "$TENANT_ID" |
| 146 | + --project-id "$PROJECT_ID" |
| 147 | + --gate-id "$GATE_ID") |
| 148 | + if [ -n "$EXPERIMENT_RUN_ID" ]; then |
| 149 | + ARGS+=(--experiment-run-id "$EXPERIMENT_RUN_ID") |
| 150 | + fi |
| 151 | + # gate-run exits 1 on a non-passing gate; capture instead of aborting |
| 152 | + # so the verdict is rendered either way. |
| 153 | + GATE_EXIT=0 |
| 154 | + "$BEATERCTL" "${ARGS[@]}" > "$REPORT" || GATE_EXIT=$? |
| 155 | + if [ ! -s "$REPORT" ]; then |
| 156 | + echo "gate-run produced no report (exit ${GATE_EXIT})" >&2 |
| 157 | + exit "$GATE_EXIT" |
| 158 | + fi |
| 159 | + echo "report-path=$REPORT" >> "$GITHUB_OUTPUT" |
| 160 | +
|
| 161 | + - name: Render verdict |
| 162 | + id: render |
| 163 | + shell: bash |
| 164 | + env: |
| 165 | + REPORT: ${{ steps.gate.outputs.report-path }} |
| 166 | + COMMENT_TAG: ${{ inputs.comment-tag }} |
| 167 | + run: | |
| 168 | + set -euo pipefail |
| 169 | + COMMENT_FILE="$(mktemp "${RUNNER_TEMP}/beater-gate-comment.XXXXXX.md")" |
| 170 | + python3 "${GITHUB_ACTION_PATH}/scripts/gate-action/render_verdict.py" \ |
| 171 | + --report "$REPORT" \ |
| 172 | + --summary "$GITHUB_STEP_SUMMARY" \ |
| 173 | + --outputs "$GITHUB_OUTPUT" \ |
| 174 | + --comment-file "$COMMENT_FILE" \ |
| 175 | + --comment-tag "$COMMENT_TAG" |
| 176 | + echo "comment-file=$COMMENT_FILE" >> "$GITHUB_OUTPUT" |
| 177 | +
|
| 178 | + - name: Upsert sticky PR comment |
| 179 | + if: ${{ inputs.github-token != '' && github.event_name == 'pull_request' }} |
| 180 | + shell: bash |
| 181 | + env: |
| 182 | + GH_TOKEN: ${{ inputs.github-token }} |
| 183 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 184 | + # Built as an env value (not spliced into the script), and matched in |
| 185 | + # jq via env.MARKER so quotes/backslashes in the tag cannot break the |
| 186 | + # filter program. |
| 187 | + MARKER: "<!-- beater-eval-gate:${{ inputs.comment-tag }} -->" |
| 188 | + BODY_FILE: ${{ steps.render.outputs.comment-file }} |
| 189 | + run: | |
| 190 | + set -euo pipefail |
| 191 | + EXISTING=$(gh api "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" \ |
| 192 | + --paginate --jq '.[] | select(.body | startswith(env.MARKER)) | .id' | head -n1) |
| 193 | + if [ -n "$EXISTING" ]; then |
| 194 | + gh api --method PATCH \ |
| 195 | + "repos/${GITHUB_REPOSITORY}/issues/comments/${EXISTING}" \ |
| 196 | + -F "body=@${BODY_FILE}" >/dev/null |
| 197 | + else |
| 198 | + gh api --method POST \ |
| 199 | + "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" \ |
| 200 | + -F "body=@${BODY_FILE}" >/dev/null |
| 201 | + fi |
| 202 | +
|
| 203 | + - name: Enforce gate result |
| 204 | + if: ${{ inputs.fail-on-gate-failure == 'true' }} |
| 205 | + shell: bash |
| 206 | + env: |
| 207 | + PASSED: ${{ steps.render.outputs.passed }} |
| 208 | + VERDICT: ${{ steps.render.outputs.verdict }} |
| 209 | + REASON: ${{ steps.render.outputs.reason }} |
| 210 | + run: | |
| 211 | + set -euo pipefail |
| 212 | + if [ "$PASSED" != "true" ]; then |
| 213 | + echo "Beater eval gate verdict: ${VERDICT} — ${REASON}" >&2 |
| 214 | + exit 1 |
| 215 | + fi |
0 commit comments