pr-artifacts #1150
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: pr-artifacts | |
on: | |
workflow_run: | |
workflows: [generate-builds] | |
types: | |
- completed | |
jobs: | |
pr-artifacts: | |
runs-on: ubuntu-latest | |
if: ${{ github.event.workflow_run.event == 'pull_request' }} | |
steps: | |
- id: 'pr-number' | |
uses: actions/github-script@v7 | |
with: | |
result-encoding: string | |
script: | | |
const {owner, repo} = context.repo; | |
const pullHeadSHA = '${{github.event.workflow_run.head_sha}}'; | |
const pullUserId = ${{github.event.sender.id}}; | |
const prNumber = await (async () => { | |
for await (const { data } of github.paginate.iterator( | |
github.rest.pulls.list, { owner, repo } | |
)) { | |
for (const pull of data) { | |
if (pull.head.sha === pullHeadSHA && pull.user.id === pullUserId) { | |
return pull.number; | |
} | |
} | |
} | |
})(); | |
if (!prNumber) { | |
return core.error(`No matching pull request found`); | |
} | |
return prNumber; | |
- id: 'artifacts-text' | |
uses: actions/github-script@v7 | |
with: | |
result-encoding: string | |
script: | | |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
run_id: context.payload.workflow_run.id, | |
}); | |
return allArtifacts.data.artifacts.reduce((acc, item) => { | |
if (item.name === "assets") return acc; | |
if (item.name === "2ship.o2r") return acc; | |
acc += ` | |
- [${item.name}.zip](https://nightly.link/${context.repo.owner}/${context.repo.repo}/actions/artifacts/${item.id}.zip)`; | |
return acc; | |
}, '### Build Artifacts'); | |
- id: 'add-to-pr' | |
uses: garrettjoecox/[email protected] | |
with: | |
repo-token: '${{ secrets.GITHUB_TOKEN }}' | |
pr-number: ${{ steps.pr-number.outputs.result }} | |
section-name: 'artifacts' | |
section-value: '${{ steps.artifacts-text.outputs.result }}' |