@@ -124,12 +124,39 @@ jobs:
124124 inputs.pr-number != ''
125125 )
126126 runs-on : ubuntu-latest
127- env :
128- HAS_APP_SECRETS : ${{ secrets.CAGENT_REVIEWER_APP_ID != '' }}
127+ permissions :
128+ contents : read
129+ pull-requests : write
130+ issues : write
131+ id-token : write
129132 outputs :
130133 exit-code : ${{ steps.run-review.outputs.exit-code }}
131134
132135 steps :
136+ - name : Configure AWS credentials
137+ uses : aws-actions/configure-aws-credentials@v4
138+ with :
139+ role-to-assume : TODO_ROLE_ARN
140+ aws-region : us-east-1
141+
142+ - name : Fetch GitHub App credentials from Secrets Manager
143+ id : app-credentials
144+ shell : bash
145+ run : |
146+ SECRET=$(aws secretsmanager get-secret-value \
147+ --secret-id docker-agent-action/github-app \
148+ --query SecretString --output text)
149+ APP_ID=$(echo "$SECRET" | jq -r .app_id)
150+ ORG_TOKEN=$(echo "$SECRET" | jq -r .org_membership_token)
151+ PRIVATE_KEY=$(echo "$SECRET" | jq -r .private_key)
152+ echo "::add-mask::$APP_ID"
153+ echo "::add-mask::$ORG_TOKEN"
154+ echo "::add-mask::$PRIVATE_KEY"
155+ echo "app-id=$APP_ID" >> $GITHUB_OUTPUT
156+ echo "org-membership-token=$ORG_TOKEN" >> $GITHUB_OUTPUT
157+ DELIM="$(openssl rand -hex 8)"
158+ { echo "private-key<<$DELIM"; echo "$PRIVATE_KEY"; echo "$DELIM"; } >> $GITHUB_OUTPUT
159+
133160 - name : Get PR number
134161 id : get-pr
135162 shell : bash
@@ -167,7 +194,7 @@ jobs:
167194 PR_DRAFT : ${{ steps.pr-info.outputs.draft }}
168195 PR_AUTHOR : ${{ steps.pr-info.outputs.author }}
169196 with :
170- github-token : ${{ secrets.CAGENT_ORG_MEMBERSHIP_TOKEN }}
197+ github-token : ${{ steps.app-credentials.outputs.org-membership-token }}
171198 script : |
172199 const org = '${{ inputs.auto-review-org }}';
173200
@@ -216,13 +243,13 @@ jobs:
216243
217244 # Generate GitHub App token for custom app identity (optional - falls back to github.token)
218245 - name : Generate GitHub App token
219- if : steps.membership.outputs.is_member == 'true' && env.HAS_APP_SECRETS == 'true'
246+ if : steps.membership.outputs.is_member == 'true'
220247 id : app-token
221248 continue-on-error : true # Don't fail workflow if token generation fails
222249 uses : tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a # v2
223250 with :
224- app_id : ${{ secrets.CAGENT_REVIEWER_APP_ID }}
225- private_key : ${{ secrets.CAGENT_REVIEWER_APP_PRIVATE_KEY }}
251+ app_id : ${{ steps.app-credentials.outputs.app-id }}
252+ private_key : ${{ steps.app-credentials.outputs.private-key }}
226253
227254 - name : Run PR Review
228255 if : steps.membership.outputs.is_member == 'true'
@@ -254,17 +281,44 @@ jobs:
254281 startsWith(github.event.comment.body, '/review') &&
255282 (github.event.comment.user.type != 'Bot' || github.event.comment.user.login == 'docker-agent[bot]')
256283 runs-on : ubuntu-latest
257- env :
258- HAS_APP_SECRETS : ${{ secrets.CAGENT_REVIEWER_APP_ID != '' }}
284+ permissions :
285+ contents : read
286+ pull-requests : write
287+ issues : write
288+ id-token : write
259289 outputs :
260290 exit-code : ${{ steps.run-review.outputs.exit-code }}
261291
262292 steps :
293+ - name : Configure AWS credentials
294+ uses : aws-actions/configure-aws-credentials@v4
295+ with :
296+ role-to-assume : TODO_ROLE_ARN
297+ aws-region : us-east-1
298+
299+ - name : Fetch GitHub App credentials from Secrets Manager
300+ id : app-credentials
301+ shell : bash
302+ run : |
303+ SECRET=$(aws secretsmanager get-secret-value \
304+ --secret-id docker-agent-action/github-app \
305+ --query SecretString --output text)
306+ APP_ID=$(echo "$SECRET" | jq -r .app_id)
307+ ORG_TOKEN=$(echo "$SECRET" | jq -r .org_membership_token)
308+ PRIVATE_KEY=$(echo "$SECRET" | jq -r .private_key)
309+ echo "::add-mask::$APP_ID"
310+ echo "::add-mask::$ORG_TOKEN"
311+ echo "::add-mask::$PRIVATE_KEY"
312+ echo "app-id=$APP_ID" >> $GITHUB_OUTPUT
313+ echo "org-membership-token=$ORG_TOKEN" >> $GITHUB_OUTPUT
314+ DELIM="$(openssl rand -hex 8)"
315+ { echo "private-key<<$DELIM"; echo "$PRIVATE_KEY"; echo "$DELIM"; } >> $GITHUB_OUTPUT
316+
263317 - name : Check if commenter is org member
264318 id : membership
265319 uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
266320 with :
267- github-token : ${{ secrets.CAGENT_ORG_MEMBERSHIP_TOKEN }}
321+ github-token : ${{ steps.app-credentials.outputs.org-membership-token }}
268322 script : |
269323 const org = '${{ inputs.auto-review-org }}';
270324 const username = context.payload.comment.user.login;
@@ -303,13 +357,13 @@ jobs:
303357 # Generate GitHub App token first so the check run is created under the app's identity
304358 # (prevents GitHub from nesting it under unrelated pull_request-triggered workflows)
305359 - name : Generate GitHub App token
306- if : steps.membership.outputs.is_member == 'true' && env.HAS_APP_SECRETS == 'true'
360+ if : steps.membership.outputs.is_member == 'true'
307361 id : app-token
308362 continue-on-error : true # Don't fail workflow if token generation fails
309363 uses : tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a # v2
310364 with :
311- app_id : ${{ secrets.CAGENT_REVIEWER_APP_ID }}
312- private_key : ${{ secrets.CAGENT_REVIEWER_APP_PRIVATE_KEY }}
365+ app_id : ${{ steps.app-credentials.outputs.app-id }}
366+ private_key : ${{ steps.app-credentials.outputs.private-key }}
313367
314368 - name : Create check run
315369 if : steps.membership.outputs.is_member == 'true'
@@ -358,7 +412,7 @@ jobs:
358412 add-prompt-files : ${{ inputs.add-prompt-files }}
359413 model : ${{ inputs.model }}
360414 github-token : ${{ steps.app-token.outputs.token || github.token }}
361- trusted-bot-app-id : ${{ secrets.CAGENT_REVIEWER_APP_ID }}
415+ trusted-bot-app-id : ${{ steps.app-credentials.outputs.app-id }}
362416 anthropic-api-key : ${{ secrets.ANTHROPIC_API_KEY }}
363417 openai-api-key : ${{ secrets.OPENAI_API_KEY }}
364418 google-api-key : ${{ secrets.GOOGLE_API_KEY }}
@@ -455,10 +509,37 @@ jobs:
455509 github.event.comment.in_reply_to_id &&
456510 github.event.comment.user.type != 'Bot'
457511 runs-on : ubuntu-latest
458- env :
459- HAS_APP_SECRETS : ${{ secrets.CAGENT_REVIEWER_APP_ID != '' }}
512+ permissions :
513+ contents : read
514+ pull-requests : write
515+ issues : write
516+ id-token : write
460517
461518 steps :
519+ - name : Configure AWS credentials
520+ uses : aws-actions/configure-aws-credentials@v4
521+ with :
522+ role-to-assume : TODO_ROLE_ARN
523+ aws-region : us-east-1
524+
525+ - name : Fetch GitHub App credentials from Secrets Manager
526+ id : app-credentials
527+ shell : bash
528+ run : |
529+ SECRET=$(aws secretsmanager get-secret-value \
530+ --secret-id docker-agent-action/github-app \
531+ --query SecretString --output text)
532+ APP_ID=$(echo "$SECRET" | jq -r .app_id)
533+ ORG_TOKEN=$(echo "$SECRET" | jq -r .org_membership_token)
534+ PRIVATE_KEY=$(echo "$SECRET" | jq -r .private_key)
535+ echo "::add-mask::$APP_ID"
536+ echo "::add-mask::$ORG_TOKEN"
537+ echo "::add-mask::$PRIVATE_KEY"
538+ echo "app-id=$APP_ID" >> $GITHUB_OUTPUT
539+ echo "org-membership-token=$ORG_TOKEN" >> $GITHUB_OUTPUT
540+ DELIM="$(openssl rand -hex 8)"
541+ { echo "private-key<<$DELIM"; echo "$PRIVATE_KEY"; echo "$DELIM"; } >> $GITHUB_OUTPUT
542+
462543 - name : Check if reply is to agent comment
463544 id : check
464545 shell : bash
@@ -526,7 +607,7 @@ jobs:
526607 id : auth
527608 shell : bash
528609 env :
529- GH_TOKEN : ${{ secrets.CAGENT_ORG_MEMBERSHIP_TOKEN }}
610+ GH_TOKEN : ${{ steps.app-credentials.outputs.org-membership-token }}
530611 ORG : ${{ inputs.auto-review-org }}
531612 USERNAME : ${{ github.event.comment.user.login }}
532613 run : |
@@ -682,13 +763,13 @@ jobs:
682763
683764 # Generate GitHub App token for custom app identity (optional - falls back to github.token)
684765 - name : Generate GitHub App token
685- if : steps.check.outputs.is_agent == 'true' && steps.auth.outputs.authorized == 'true' && env.HAS_APP_SECRETS == 'true'
766+ if : steps.check.outputs.is_agent == 'true' && steps.auth.outputs.authorized == 'true'
686767 id : app-token
687768 continue-on-error : true
688769 uses : tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a # v2
689770 with :
690- app_id : ${{ secrets.CAGENT_REVIEWER_APP_ID }}
691- private_key : ${{ secrets.CAGENT_REVIEWER_APP_PRIVATE_KEY }}
771+ app_id : ${{ steps.app-credentials.outputs.app-id }}
772+ private_key : ${{ steps.app-credentials.outputs.private-key }}
692773
693774 - name : Run reply
694775 if : steps.check.outputs.is_agent == 'true' && steps.auth.outputs.authorized == 'true'
0 commit comments