-
Notifications
You must be signed in to change notification settings - Fork 424
65 lines (55 loc) · 2.12 KB
/
Copy pathpr-artifact-publish.yml
File metadata and controls
65 lines (55 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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' }}