-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yml
78 lines (70 loc) · 2.41 KB
/
action.yml
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
66
67
68
69
70
71
72
73
74
75
76
77
78
name: Get PR Number
description: Get PR number for mergue queues and squash merges
branding:
icon: package
color: blue
inputs:
### Required
# Nothing!
### Typical / recommended
# Nothing!
### Usually a bad idea / not recommended
token:
description: Specify token (GH or PAT), instead of inheriting one from the calling workflow
default: ${{ github.token }}
outputs:
pr:
description: 'Associated pull request number'
value: ${{ steps.vars.outputs.pr }}
runs:
using: composite
steps:
# Process variables and inputs
- uses: actions/checkout@v4
- id: vars
shell: bash
run: |
# Get PR number (pull_request, merge_group or push)
if [ ${{ github.event_name }} == 'pull_request' ]
then
echo "Event type: pull request"
pr=${{ github.event.number }}
elif [ ${{ github.event_name }} == 'merge_group' ]
then
echo "Event type: merge queue"
pr=$(echo ${{ github.event.merge_group.head_ref }} | grep -Eo "queue/main/pr-[0-9]+" | cut -d '-' -f2)
elif [ ${{ github.event_name }} == 'push' ]
then
echo "Event type: push"
pr=$(\
curl -sL -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ inputs.token }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ github.repository }}/commits/${{ github.event.after }}/pulls \
| jq .[0].number
)
elif [ ${{ github.event_name }} == 'release' ]
then
echo "Event type: release"
pr=$(\
curl -sL -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ inputs.token }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/search/issues\?q\=repo:${{ github.repository }}+is:pr+is:merged \
| jq .items[0].number
)
if [ -z "${pr}" ]
then
echo "No PR number found. Was this push triggered by a squashed PR merge?"
pr=""
fi
else
echo "Event type: unknown or unexpected"
fi
# Validate PR number
if [[ ! "${pr}" =~ ^[0-9]+$ ]]; then
echo "PR number format incorrect: ${pr}"
exit 1
fi
# Output PR number
echo "Summary ---"
echo -e "\tPR: ${pr}"
echo "pr=${pr}" >> $GITHUB_OUTPUT