diff --git a/.github/scripts/label_related_issue.js b/.github/scripts/label_related_issue.js index 9d61e86..7c5b794 100644 --- a/.github/scripts/label_related_issue.js +++ b/.github/scripts/label_related_issue.js @@ -1,8 +1,13 @@ module.exports = async ({github, context, core}) => { + const fs = require('fs'); + const pr_number = Number(fs.readFileSync('./number')); + const pr_event = JSON.parse(fs.readFileSync('./event')) + + core.info(`Is it a PR Merge: ${pr_event.pull_request.merged}`) core.info("Payload as it comes..") - core.info(JSON.stringify(context.payload)); - const prBody = context.payload.body; - const prNumber = context.payload.number; + core.info(JSON.stringify(pr_event)); + const prBody =pr_event.body; + const prNumber = pr_number; const releaseLabel = process.env.RELEASE_LABEL; const maintainersTeam = process.env.MAINTAINERS_TEAM diff --git a/.github/workflows/on_pr.yml b/.github/workflows/on_pr.yml index 4e4f65a..f95ab82 100644 --- a/.github/workflows/on_pr.yml +++ b/.github/workflows/on_pr.yml @@ -18,6 +18,7 @@ jobs: echo "${{ github.event.pull_request.body }}" > ./pr/body echo "${{ github.event.pull_request.user.login }}" > ./pr/author echo "${{ github.event.action }}" > ./pr/action + echo "${{ github.event }}" > ./pr/event - uses: actions/upload-artifact@v3 with: name: pr diff --git a/.github/workflows/on_pr_merge.yml b/.github/workflows/on_pr_merge.yml index dc7fc61..e7bd191 100644 --- a/.github/workflows/on_pr_merge.yml +++ b/.github/workflows/on_pr_merge.yml @@ -20,6 +20,31 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + - name: "Download artifact" + uses: actions/github-script@v6 + # For security, we only download artifacts tied to the successful PR recording workflow + with: + script: | + const fs = require('fs'); + + const artifacts = await github.rest.actions.listWorkflowRunArtifacts({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: ${{github.event.workflow_run.id }}, + }); + + const matchArtifact = artifacts.data.artifacts.filter(artifact => artifact.name == "pr")[0]; + + const artifact = await github.rest.actions.downloadArtifact({ + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: matchArtifact.id, + archive_format: 'zip', + }); + + fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(artifact.data)); + # NodeJS standard library doesn't provide ZIP capabilities; use system `unzip` command instead + - run: unzip pr.zip - name: "Label PR related issue for release" uses: actions/github-script@v6 with: diff --git a/README.md b/README.md index 83b2a16..0b669b6 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,5 @@ 6 7 8 -9 \ No newline at end of file +9 +10 \ No newline at end of file