From 1c79d5be304692d61844b02591ed300455a78c83 Mon Sep 17 00:00:00 2001 From: smrpn Date: Thu, 22 Apr 2021 02:24:21 +0530 Subject: [PATCH] ci: add workflow for pr comment Signed-off-by: smrpn --- .github/workflows/commentPR.yml | 56 ++++++++++++++++++++++++++++++ .github/workflows/pull_request.yml | 10 ++++++ 2 files changed, 66 insertions(+) create mode 100644 .github/workflows/commentPR.yml diff --git a/.github/workflows/commentPR.yml b/.github/workflows/commentPR.yml new file mode 100644 index 00000000..48bfc532 --- /dev/null +++ b/.github/workflows/commentPR.yml @@ -0,0 +1,56 @@ +name: Comment on the pull request + +# read-write repo token +# access to secrets +on: + workflow_run: + workflows: ["Benchmarks"] + types: + - completed + +jobs: + upload: + runs-on: ubuntu-latest + if: > + ${{ github.event.workflow_run.event == 'pull_request' && + github.event.workflow_run.conclusion == 'success' }} + 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 == "pr" + })[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}}/pr.zip', Buffer.from(download.data)); + - run: unzip pr.zip + + - name: 'Comment on PR' + uses: actions/github-script@v3 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + var file = "benchResults.txt" + if (file) { + 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('./benchResults.txt')).toString('utf8') + }); + } + diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 3544369a..fe69158d 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -23,4 +23,14 @@ jobs: with: cwd: benches token: ${{ secrets.GITHUB_TOKEN }} + + + - name: Save PR number + run: | + mkdir -p ./pr + echo ${{ github.event.number }} > ./pr/NR + - uses: actions/upload-artifact@v2 + with: + name: pr + path: pr/