-
Notifications
You must be signed in to change notification settings - Fork 493
46 lines (44 loc) · 1.52 KB
/
CREATE_MILESTONE.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
name: CREATE_NEW_MILESTONE
on:
milestone:
types: ['closed']
jobs:
create_milestone:
runs-on: ubuntu-latest
name: Create new Milestone
if: startsWith(github.event.milestone.title, 'M')
steps:
- name: Get new Milestone Title
id: get_title
env:
TITLE: ${{github.event.milestone.title}}
run: |
MILESTONE_NUMBER=${TITLE:1}
INCREMENTED_NUMBER=$((MILESTONE_NUMBER + 1))
echo "MILESTONE_NAME=M$INCREMENTED_NUMBER" >> $GITHUB_OUTPUT
- name: Check if Milestone already exists
id: check_if_milestone_exists
env:
TITLE: ${{steps.get_title.outputs.MILESTONE_NAME}}
run: |
existing_milestones=$(
gh api -H "Accept: application/vnd.github.v3+json" \
/repos/${{ github.repository }}/milestones \
--jq '[.[] | select(.title | startswith("'$TITLE'")) | .number ][0]'
)
if [ -z "$existing_milestones" ]; then
echo "MILESTONE_EXISTS=false" >> $GITHUB_OUTPUT
else
echo "MILESTONE_EXISTS=true" >> $GITHUB_OUTPUT
fi
- name: Create new Milestone
if: steps.check_if_milestone_exists.outputs.MILESTONE_EXISTS == 'false'
env:
TITLE: ${{steps.get_title.outputs.MILESTONE_NAME}}
GH_TOKEN: ${{ github.token }}
shell: bash
run: |
gh api \
--method POST \
/repos/${{ github.repository }}/milestones \
-f "title=$TITLE" -f "state=open"