-
Notifications
You must be signed in to change notification settings - Fork 157
59 lines (51 loc) · 1.91 KB
/
Copy pathadd-milestone.yml
File metadata and controls
59 lines (51 loc) · 1.91 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
name: Add Milestone on a Merged PR
on:
pull_request:
types:
- closed
branches:
- main
- "v[0-9]+.[0-9]+"
permissions: {}
jobs:
add-milestone-pr:
name: Add Milestone on PR
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
permissions:
pull-requests: write
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
steps:
- name: Get current milestone from branch
id: current-milestone
run: |
BASE_BRANCH="${{ github.base_ref }}"
if [[ "$BASE_BRANCH" == "main" ]]; then
# For main, use the open milestone with the highest creation order (latest upcoming release).
MILESTONE=$(gh api repos/${{ github.repository }}/milestones \
--jq '[.[] | select(.state == "open")] | sort_by(.number) | last | .title')
elif [[ "$BASE_BRANCH" =~ ^v([0-9]+)\.([0-9]+)$ ]]; then
# For release branches like v1.25, derive the milestone as v1.25.0.
MILESTONE="v${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.0"
else
echo "Error: Unexpected branch '$BASE_BRANCH'."
exit 1
fi
if [ -z "$MILESTONE" ]; then
echo "Error: Couldn't determine a current milestone for branch '$BASE_BRANCH'."
exit 1
fi
if [[ ! $MILESTONE =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Malformed milestone '$MILESTONE'. It should be of the form 'vX.Y.Z'."
exit 1
fi
echo "MILESTONE=$MILESTONE" >> "$GITHUB_OUTPUT"
- name: Set the merged PR milestone to current milestone
run: |
echo "Setting milestone $MILESTONE to PR $NUMBER."
gh issue edit "$NUMBER" --milestone "$MILESTONE"
env:
NUMBER: ${{ github.event.number }}
MILESTONE: ${{ steps.current-milestone.outputs.MILESTONE }}