Added new github action to retrieve the PR associated with the branch… #1
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Get PR Number | |
description: Get PR number for merge queues and squash merges | |
branding: | |
icon: package | |
color: blue | |
inputs: | |
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: | |
- id: vars | |
shell: bash | |
run: | | |
# Get PR number based on the event type | |
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.sha }}/pulls \ | |
| jq 'map(select(.base.ref == "release/${{ github.ref_name }}")) | .[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" | |
pr="" | |
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 |