|
| 1 | +on: |
| 2 | + workflow_call: |
| 3 | + inputs: |
| 4 | + record_pr_workflow_id: |
| 5 | + required: true |
| 6 | + type: number |
| 7 | + secrets: |
| 8 | + token: |
| 9 | + required: true |
| 10 | + # Map the workflow outputs to job outputs |
| 11 | + outputs: |
| 12 | + prNumber: |
| 13 | + description: "The first output string" |
| 14 | + value: ${{ jobs.export_pr_details.outputs.prNumber }} |
| 15 | + prTitle: |
| 16 | + description: "The second output string" |
| 17 | + value: ${{ jobs.export_pr_details.outputs.prTitle }} |
| 18 | + prBody: |
| 19 | + description: "The second output string" |
| 20 | + value: ${{ jobs.export_pr_details.outputs.prBody }} |
| 21 | + prAuthor: |
| 22 | + description: "The second output string" |
| 23 | + value: ${{ jobs.export_pr_details.outputs.prAuthor }} |
| 24 | + prAction: |
| 25 | + description: "The second output string" |
| 26 | + value: ${{ jobs.export_pr_details.outputs.prAction }} |
| 27 | + |
| 28 | +name: Export Pull Request details from fork |
| 29 | +jobs: |
| 30 | + export_pr_details: |
| 31 | + runs-on: ubuntu-latest |
| 32 | + # Map the job outputs to step outputs |
| 33 | + outputs: |
| 34 | + prNumber: ${{ steps.prNumber.outputs.prNumber }} |
| 35 | + prTitle: ${{ steps.prTitle.outputs.prTitle }} |
| 36 | + prBody: ${{ steps.prBody.outputs.prBody }} |
| 37 | + prAuthor: ${{ steps.prAuthor.outputs.prAuthor }} |
| 38 | + prAction: ${{ steps.prAction.outputs.prAction }} |
| 39 | + steps: |
| 40 | + - name: "Download artifact" |
| 41 | + uses: actions/github-script@v6 |
| 42 | + # For security, we only download artifacts tied to the successful PR recording workflow |
| 43 | + with: |
| 44 | + github-token: ${{ inputs.token }} |
| 45 | + script: | |
| 46 | + const fs = require('fs'); |
| 47 | +
|
| 48 | + const artifacts = await github.rest.actions.listWorkflowRunArtifacts({ |
| 49 | + owner: context.repo.owner, |
| 50 | + repo: context.repo.repo, |
| 51 | + run_id: ${{inputs.record_pr_workflow_id}}, |
| 52 | + }); |
| 53 | +
|
| 54 | + const matchArtifact = artifacts.data.artifacts.filter(artifact => artifact.name == "pr")[0]; |
| 55 | +
|
| 56 | + const artifact = await github.rest.actions.downloadArtifact({ |
| 57 | + owner: context.repo.owner, |
| 58 | + repo: context.repo.repo, |
| 59 | + artifact_id: matchArtifact.id, |
| 60 | + archive_format: 'zip', |
| 61 | + }); |
| 62 | +
|
| 63 | + fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(artifact.data)); |
| 64 | + # NodeJS standard library doesn't provide ZIP capabilities; use system `unzip` command instead |
| 65 | + - run: unzip pr.zip |
| 66 | + - id: prNumber |
| 67 | + run: echo ::set-output name=prNumber::$(cat ./number) |
| 68 | + - id: prTitle |
| 69 | + run: echo ::set-output name=prTitle::$(cat ./title) |
| 70 | + - id: prBody |
| 71 | + run: echo ::set-output name=prBody::$(cat ./body) |
| 72 | + - id: prAuthor |
| 73 | + run: echo ::set-output name=prAuthor::$(cat ./author) |
| 74 | + - id: prAction |
| 75 | + run: echo ::set-output name=prAction::$(cat ./action) |
0 commit comments