30 lines
1.2 KiB
Bash
Executable File
30 lines
1.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Creates the Gitea release for the current tag (or reuses it) and uploads every file
|
|
# given as an argument, replacing files of the same name from an earlier run.
|
|
# Needs GITEA_TOKEN plus the GITHUB_* variables every Actions job gets.
|
|
set -euo pipefail
|
|
|
|
api="$GITHUB_SERVER_URL/api/v1/repos/$GITHUB_REPOSITORY"
|
|
tag="$GITHUB_REF_NAME"
|
|
auth=(-H "Authorization: token $GITEA_TOKEN")
|
|
json() { node -e "let s='';process.stdin.on('data',d=>s+=d).on('end',()=>{const v=JSON.parse(s);console.log($1)})"; }
|
|
|
|
if release=$(curl -sf "${auth[@]}" "$api/releases/tags/$tag"); then
|
|
echo "Using the existing release for $tag"
|
|
else
|
|
echo "Creating the release for $tag"
|
|
release=$(curl -sf "${auth[@]}" -H "Content-Type: application/json" \
|
|
-d "{\"tag_name\": \"$tag\", \"name\": \"$tag\"}" "$api/releases")
|
|
fi
|
|
id=$(echo "$release" | json 'v.id')
|
|
|
|
for file in "$@"; do
|
|
name=$(basename "$file")
|
|
old=$(echo "$release" | NAME="$name" json "(v.assets||[]).filter(a=>a.name===process.env.NAME).map(a=>a.id).join(' ')")
|
|
for asset in $old; do
|
|
curl -sf "${auth[@]}" -X DELETE "$api/releases/$id/assets/$asset"
|
|
done
|
|
echo "Uploading $name"
|
|
curl -sf "${auth[@]}" -F "attachment=@$file" "$api/releases/$id/assets?name=$name" >/dev/null
|
|
done
|