|
| 1 | +name: Vault Audit Commands |
| 2 | + |
| 3 | +# Handles /vault-audit and /vault-audit skip <reason> comments from authorized reviewers. |
| 4 | +# Authorization: commenter must have write or admin permission on this repository |
| 5 | +# (which is the requirement for being listed in CODEOWNERS). |
| 6 | + |
| 7 | +on: |
| 8 | + issue_comment: |
| 9 | + types: [created] |
| 10 | + |
| 11 | +jobs: |
| 12 | + handle-command: |
| 13 | + # Only run on PR comments containing a vault-audit command |
| 14 | + if: | |
| 15 | + github.event.issue.pull_request != null && |
| 16 | + ( |
| 17 | + startsWith(github.event.comment.body, '/vault-audit skip ') || |
| 18 | + github.event.comment.body == '/vault-audit' || |
| 19 | + startsWith(github.event.comment.body, '/vault-audit ') |
| 20 | + ) |
| 21 | + runs-on: ubuntu-latest |
| 22 | + permissions: |
| 23 | + issues: write |
| 24 | + pull-requests: write |
| 25 | + statuses: write |
| 26 | + |
| 27 | + steps: |
| 28 | + - name: Check commenter authorization |
| 29 | + id: auth |
| 30 | + env: |
| 31 | + GH_TOKEN: ${{ github.token }} |
| 32 | + run: | |
| 33 | + PERMISSION=$(gh api /repos/${{ github.repository }}/collaborators/${{ github.event.comment.user.login }}/permission \ |
| 34 | + --jq '.permission' 2>/dev/null || echo "none") |
| 35 | +
|
| 36 | + if [[ "$PERMISSION" == "write" || "$PERMISSION" == "admin" ]]; then |
| 37 | + echo "authorized=true" >> $GITHUB_OUTPUT |
| 38 | + else |
| 39 | + echo "authorized=false" >> $GITHUB_OUTPUT |
| 40 | + fi |
| 41 | +
|
| 42 | + - name: Reject unauthorized commenter |
| 43 | + if: steps.auth.outputs.authorized == 'false' |
| 44 | + env: |
| 45 | + GH_TOKEN: ${{ github.token }} |
| 46 | + run: | |
| 47 | + gh pr comment ${{ github.event.issue.number }} \ |
| 48 | + --body "⛔ @${{ github.event.comment.user.login }} — only authorized reviewers (repository write access) can trigger the vault audit." |
| 49 | + exit 1 |
| 50 | +
|
| 51 | + - name: Get PR details |
| 52 | + id: pr |
| 53 | + env: |
| 54 | + GH_TOKEN: ${{ github.token }} |
| 55 | + run: | |
| 56 | + PR=$(gh api /repos/${{ github.repository }}/pulls/${{ github.event.issue.number }} \ |
| 57 | + --jq '{head_sha: .head.sha, base_sha: .base.sha}') |
| 58 | + echo "head_sha=$(echo "$PR" | jq -r '.head_sha')" >> $GITHUB_OUTPUT |
| 59 | + echo "base_sha=$(echo "$PR" | jq -r '.base_sha')" >> $GITHUB_OUTPUT |
| 60 | +
|
| 61 | + - name: Parse command |
| 62 | + id: cmd |
| 63 | + run: | |
| 64 | + BODY="${{ github.event.comment.body }}" |
| 65 | + if echo "$BODY" | grep -qP '^/vault-audit skip .+'; then |
| 66 | + echo "type=skip" >> $GITHUB_OUTPUT |
| 67 | + REASON=$(echo "$BODY" | sed 's|^/vault-audit skip ||') |
| 68 | + echo "reason=$REASON" >> $GITHUB_OUTPUT |
| 69 | + else |
| 70 | + echo "type=run" >> $GITHUB_OUTPUT |
| 71 | + fi |
| 72 | +
|
| 73 | + # ── /vault-audit skip <reason> ──────────────────────────────────────────── |
| 74 | + - name: Handle skip |
| 75 | + if: steps.cmd.outputs.type == 'skip' |
| 76 | + env: |
| 77 | + GH_TOKEN: ${{ github.token }} |
| 78 | + run: | |
| 79 | + REASON="${{ steps.cmd.outputs.reason }}" |
| 80 | + SHA="${{ steps.pr.outputs.head_sha }}" |
| 81 | +
|
| 82 | + gh api /repos/${{ github.repository }}/statuses/$SHA \ |
| 83 | + --method POST \ |
| 84 | + -f state=success \ |
| 85 | + -f context="vault-audit" \ |
| 86 | + -f description="Vault audit skipped by ${{ github.event.comment.user.login }}: $REASON" |
| 87 | +
|
| 88 | + gh pr comment ${{ github.event.issue.number }} \ |
| 89 | + --body "✅ Vault audit skipped by @${{ github.event.comment.user.login }} |
| 90 | +
|
| 91 | + **Reason:** $REASON |
| 92 | +
|
| 93 | + > ⚠️ This skip applies to the current HEAD (\`${SHA:0:8}\`). Pushing new vault file changes will re-require an audit." |
| 94 | +
|
| 95 | + # ── /vault-audit ───────────────────────────────────────────────────────── |
| 96 | + - name: Acknowledge audit request |
| 97 | + if: steps.cmd.outputs.type == 'run' |
| 98 | + env: |
| 99 | + GH_TOKEN: ${{ github.token }} |
| 100 | + run: | |
| 101 | + gh pr comment ${{ github.event.issue.number }} \ |
| 102 | + --body "🔍 Vault audit triggered by @${{ github.event.comment.user.login }} — running now. Results will appear as a new comment when complete." |
| 103 | +
|
| 104 | + - name: Trigger vault audit |
| 105 | + if: steps.cmd.outputs.type == 'run' |
| 106 | + uses: smartcontractkit/cre-docs/.github/workflows/vault-audit.yml@main |
| 107 | + with: |
| 108 | + pr_number: ${{ github.event.issue.number }} |
| 109 | + head_sha: ${{ steps.pr.outputs.head_sha }} |
| 110 | + base_sha: ${{ steps.pr.outputs.base_sha }} |
| 111 | + chainlink_repo: ${{ github.repository }} |
| 112 | + secrets: |
| 113 | + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} |
| 114 | + CRE_DOCS_TOKEN: ${{ secrets.CRE_DOCS_TOKEN }} |
| 115 | + CHAINLINK_TOKEN: ${{ github.token }} |
0 commit comments