Skip to content

Commit

Permalink
FIX Don't exit with error for deleted patch-release workflow (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli authored Oct 4, 2024
1 parent b3f1641 commit a7a1149
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,36 @@ jobs:
shell: bash
id: dispatch-tag-patch-release
run: |
# Check if the workflow currently exists. Without this, if the workflow USED to exist but was deleted,
# the response code for dispatching the workflow would be 422 instead of 404 so we can't rely on that.
# https://docs.github.com/en/rest/actions/workflows?apiVersion=2022-11-28#list-repository-workflows
RESP_CODE=$(curl -w %{http_code} -s -L -o __response.json \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ github.token }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/$GITHUB_REPOSITORY/actions/workflows
)
if [[ $RESP_CODE != "200" ]]; then
echo "Failed to get list of workflows - HTTP response code was $RESP_CODE"
cat __response.json
exit 1
fi
FOUND_WORKFLOW=0
WORKFLOWS=$(jq -r '.workflows[].path' __response.json)
while IFS= read -r WORKFLOW_PATH; do
if [[ "$WORKFLOW_PATH" == ".github/workflows/tag-patch-release.yml" ]]; then
echo "Found tag-patch-release.yml"
FOUND_WORKFLOW=1
break
fi
done <<< "$WORKFLOWS"
if [[ $FOUND_WORKFLOW == 0 ]]; then
echo "tag-patch-release.yml not present."
exit 0
fi
# https://docs.github.com/en/rest/actions/workflows?apiVersion=2022-11-28#create-a-workflow-dispatch-event
RESP_CODE=$(curl -w %{http_code} -s -L -o __response.json \
-X POST \
Expand All @@ -1063,10 +1093,6 @@ jobs:
https://api.github.com/repos/$GITHUB_REPOSITORY/actions/workflows/tag-patch-release.yml/dispatches \
-d "{\"ref\":\"$BRANCH\",\"inputs\":{\"latest_local_sha\":\"${{ needs.tests.outputs.latest_local_sha }}\"}}"
)
if [[ $RESP_CODE == "404" ]]; then
echo "tag-patch-release.yml not present."
exit 0
fi
if [[ $RESP_CODE != "204" ]]; then
echo "Failed to dispatch workflow - HTTP response code was $RESP_CODE"
cat __response.json
Expand Down

0 comments on commit a7a1149

Please sign in to comment.