From 7c733b064d79e85811f7bdadf5bf83ccd1bd97ae Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 25 Feb 2022 20:48:09 +0800 Subject: [PATCH 1/3] [add] Receive PR workflow --- .github/workflows/pr-receive.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .github/workflows/pr-receive.yml diff --git a/.github/workflows/pr-receive.yml b/.github/workflows/pr-receive.yml new file mode 100644 index 00000000..302e3d0e --- /dev/null +++ b/.github/workflows/pr-receive.yml @@ -0,0 +1,25 @@ +name: Receive PR + +# read-only repo token +# no access to secrets +on: + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Build + run: /bin/bash ./build.sh + + - name: Save PR number + run: | + mkdir -p ./pr + echo ${{ github.event.number }} > ./pr/NR + - uses: actions/upload-artifact@v2 + with: + name: pr + path: pr/ From 61af3a538908fe7d5b501a61b2caef562081c8eb Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 25 Feb 2022 20:56:24 +0800 Subject: [PATCH 2/3] Fix Receive PR workflow & rm unit-test pr trigger --- .github/workflows/pr-receive.yml | 3 --- .github/workflows/unit-test.yml | 2 -- 2 files changed, 5 deletions(-) diff --git a/.github/workflows/pr-receive.yml b/.github/workflows/pr-receive.yml index 302e3d0e..c8be38ea 100644 --- a/.github/workflows/pr-receive.yml +++ b/.github/workflows/pr-receive.yml @@ -12,9 +12,6 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Build - run: /bin/bash ./build.sh - - name: Save PR number run: | mkdir -p ./pr diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 2b5f03c1..e7987d1c 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -3,8 +3,6 @@ name: UnitTest on: push: branches: [main] - pull_request: - branches: [main] env: YAO_DEV: ${{ github.WORKSPACE }} From a49e4edcc1832eaf949e6ead81ce6e73f19ec08f Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 25 Feb 2022 21:08:34 +0800 Subject: [PATCH 3/3] [add] pr-test workflow --- .github/workflows/pr-test.yml | 55 +++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 .github/workflows/pr-test.yml diff --git a/.github/workflows/pr-test.yml b/.github/workflows/pr-test.yml new file mode 100644 index 00000000..e9eb0472 --- /dev/null +++ b/.github/workflows/pr-test.yml @@ -0,0 +1,55 @@ +name: Comment on the pull request + +# read-write repo token +# access to secrets +on: + workflow_run: + workflows: ["Receive PR"] + 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)); + - name: "Unzip" + run: | + unzip pr.zip + ls -l + + - 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: 'Everything is OK. Thank you for the PR!' + });