From 5f19ae1ddb766f79222fb70f6ba8a3cfab1d7b23 Mon Sep 17 00:00:00 2001 From: Lucille Delisle Date: Thu, 11 Jan 2024 17:16:58 +0100 Subject: [PATCH] try to comment on PR from forks --- .github/workflows/comment_on_pr.yml | 52 +++++++++++++++++++++++++++++ .github/workflows/workflow_test.yml | 22 +++--------- 2 files changed, 57 insertions(+), 17 deletions(-) create mode 100644 .github/workflows/comment_on_pr.yml diff --git a/.github/workflows/comment_on_pr.yml b/.github/workflows/comment_on_pr.yml new file mode 100644 index 000000000..bf96541a3 --- /dev/null +++ b/.github/workflows/comment_on_pr.yml @@ -0,0 +1,52 @@ +name: Comment on the pull request + +# read-write repo token +# access to secrets +on: + workflow_run: + workflows: ["Galaxy Workflow Tests for push and PR"] + types: + - completed + +jobs: + upload: + runs-on: ubuntu-latest + if: github.event.workflow_run.event == 'pull_request' + steps: + - name: 'Download artifact' + uses: actions/github-script@v3.1.0 + with: + script: | + var artifacts = await github.actions.listWorkflowRunArtifacts({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: ${{github.event.workflow_run.id }}, + }); + var matchArtifact = artifacts.data.artifacts.filter((artifact) => { + return artifact.name == 'All tool test results' + })[0]; + var download = await github.actions.downloadArtifact({ + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: matchArtifact.id, + archive_format: 'zip', + }); + var fs = require('fs'); + fs.writeFileSync('${{github.workspace}}/upload.zip', Buffer.from(download.data)); + - run: unzip upload.zip + - name: Check the output of unzip + run: | + ls + - name: 'Comment on PR' + uses: actions/github-script@v3 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + var fs = require('fs'); + var issue_number = Number(fs.readFileSync('./NR')); + await github.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issue_number, + body: fs.readFileSync('./tool_test_output.md') + }); diff --git a/.github/workflows/workflow_test.yml b/.github/workflows/workflow_test.yml index a6292d7f8..3c96095bc 100644 --- a/.github/workflows/workflow_test.yml +++ b/.github/workflows/workflow_test.yml @@ -89,6 +89,11 @@ jobs: html-report: true markdown-report: true - run: cat upload/tool_test_output.md >> $GITHUB_STEP_SUMMARY + - name: Save PR number + run: echo ${{ github.event.number }} > ./upload/NR + - name: Debug PR number + run: | + cat ./upload/NR - uses: actions/upload-artifact@v3 with: name: 'All tool test results' @@ -98,23 +103,6 @@ jobs: id: check with: mode: check - - name: Get PR object - if: failure() - uses: 8BitJonny/gh-get-current-pr@2.2.0 - id: failed_pr_number - with: - sha: ${{ github.event.pull_request.head.sha }} - - name: Debug GetPR output - if: failure() - run: | - echo ${{ steps.failed_pr_number.outputs.number }} - - name: Post comment with test report - if: failure() - uses: peter-evans/create-or-update-comment@v3 - with: - token: ${{ secrets.PAT }} - issue-number: ${{ steps.failed_pr_number.outputs.number }} - body-path: upload/tool_test_output.md # deploy workflows to organization deploy: