|
| 1 | +name: Spec Linter Gate |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + paths: ['specs/**/*.tri'] |
| 6 | + push: |
| 7 | + paths: ['specs/**/*.tri'] |
| 8 | + branches: [main] |
| 9 | + |
| 10 | +jobs: |
| 11 | + lint-specs: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - uses: actions/checkout@v4 |
| 15 | + with: |
| 16 | + fetch-depth: 0 |
| 17 | + |
| 18 | + - name: Install Zig |
| 19 | + uses: goto-bus-stop/setup-zig@v2 |
| 20 | + with: |
| 21 | + version: 0.15.0 |
| 22 | + |
| 23 | + - name: Build vibee |
| 24 | + run: zig build vibee |
| 25 | + |
| 26 | + - name: Lint changed specs |
| 27 | + id: lint |
| 28 | + run: | |
| 29 | + if [ "${{ github.event_name }}" = "pull_request" ]; then |
| 30 | + CHANGED=$(git diff --name-only origin/${{ github.base_ref }}...HEAD -- 'specs/**/*.tri') |
| 31 | + else |
| 32 | + CHANGED=$(git diff --name-only HEAD~1 HEAD -- 'specs/**/*.tri') |
| 33 | + fi |
| 34 | +
|
| 35 | + if [ -z "$CHANGED" ]; then |
| 36 | + echo "No .tri files changed" |
| 37 | + echo "summary=No specs changed" >> $GITHUB_OUTPUT |
| 38 | + exit 0 |
| 39 | + fi |
| 40 | +
|
| 41 | + PASS=0; FAIL=0; WARN=0 |
| 42 | + DETAILS="" |
| 43 | +
|
| 44 | + for f in $CHANGED; do |
| 45 | + if [ ! -f "$f" ]; then continue; fi |
| 46 | + RESULT=$(./zig-out/bin/vibee validate "$f" 2>&1) |
| 47 | + RC=$? |
| 48 | + if [ $RC -ne 0 ]; then |
| 49 | + FAIL=$((FAIL+1)) |
| 50 | + DETAILS="${DETAILS}FAIL ${f}\n${RESULT}\n\n" |
| 51 | + elif echo "$RESULT" | grep -q "WARN"; then |
| 52 | + WARN=$((WARN+1)) |
| 53 | + else |
| 54 | + PASS=$((PASS+1)) |
| 55 | + fi |
| 56 | + done |
| 57 | +
|
| 58 | + echo "pass=$PASS" >> $GITHUB_OUTPUT |
| 59 | + echo "fail=$FAIL" >> $GITHUB_OUTPUT |
| 60 | + echo "warn=$WARN" >> $GITHUB_OUTPUT |
| 61 | + echo "summary=Pass:$PASS Warn:$WARN Fail:$FAIL" >> $GITHUB_OUTPUT |
| 62 | +
|
| 63 | + if [ $FAIL -gt 0 ]; then |
| 64 | + echo -e "$DETAILS" |
| 65 | + echo "Spec lint failed: $FAIL spec(s) have errors" |
| 66 | + exit 1 |
| 67 | + fi |
| 68 | +
|
| 69 | + - name: Comment PR |
| 70 | + if: github.event_name == 'pull_request' && always() |
| 71 | + uses: actions/github-script@v7 |
| 72 | + with: |
| 73 | + script: | |
| 74 | + const pass = '${{ steps.lint.outputs.pass }}' || '0'; |
| 75 | + const fail = '${{ steps.lint.outputs.fail }}' || '0'; |
| 76 | + const warn = '${{ steps.lint.outputs.warn }}' || '0'; |
| 77 | + const status = fail > 0 ? 'BLOCKED' : 'OPEN'; |
| 78 | + const emoji = fail > 0 ? '🔴' : '🟢'; |
| 79 | +
|
| 80 | + await github.rest.issues.createComment({ |
| 81 | + owner: context.repo.owner, |
| 82 | + repo: context.repo.repo, |
| 83 | + issue_number: context.issue.number, |
| 84 | + body: `### Spec Linter Gate ${emoji}\n\n| Result | Count |\n|--------|-------|\n| Pass | ${pass} |\n| Warn | ${warn} |\n| Fail | ${fail} |\n\n**Gate**: ${status}` |
| 85 | + }); |
0 commit comments