Files
otunes/scripts/upload-release-asset.sh
T

23 lines
936 B
Bash
Executable File

#!/usr/bin/env bash
# Uploads a file to the Gitea release for the current tag, creating the release
# if it does not exist yet. Used by .gitea/workflows/mobile-build.yml.
# Usage: GITEA_TOKEN=... upload-release-asset.sh <file>
set -euo pipefail
file=$1
api="$GITHUB_SERVER_URL/api/v1/repos/$GITHUB_REPOSITORY/releases"
auth=(-H "Authorization: token $GITEA_TOKEN")
json_id() { node -pe 'JSON.parse(require("fs").readFileSync(0, "utf8")).id'; }
existing_id() { curl -fsS "${auth[@]}" "$api/tags/$GITHUB_REF_NAME" | json_id; }
create_id() {
curl -fsS "${auth[@]}" -H "Content-Type: application/json" \
-d "{\"tag_name\":\"$GITHUB_REF_NAME\",\"name\":\"$GITHUB_REF_NAME\"}" "$api" | json_id
}
# Android and iOS race to create the release; whoever loses re-reads it.
id=$(existing_id 2>/dev/null || create_id || existing_id)
curl -fsS "${auth[@]}" -F "attachment=@$file" \
"$api/$id/assets?name=$(basename "$file")" > /dev/null