|
| 1 | +name: Claude Code Action |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + issue_comment: |
| 6 | + types: [created] |
| 7 | + |
| 8 | +permissions: |
| 9 | + id-token: write |
| 10 | + contents: write |
| 11 | + pull-requests: write |
| 12 | + issues: write |
| 13 | + |
| 14 | +jobs: |
| 15 | + check-membership: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + outputs: |
| 18 | + is-member: ${{ steps.check.outputs.is-member }} |
| 19 | + should-run: ${{ steps.check.outputs.should-run }} |
| 20 | + steps: |
| 21 | + - name: Generate GitHub App token |
| 22 | + id: app-token |
| 23 | + uses: actions/create-github-app-token@v2 |
| 24 | + with: |
| 25 | + app-id: ${{ vars.APP_ID }} |
| 26 | + private-key: ${{ secrets.APP_PRIVATE_KEY }} |
| 27 | + |
| 28 | + - name: Check if Claude is mentioned and user is org member |
| 29 | + id: check |
| 30 | + env: |
| 31 | + GH_TOKEN: ${{ steps.app-token.outputs.token }} |
| 32 | + run: | |
| 33 | + USER="${{ github.event.pull_request.user.login || github.event.comment.user.login }}" |
| 34 | + COMMENT_BODY="${{ github.event.comment.body }}" |
| 35 | + PR_TITLE="${{ github.event.pull_request.title }}" |
| 36 | + PR_BODY="${{ github.event.pull_request.body }}" |
| 37 | +
|
| 38 | + # Check if @claude is mentioned in PR title/body or comment |
| 39 | + if [[ "$COMMENT_BODY" == *"@claude"* ]] || [[ "$PR_TITLE" == *"@claude"* ]] || [[ "$PR_BODY" == *"@claude"* ]]; then |
| 40 | + echo "should-run=true" >> $GITHUB_OUTPUT |
| 41 | + else |
| 42 | + echo "should-run=false" >> $GITHUB_OUTPUT |
| 43 | + echo "Skipping: @claude not mentioned" |
| 44 | + exit 0 |
| 45 | + fi |
| 46 | +
|
| 47 | + # Check org membership. |
| 48 | + if gh api /orgs/sigp/members/$USER --silent 2>/dev/null; then |
| 49 | + echo "is-member=true" >> $GITHUB_OUTPUT |
| 50 | + else |
| 51 | + echo "is-member=false" >> $GITHUB_OUTPUT |
| 52 | + echo "⚠️ User $USER is not a member of sigp organization. Skipping Claude Code Action." |
| 53 | + fi |
| 54 | +
|
| 55 | + claude-code: |
| 56 | + runs-on: ubuntu-latest |
| 57 | + needs: check-membership |
| 58 | + if: needs.check-membership.outputs.is-member == 'true' && needs.check-membership.outputs.should-run == 'true' |
| 59 | + steps: |
| 60 | + - name: Configure AWS Credentials (OIDC) |
| 61 | + uses: aws-actions/configure-aws-credentials@v4 |
| 62 | + with: |
| 63 | + role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }} |
| 64 | + aws-region: us-west-2 |
| 65 | + |
| 66 | + - name: Generate GitHub App token |
| 67 | + id: app-token |
| 68 | + uses: actions/create-github-app-token@v2 |
| 69 | + with: |
| 70 | + app-id: ${{ vars.APP_ID }} |
| 71 | + private-key: ${{ secrets.APP_PRIVATE_KEY }} |
| 72 | + |
| 73 | + - uses: anthropics/claude-code-action@v1 |
| 74 | + with: |
| 75 | + use_bedrock: "true" |
| 76 | + claude_args: | |
| 77 | + --model anthropic.claude-sonnet-4-5-20250929-v1:0 |
| 78 | + env: |
| 79 | + GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} |
0 commit comments