@@ -31,25 +31,23 @@ jobs:
3131 - name : Create release zip
3232 run : zip -r "V${{ steps.get-version.outputs.version }}-prerelease.zip" .
3333
34- - name : Set Artifact Path
35- run : echo "ARTIFACT_PATH=release-${{ steps.get-version.outputs.version }}.zip" >> $GITHUB_ENV
36-
37- - name : Check if tag exists
38- id : check_tag
34+ - name : Check if release exists
35+ id : check_release
3936 run : |
4037 set -e
41- if git rev-parse "v${{ steps.get-version.outputs.version }}" >/dev/null 2>&1; then
42- echo "Tag v${{ steps.get-version.outputs.version }}" exists.
43- echo "TAG_EXISTS=true" >> $GITHUB_ENV
38+ response=$(curl -s -o /dev/null -w "%{http_code}" -X GET -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/releases/tags/v${{ steps.get-version.outputs.version }}")
39+ if [[ $response -eq 200 ]]; then
40+ echo "Release v${{ steps.get-version.outputs.version }}" exists.
41+ echo "RELEASE_EXISTS=true" >> $GITHUB_ENV
4442 else
45- echo "Tag v${{ steps.get-version.outputs.version }}" does not exist.
46- echo "TAG_EXISTS =false" >> $GITHUB_ENV
43+ echo "Release v${{ steps.get-version.outputs.version }}" does not exist.
44+ echo "RELEASE_EXISTS =false" >> $GITHUB_ENV
4745 fi
48- shell : bash
46+ env :
47+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
4948
50- - name : Create GitHub Release
51- if : env.TAG_EXISTS != 'true'
52- id : create_github_release
49+ - name : Create or update GitHub Release
50+ id : create_or_update_github_release
5351 uses : actions/create-release@v1
5452 with :
5553 tag_name : " v${{ steps.get-version.outputs.version }}"
5856 prerelease : true
5957 env :
6058 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
59+ if : env.RELEASE_EXISTS != 'true'
60+
61+ - name : Get Release ID
62+ if : env.RELEASE_EXISTS == 'true'
63+ id : get_release_id
64+ run : |
65+ set -e
66+ release_id=$(curl -s -X GET -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/releases/tags/v${{ steps.get-version.outputs.version }}" | jq -r '.id')
67+ echo "RELEASE_ID=$release_id" >> $GITHUB_ENV
6168
6269 - name : Upload release artifact
6370 uses : actions/upload-artifact@v2
6471 with :
6572 name : " release"
66- path : " ${{ env.ARTIFACT_PATH }}"
73+ path : " release-${{ steps.get-version.outputs.version }}.zip"
74+
75+ - name : Attach artifact to release
76+ if : env.RELEASE_EXISTS == 'true'
77+ run : |
78+ set -e
79+ curl -X POST -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" -H "Content-Type: application/zip" --data-binary @release-${{ steps.get-version.outputs.version }}.zip "https://uploads.github.com/repos/${{ github.repository }}/releases/${{ env.RELEASE_ID }}/assets?name=release-${{ steps.get-version.outputs.version }}.zip"
0 commit comments