Skip to content

PR Artifact Publisher #4936

PR Artifact Publisher

PR Artifact Publisher #4936

name: PR Artifact Publisher
on:
workflow_run:
workflows: [matrix]
types: [requested, completed]
permissions:
actions: read
contents: read
pull-requests: write
concurrency:
group: pr-artifact-publish-${{ github.event.workflow_run.pull_requests[0].number || github.event.workflow_run.head_sha }}
cancel-in-progress: false
jobs:
publish:
if: github.event.workflow_run.event == 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Resolve pull request metadata
id: pr
env:
GH_TOKEN: ${{ github.token }}
REPOSITORY: ${{ github.repository }}
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
run: |
set -euo pipefail
pr_number=$(jq -r '.workflow_run.pull_requests[0].number // empty' "$GITHUB_EVENT_PATH")
if [ -z "$pr_number" ]; then
pr_number=$(gh api "repos/${REPOSITORY}/pulls?state=open&base=main&per_page=100" \
--jq "map(select(.head.sha == \"${HEAD_SHA}\"))[0].number // empty")
fi
if [ -z "$pr_number" ]; then
echo "found=false" >> "$GITHUB_OUTPUT"
exit 0
fi
current_head=$(gh api "repos/${REPOSITORY}/pulls/${pr_number}" --jq '.head.sha')
if [ "$current_head" != "$HEAD_SHA" ]; then
echo "found=false" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "found=true" >> "$GITHUB_OUTPUT"
echo "number=$pr_number" >> "$GITHUB_OUTPUT"
- name: Check out workflow actions
if: steps.pr.outputs.found == 'true'
uses: actions/checkout@v4
- name: Publish pull request artifact links
if: steps.pr.outputs.found == 'true'
uses: ./.github/actions/publish-pr-artifact-body
with:
repository: ${{ github.repository }}
pr-number: ${{ steps.pr.outputs.number }}
run-id: ${{ github.event.workflow_run.id }}
run-url: ${{ github.event.workflow_run.html_url }}
head-sha: ${{ github.event.workflow_run.head_sha }}
token: ${{ github.token }}
watch: ${{ github.event.action == 'requested' }}