Skip to content

CREATE_NEW_MILESTONE #8

CREATE_NEW_MILESTONE

CREATE_NEW_MILESTONE #8

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"