Skip to content

Commit

Permalink
Improved error handling for release creation
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorm committed Apr 26, 2022
1 parent 655ac99 commit e15fc71
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ jobs:
labels: '${{ steps.meta.outputs.labels }}'
push: "${{ github.event_name != 'pull_request' }}"

release:
name: 'Create release'
if: "startsWith(github.ref, 'refs/tags/')"
release-github:
name: 'Create GitHub release'
if: "startsWith(github.ref, 'refs/tags/v')"
needs: ['build', 'build-push-docker']
runs-on: 'ubuntu-latest'
permissions:
Expand All @@ -169,21 +169,21 @@ jobs:
--header 'Accept: application/vnd.github.v3+json' \
--header 'Content-Type: application/json' \
--write-out '%{http_code}' --output /dev/null ||:)"
if [ "${RELEASE_STATUS:?}" != '200' ]; then
RELEASE_ID="$(curl -fsS --proto '=https' --tlsv1.3 --globoff \
--url "https://api.github.com/repos/${GITHUB_REPOSITORY:?}/releases" \
if [ "${RELEASE_STATUS:?}" = '200' ]; then exit 0; fi
RELEASE_ID="$(curl -fsS --proto '=https' --tlsv1.3 --globoff \
--url "https://api.github.com/repos/${GITHUB_REPOSITORY:?}/releases" \
--header 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
--header 'Accept: application/vnd.github.v3+json' \
--header 'Content-Type: application/json' \
--data "$(jq -rn --arg tag "${GITHUB_REF_NAME:?}" '{"name": $tag, "tag_name": $tag, "generate_release_notes": true}')" | jq -r '.id')"
if [ -z "${RELEASE_ID-}" ] || [ "${RELEASE_ID:?}" = 'null' ]; then exit 1; fi
for asset in ./*; do
[ -f "${asset:?}" ] || continue
encodedAssetName="$(jq -rn --arg v "$(basename "${asset:?}")" '$v|@uri')"
curl -fsS --proto '=https' --tlsv1.3 --globoff \
--url "https://uploads.github.com/repos/${GITHUB_REPOSITORY:?}/releases/${RELEASE_ID:?}/assets?name=${encodedAssetName:?})" \
--header 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
--header 'Accept: application/vnd.github.v3+json' \
--header 'Content-Type: application/json' \
--data "$(jq -rn --arg tag "${GITHUB_REF_NAME:?}" '{"name": $tag, "tag_name": $tag, "generate_release_notes": true}')" | jq -r '.id')"
for asset in ./*; do
[ -f "${asset:?}" ] || continue
encodedAssetName="$(jq -rn --arg v "$(basename "${asset:?}")" '$v|@uri')"
curl -fsS --proto '=https' --tlsv1.3 --globoff \
--url "https://uploads.github.com/repos/${GITHUB_REPOSITORY:?}/releases/${RELEASE_ID:?}/assets?name=${encodedAssetName:?})" \
--header 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
--header 'Accept: application/vnd.github.v3+json' \
--header 'Content-Type: application/octet-stream' \
--data-binary "@${asset:?}" --output /dev/null
done
fi
--header 'Content-Type: application/octet-stream' \
--data-binary "@${asset:?}" --output /dev/null
done

0 comments on commit e15fc71

Please sign in to comment.