From cbecfa3e84f32582a54d8ddf3745666c14388093 Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Sun, 22 Nov 2026 16:06:15 +0000 Subject: [PATCH] fix(ci): use source-scoped App token for submodule PR feedback The source workflow has an Issues:write GITHUB_TOKEN but GitHub returns HTTP 403 when posting the linked-PR acknowledgment. Keep signed target verification mandatory and make the feedback best-effort using a short-lived source-repository GitHub App token, without broadening destination access. Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- .../nextcloud/command-submodule-pr.yml.patch | 35 ++++++++++++++++--- tests/test_submodule_workflows.py | 5 +++ workflow-templates/command-submodule-pr.yml | 33 +++++++++++++++-- 3 files changed, 66 insertions(+), 7 deletions(-) diff --git a/patches/nextcloud/command-submodule-pr.yml.patch b/patches/nextcloud/command-submodule-pr.yml.patch index 114f3eb..58984fe 100644 --- a/patches/nextcloud/command-submodule-pr.yml.patch +++ b/patches/nextcloud/command-submodule-pr.yml.patch @@ -104,7 +104,7 @@ persist-credentials: false fetch-depth: 0 ref: ${{ needs.init.outputs.head_sha }} -@@ -99,63 +133,126 @@ +@@ -99,63 +133,153 @@ coverage: none - name: Generate composer diff @@ -244,10 +244,9 @@ + signoff: true + sign-commits: true + -+ - name: Verify signed destination and report source ++ - name: Verify signed destination + shell: bash + env: -+ GH_TOKEN: ${{ github.token }} + TARGET_URL: ${{ steps.target-pr.outputs.pull-request-url }} + VERIFIED: ${{ steps.target-pr.outputs.pull-request-commits-verified }} + run: | @@ -256,8 +255,36 @@ + echo "::error::Destination pull request commits were not verified" + exit 1 + } -+ [[ -n "$TARGET_URL" ]] || exit 1 ++ [[ -n "$TARGET_URL" ]] || { ++ echo "::error::Signed destination pull request URL is missing" ++ exit 1 ++ } ++ ++ - name: Create scoped source feedback token ++ id: source-feedback-token ++ continue-on-error: true ++ uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0 ++ with: ++ client-id: ${{ vars.WORKFLOW_SYNC_APP_CLIENT_ID }} ++ private-key: ${{ secrets.WORKFLOW_SYNC_APP_PRIVATE_KEY }} ++ owner: ${{ github.repository_owner }} ++ repositories: ${{ github.event.repository.name }} ++ permission-issues: write ++ ++ - name: Report linked PR on source ++ if: steps.source-feedback-token.outputs.token != '' ++ continue-on-error: true ++ shell: bash ++ env: ++ GH_TOKEN: ${{ steps.source-feedback-token.outputs.token }} ++ TARGET_URL: ${{ steps.target-pr.outputs.pull-request-url }} ++ run: | ++ set -euo pipefail + gh api --method POST "repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/comments" -f body="- Parent PR: $TARGET_URL" ++ ++ - name: Warn if source feedback is unavailable ++ if: steps.source-feedback-token.outputs.token == '' ++ run: echo "::warning::Source feedback token unavailable; the verified destination pull request was created." - name: Add reaction on failure uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0 diff --git a/tests/test_submodule_workflows.py b/tests/test_submodule_workflows.py index fa8d266..1464766 100644 --- a/tests/test_submodule_workflows.py +++ b/tests/test_submodule_workflows.py @@ -70,6 +70,11 @@ def test_commands_use_scoped_temporary_tokens(self) -> None: source = (ROOT / "workflow-templates/command-submodule-pr.yml").read_text() self.assertNotIn("COMMAND_BOT_PAT", source) self.assertIn("issues: write", source) + self.assertIn("id: source-feedback-token", source) + self.assertIn("permission-issues: write", source) + self.assertIn("GH_TOKEN: " + "$" + "{{ steps.source-feedback-token.outputs.token }}", source) + self.assertLess(source.index("- name: Verify signed destination"), + source.index("- name: Create scoped source feedback token")) self.assertIn('gh api --method POST "repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/comments"', source) self.assertNotIn("gh pr comment", source) self.assertIn("token: " + "$" + "{{ github.token }}", source) diff --git a/workflow-templates/command-submodule-pr.yml b/workflow-templates/command-submodule-pr.yml index 0978c36..2d726f6 100644 --- a/workflow-templates/command-submodule-pr.yml +++ b/workflow-templates/command-submodule-pr.yml @@ -233,10 +233,9 @@ jobs: signoff: true sign-commits: true - - name: Verify signed destination and report source + - name: Verify signed destination shell: bash env: - GH_TOKEN: ${{ github.token }} TARGET_URL: ${{ steps.target-pr.outputs.pull-request-url }} VERIFIED: ${{ steps.target-pr.outputs.pull-request-commits-verified }} run: | @@ -245,9 +244,37 @@ jobs: echo "::error::Destination pull request commits were not verified" exit 1 } - [[ -n "$TARGET_URL" ]] || exit 1 + [[ -n "$TARGET_URL" ]] || { + echo "::error::Signed destination pull request URL is missing" + exit 1 + } + + - name: Create scoped source feedback token + id: source-feedback-token + continue-on-error: true + uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0 + with: + client-id: ${{ vars.WORKFLOW_SYNC_APP_CLIENT_ID }} + private-key: ${{ secrets.WORKFLOW_SYNC_APP_PRIVATE_KEY }} + owner: ${{ github.repository_owner }} + repositories: ${{ github.event.repository.name }} + permission-issues: write + + - name: Report linked PR on source + if: steps.source-feedback-token.outputs.token != '' + continue-on-error: true + shell: bash + env: + GH_TOKEN: ${{ steps.source-feedback-token.outputs.token }} + TARGET_URL: ${{ steps.target-pr.outputs.pull-request-url }} + run: | + set -euo pipefail gh api --method POST "repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/comments" -f body="- Parent PR: $TARGET_URL" + - name: Warn if source feedback is unavailable + if: steps.source-feedback-token.outputs.token == '' + run: echo "::warning::Source feedback token unavailable; the verified destination pull request was created." + - name: Add reaction on failure uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0 if: failure()