2024-08-01 13:02:35 +02:00
|
|
|
name: update-pr-artifacts
|
|
|
|
on:
|
|
|
|
workflow_run:
|
2024-08-01 14:39:40 +02:00
|
|
|
workflows: [validate-external, validate-internal]
|
2024-08-01 13:02:35 +02:00
|
|
|
types:
|
|
|
|
- completed
|
|
|
|
jobs:
|
|
|
|
update-pr-artifacts:
|
|
|
|
runs-on: ubuntu-latest
|
2024-08-01 21:00:38 +02:00
|
|
|
if: (github.event.workflow_run.event == 'pull_request' || github.event.workflow_run.event == 'pull_request_target') && github.event.workflow_run.conclusion == 'success'
|
2024-08-01 13:02:35 +02:00
|
|
|
name: Update PR Artifacts
|
|
|
|
steps:
|
|
|
|
- name: Get PR Number
|
|
|
|
id: pr-number
|
2024-08-01 21:00:38 +02:00
|
|
|
uses: actions/github-script@v6
|
|
|
|
with:
|
|
|
|
result-encoding: string
|
|
|
|
script: |
|
|
|
|
const { owner, repo } = context.repo;
|
|
|
|
|
|
|
|
const findPRNumber = async () => {
|
|
|
|
const pulls = await github.rest.pulls.list({ owner, repo });
|
|
|
|
for await (const { data } of github.paginate.iterator(pulls)) {
|
|
|
|
for (const pull of data) {
|
|
|
|
if (pull.head.sha === '${{ github.event.workflow_run.head_sha }}' && pull.user.id === ${{ github.event.sender.id }}) {
|
|
|
|
return pull.number;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
const prNumber = await findPRNumber();
|
|
|
|
if (!prNumber) {
|
|
|
|
core.error(`No matching pull request found`);
|
|
|
|
} else {
|
|
|
|
return prNumber;
|
|
|
|
}
|
2024-08-01 13:02:35 +02:00
|
|
|
- name: Create Artifacts Content
|
|
|
|
id: artifacts-content
|
2024-08-01 21:00:38 +02:00
|
|
|
uses: actions/github-script@v6
|
2024-08-01 13:02:35 +02:00
|
|
|
with:
|
|
|
|
result-encoding: string
|
|
|
|
script: |
|
|
|
|
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
|
|
|
|
owner: context.repo.owner,
|
|
|
|
repo: context.repo.repo,
|
|
|
|
run_id: context.payload.workflow_run.id,
|
|
|
|
});
|
|
|
|
|
|
|
|
const nightlyLinks = artifacts.data.artifacts.reduce((acc, item) => {
|
|
|
|
acc += `- [${item.name}.zip](https://nightly.link/${context.repo.owner}/${context.repo.repo}/actions/artifacts/${item.id}.zip)\n`;
|
|
|
|
return acc;
|
|
|
|
}, '### Build Artifacts\n');
|
|
|
|
|
|
|
|
return nightlyLinks;
|
|
|
|
- name: Update PR Description
|
|
|
|
uses: garrettjoecox/pr-section@3.1.0
|
|
|
|
with:
|
|
|
|
section-name: 'artifacts'
|
|
|
|
repo-token: '${{ secrets.GITHUB_TOKEN }}'
|
2024-08-01 21:00:38 +02:00
|
|
|
pr-number: ${{ steps.pr-number.outputs.result }}
|
2024-08-01 13:02:35 +02:00
|
|
|
section-value: '${{ steps.artifacts-content.outputs.result }}'
|