|
| 1 | +#!/bin/bash |
| 2 | +set -x -e |
| 3 | +DEBUG=$1 # Value is '' or 'debug' |
| 4 | +GITHUB_ACCESS_TOKEN=$2 |
| 5 | +TAG=$3 # Release name/tag |
| 6 | + |
| 7 | +# For tags `actions/checkout@v2` action fetches a tag's commit, but |
| 8 | +# not the tag annotation itself. Let's refetch the tag from origin. |
| 9 | +# This makes `git show --no-patch --format=%n $TAG` work again. |
| 10 | +git tag --delete $TAG |
| 11 | +git fetch --tags |
| 12 | + |
| 13 | +git show --no-patch --format=%n $TAG | \ |
| 14 | + sed -e '1,/Release notes/d' > release_notes.md |
| 15 | + |
| 16 | +# Try to create a release |
| 17 | +jq --null-input --arg tag $TAG \ |
| 18 | + --rawfile body release_notes.md \ |
| 19 | + '{"tag_name": $tag, "name": $tag, "body": $body}' | \ |
| 20 | +curl -v \ |
| 21 | + -X POST \ |
| 22 | + -H "Accept: application/vnd.github+json" \ |
| 23 | + -H "Authorization: token $GITHUB_ACCESS_TOKEN" \ |
| 24 | + -H 'Content-Type: application/json' \ |
| 25 | + https://api.github.com/repos/$GITHUB_REPOSITORY/releases \ |
| 26 | + -d "@-" |
| 27 | + |
| 28 | +rm -f release_notes.md |
| 29 | + |
| 30 | +# Get asset upload url, drop "quotes" around it and {parameters} at the end |
| 31 | +upload_url=$( curl \ |
| 32 | + -H "Accept: application/vnd.github+json" \ |
| 33 | + -H "Authorization: token $GITHUB_ACCESS_TOKEN" \ |
| 34 | + https://api.github.com/repos/$GITHUB_REPOSITORY/releases/tags/$TAG | \ |
| 35 | + jq -r '.upload_url | rtrimstr("{?name,label}")') |
| 36 | + |
| 37 | +echo "upload_url=$upload_url" |
| 38 | + |
| 39 | +chmod -R -v +x als-*-$DEBUG |
| 40 | + |
| 41 | +for X in Linux macOS Windows ; do |
| 42 | + FILE=als-$TAG-$X${DEBUG:+-debug}_amd64.zip |
| 43 | + cd als-$X-$DEBUG |
| 44 | + zip -9 -r ../$FILE . |
| 45 | + cd .. |
| 46 | + |
| 47 | + # Upload $FILE as an asset to the release |
| 48 | + curl \ |
| 49 | + -X POST \ |
| 50 | + -H "Accept: application/vnd.github+json" \ |
| 51 | + -H "Authorization: token $GITHUB_ACCESS_TOKEN" \ |
| 52 | + -H 'Content-Type: application/zip' \ |
| 53 | + --data-binary @$FILE \ |
| 54 | + $upload_url?name=$FILE |
| 55 | + rm -v -f $FILE |
| 56 | +done |
0 commit comments