chore(ci): finalize PR build artifacts (#455)

This commit is contained in:
David Chavez 2024-08-01 21:00:38 +02:00 committed by GitHub
parent 142b4d021b
commit d782d3dcb9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 28 additions and 21 deletions

View File

@ -7,32 +7,39 @@ on:
jobs: jobs:
update-pr-artifacts: update-pr-artifacts:
runs-on: ubuntu-latest runs-on: ubuntu-latest
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' if: (github.event.workflow_run.event == 'pull_request' || github.event.workflow_run.event == 'pull_request_target') && github.event.workflow_run.conclusion == 'success'
name: Update PR Artifacts name: Update PR Artifacts
steps: steps:
- name: Get PR Number - name: Get PR Number
id: pr-number id: pr-number
env: uses: actions/github-script@v6
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with:
run: | result-encoding: string
# Get list of PR's associated to the commit that triggered the workflow run script: |
prs=$(gh api \ const { owner, repo } = context.repo;
-H "Accept: application/vnd.github+json" \
/repos/${{ github.event.pull_request.head.repo.full_name }}/commits/${{ github.event.workflow_run.head_sha }}/pulls) const findPRNumber = async () => {
const pulls = await github.rest.pulls.list({ owner, repo });
# Find the PR against the current repo for await (const { data } of github.paginate.iterator(pulls)) {
pr_number=$(echo "$prs" | jq -r '.[] | select(.base.repo.full_name == "${{ github.repository }}") | .number' | head -n1) for (const pull of data) {
if (pull.head.sha === '${{ github.event.workflow_run.head_sha }}' && pull.user.id === ${{ github.event.sender.id }}) {
if [ -z "$pr_number" ]; then return pull.number;
echo "No pull request found for this workflow run" }
exit 1 }
else }
echo "pr_number=$pr_number" >> $GITHUB_OUTPUT
echo "PR number: $pr_number" return null;
fi };
const prNumber = await findPRNumber();
if (!prNumber) {
core.error(`No matching pull request found`);
} else {
return prNumber;
}
- name: Create Artifacts Content - name: Create Artifacts Content
id: artifacts-content id: artifacts-content
uses: actions/github-script@v7 uses: actions/github-script@v6
with: with:
result-encoding: string result-encoding: string
script: | script: |
@ -53,5 +60,5 @@ jobs:
with: with:
section-name: 'artifacts' section-name: 'artifacts'
repo-token: '${{ secrets.GITHUB_TOKEN }}' repo-token: '${{ secrets.GITHUB_TOKEN }}'
pr-number: ${{ steps.pr-number.outputs.pr_number }} pr-number: ${{ steps.pr-number.outputs.result }}
section-value: '${{ steps.artifacts-content.outputs.result }}' section-value: '${{ steps.artifacts-content.outputs.result }}'