CREATE_NEW_MILESTONE #7
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: 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: getTitle | |
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: Create new Milestone | |
env: | |
TITLE: ${{steps.getTitle.outputs.MILESTONE_NAME}} | |
GH_TOKEN: ${{ github.token }} | |
shell: bash | |
run: | | |
response=$(gh api \ | |
--method POST \ | |
/repos/${{ github.repository }}/milestones \ | |
-f "title=$TITLE" -f "state=open") | |
# if response has a errors[].code === "already_exists" in a JSON response, we do nothing | |
if echo "$response" | jq -e '.errors | map(select(.code == "already_exists")) | length > 0' > /dev/null; then | |
echo "Milestone $TITLE already exists, no action needed" | |
# if there is .title === $TITLE in the response, we successfully created the milestone | |
elif echo "$response" | jq -e ".title == \"$TITLE\"" >/dev/null; then | |
echo "Milestone $TITLE created successfully" | |
# otherwise, we print the error | |
else | |
echo "Error creating milestone $TITLE" | |
echo $response | |
exit 1 | |
fi |