Skip to content

Commit

Permalink
chore(CI): gracefully handle creating milestone with existing name
Browse files Browse the repository at this point in the history
  • Loading branch information
misiekhardcore committed Oct 28, 2024
1 parent 34d38bc commit 08fbe6e
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions .github/workflows/CREATE_MILESTONE.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,22 @@ jobs:
env:
TITLE: ${{steps.getTitle.outputs.MILESTONE_NAME}}
GH_TOKEN: ${{ github.token }}
shell: bash
run: |
gh api \
response=$(gh api \
--method POST \
/repos/${{ github.repository }}/milestones \
-f "title=$TITLE" -f "state=open"
-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

0 comments on commit 08fbe6e

Please sign in to comment.