#!/bin/sh # Publishes the ISO images of the current version as a Gitea release: # release.sh # Needs GITEA_TOKEN, GITEA_SERVER_URL and GITEA_REPOSITORY (owner/name); in CI # the job provides them. Running it again for the same tag replaces the files. set -eu tag=$1 dir=$2 version=$(cat VERSION) [ "$tag" = "v$version" ] || { echo "release: tag $tag does not match VERSION $version" >&2; exit 1; } api=$GITEA_SERVER_URL/api/v1/repos/$GITEA_REPOSITORY auth="Authorization: token $GITEA_TOKEN" json() { python3 -c "import json,sys; d=json.load(sys.stdin); $1"; } isos="dasos-$version-x86_64.iso dasos-server-$version-x86_64.iso" cd "$dir" sha256sum $isos >SHA256SUMS if ! id=$(curl -fsS -H "$auth" "$api/releases/tags/$tag" 2>/dev/null | json 'print(d["id"])' 2>/dev/null); then id=$(curl -fsS -H "$auth" -H 'Content-Type: application/json' \ -d "{\"tag_name\":\"$tag\",\"name\":\"Das OS $version\",\"body\":\"Desktop and server live ISO images. Check them with sha256sum -c SHA256SUMS.\"}" \ "$api/releases" | json 'print(d["id"])') echo "release: created $tag (id $id)" fi # Files left from an earlier run for this tag are replaced curl -fsS -H "$auth" "$api/releases/$id/assets" | json '[print(a["id"], a["name"]) for a in d]' | while read -r asset name; do case " $isos SHA256SUMS " in *" $name "*) curl -fsS -X DELETE -H "$auth" "$api/releases/$id/assets/$asset" ;; esac done for f in $isos SHA256SUMS; do echo "release: uploading $f" curl -fsS -o /dev/null -H "$auth" -F "attachment=@$f" "$api/releases/$id/assets?name=$f" done echo "release: $GITEA_SERVER_URL/$GITEA_REPOSITORY/releases/tag/$tag"