From 0bb958ff0b8cc491356183a6e29ddd4f1d1df722 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Thu, 7 Jul 2022 13:57:08 +0200 Subject: [PATCH] workflows: new method for signaling PR number of review comments Signed-off-by: Patrik Oldsberg --- .../workflows/pr-review-comment-trigger.yaml | 11 ++++++++- .github/workflows/pr-review-comment.yaml | 23 +++++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr-review-comment-trigger.yaml b/.github/workflows/pr-review-comment-trigger.yaml index 25475a03dc..67e4c5abba 100644 --- a/.github/workflows/pr-review-comment-trigger.yaml +++ b/.github/workflows/pr-review-comment-trigger.yaml @@ -16,4 +16,13 @@ jobs: if: github.repository == 'backstage/backstage' && github.event.comment.user.id == github.event.pull_request.user.id steps: - - run: echo "This PR needs another review" + - name: Save PR number + env: + PR_NUMBER: ${{ github.event.pull_request.number }} + run: | + mkdir -p ./pr + echo $PR_NUMBER > ./pr/pr_number + - uses: actions/upload-artifact@v3 + with: + name: pr_number-${{ github.event.pull_request.number }} + path: pr/ diff --git a/.github/workflows/pr-review-comment.yaml b/.github/workflows/pr-review-comment.yaml index b7a97abbe4..fac7fd2fc4 100644 --- a/.github/workflows/pr-review-comment.yaml +++ b/.github/workflows/pr-review-comment.yaml @@ -15,11 +15,30 @@ jobs: if: github.repository == 'backstage/backstage' && github.event.workflow_run.conclusion == 'success' steps: - - uses: hmarr/debug-action@v2 + # Inspired by https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#using-data-from-the-triggering-workflow + - name: Read PR Number + id: pr-number + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: context.payload.workflow_run.id, + }); + const [artifact] = allArtifacts.data.artifacts.filter(artifact => artifact.name.startsWith('pr_number-')) + if (!artifact) { + throw new Error('No PR Number artifact available') + } + + const prNumber = artifact.name.slice('pr_number-'.length) + console.log(`::set-output name=pr-number::${prNumber}`); + - uses: backstage/actions/re-review@v0.5.3 with: app-id: ${{ secrets.BACKSTAGE_GOALIE_APPLICATION_ID }} private-key: ${{ secrets.BACKSTAGE_GOALIE_PRIVATE_KEY }} installation-id: ${{ secrets.BACKSTAGE_GOALIE_INSTALLATION_ID }} project-id: PVT_kwDOBFKqdc02LQ - issue-number: ${{ github.event.workflow_run.pull_requests[0].number }} + issue-number: ${{ steps.pr-number.outputs.pr-number }}