|
| 1 | +name: Decision model lint |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, reopened, synchronize, labeled, unlabeled] |
| 6 | + |
| 7 | +concurrency: |
| 8 | + group: ${{ github.workflow }}-${{ github.event.number }} |
| 9 | + cancel-in-progress: true |
| 10 | + |
| 11 | +permissions: {} |
| 12 | + |
| 13 | +jobs: |
| 14 | + lint: |
| 15 | + name: Decision model lint |
| 16 | + # Never pull_request_target, which would give a pull request's code the key. Forks get no |
| 17 | + # secrets, so skip them. Every label change re-runs the lint, because a skipped run would |
| 18 | + # replace the last result. |
| 19 | + if: github.event.pull_request.head.repo.full_name == github.repository |
| 20 | + runs-on: ubuntu-latest |
| 21 | + timeout-minutes: 15 |
| 22 | + permissions: |
| 23 | + contents: read |
| 24 | + pull-requests: write # to keep one comment with the findings |
| 25 | + steps: |
| 26 | + # The pull request's merge commit and its first parent: HEAD^1..HEAD is what it changes. |
| 27 | + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 28 | + with: |
| 29 | + fetch-depth: 2 |
| 30 | + persist-credentials: false |
| 31 | + |
| 32 | + - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 |
| 33 | + with: |
| 34 | + node-version: '24' |
| 35 | + |
| 36 | + - run: npm ci --prefix lint --ignore-scripts |
| 37 | + |
| 38 | + - name: Lint |
| 39 | + env: |
| 40 | + OPENROUTER_API_KEY: ${{ secrets.WARDEN_OPENROUTER_API_KEY }} |
| 41 | + GH_TOKEN: ${{ github.token }} |
| 42 | + PR: ${{ github.event.number }} |
| 43 | + LABEL: Override decision model lint |
| 44 | + OVERRIDDEN: "${{ contains(github.event.pull_request.labels.*.name, 'Override decision model lint') }}" |
| 45 | + run: | |
| 46 | + report="$RUNNER_TEMP/decision-model-lint.md" |
| 47 | + status=0 |
| 48 | + lint/node_modules/.bin/decision-model-linter --config lint/decision-model-linter.config.ts \ |
| 49 | + --base HEAD^1 --format markdown > "$report" || status=$? |
| 50 | +
|
| 51 | + # Only 1 means findings; any other failure means the linter did not finish. |
| 52 | + if [ "$status" -eq 1 ] && [ "$OVERRIDDEN" = true ]; then |
| 53 | + printf '\nThe `%s` label keeps these errors from failing the check.\n' "$LABEL" >> "$report" |
| 54 | + elif [ "$status" -eq 1 ]; then |
| 55 | + printf '\nThese errors fail the check; fix the code to resolve them. If you and a reviewer are confident an error is wrong, a person can add the `%s` label to pass the check while the findings stay reported. Agents should never add this label.\n' "$LABEL" >> "$report" |
| 56 | + elif [ "$status" -gt 1 ] && [ "$OVERRIDDEN" = true ]; then |
| 57 | + printf 'The linter did not finish (exit %s), and the `%s` label passes the check anyway; see the job log.\n' "$status" "$LABEL" >> "$report" |
| 58 | + fi |
| 59 | +
|
| 60 | + marker='<!-- decision-model-linter -->' |
| 61 | + comment=$(gh api "repos/$GITHUB_REPOSITORY/issues/$PR/comments" --paginate \ |
| 62 | + --jq ".[] | select(.user.login == \"github-actions[bot]\" and (.body | contains(\"$marker\"))) | .id" | head -n 1) |
| 63 | + body= |
| 64 | + if [ -s "$report" ] && { [ "$status" -le 1 ] || [ "$OVERRIDDEN" = true ]; }; then |
| 65 | + body=$(printf '%s\n%s' "$marker" "$(cat "$report")") |
| 66 | + elif [ "$status" -eq 0 ] && [ -n "$comment" ]; then |
| 67 | + body=$(printf '%s\nNo findings on the latest commit.' "$marker") |
| 68 | + fi |
| 69 | + if [ -n "$body" ] && [ -n "$comment" ]; then |
| 70 | + gh api -X PATCH "repos/$GITHUB_REPOSITORY/issues/comments/$comment" -f body="$body" > /dev/null |
| 71 | + elif [ -n "$body" ]; then |
| 72 | + gh api "repos/$GITHUB_REPOSITORY/issues/$PR/comments" -f body="$body" > /dev/null |
| 73 | + fi |
| 74 | + cat "$report" >> "$GITHUB_STEP_SUMMARY" |
| 75 | +
|
| 76 | + if [ "$status" -ne 0 ] && [ "$OVERRIDDEN" = true ]; then exit 0; fi |
| 77 | + exit "$status" |
0 commit comments