ci: make release step idempotent + fix Gitea asset upload #9
@@ -42,13 +42,40 @@ jobs:
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
release_id=$(curl -s -X POST \
|
json_id() { node -e 'let d="";process.stdin.on("data",c=>d+=c).on("end",()=>{const j=JSON.parse(d||"{}");if(j.id==null){console.error("no release id:",JSON.stringify(j));process.exit(1)}console.log(j.id)})'; }
|
||||||
|
|
||||||
|
release_id=$(
|
||||||
|
curl -s -o /tmp/rel.json -w "%{http_code}" \
|
||||||
|
-H "Authorization: token $GITEA_TOKEN" \
|
||||||
|
"$GITEA_API/repos/$REPO/releases/tags/$TAG"
|
||||||
|
)
|
||||||
|
|
||||||
|
if [ "$release_id" = "200" ]; then
|
||||||
|
echo "Release for $TAG already exists; reusing it."
|
||||||
|
release_id=$(json_id < /tmp/rel.json)
|
||||||
|
else
|
||||||
|
echo "Creating release for $TAG."
|
||||||
|
release_id=$(
|
||||||
|
curl -s -o /tmp/rel.json -w "%{http_code}" -X POST \
|
||||||
-H "Authorization: token $GITEA_TOKEN" \
|
-H "Authorization: token $GITEA_TOKEN" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d "{\"tag_name\": \"$TAG\", \"name\": \"$TAG\", \"body\": \"Automated release build for $TAG\"}" \
|
-d "{\"tag_name\": \"$TAG\", \"name\": \"$TAG\", \"body\": \"Automated release build for $TAG\"}" \
|
||||||
"$GITEA_API/repos/$REPO/releases" | node -e 'let d="";process.stdin.on("data",c=>d+=c).on("end",()=>{const j=JSON.parse(d);if(j.id==null){console.error("release create failed:",JSON.stringify(j));process.exit(1)}console.log(j.id)})')
|
"$GITEA_API/repos/$REPO/releases"
|
||||||
|
)
|
||||||
|
case "$release_id" in
|
||||||
|
201|200) release_id=$(json_id < /tmp/rel.json) ;;
|
||||||
|
*) echo "::error::release create returned HTTP $release_id: $(cat /tmp/rel.json)"; exit 1 ;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
curl -s -X POST \
|
echo "Uploading asset to release $release_id."
|
||||||
|
resp=$(curl -s -o /tmp/att.json -w "%{http_code}" -X POST \
|
||||||
-H "Authorization: token $GITEA_TOKEN" \
|
-H "Authorization: token $GITEA_TOKEN" \
|
||||||
-F "file=@vidplex-${TAG}.zip" \
|
-F "attachment=@vidplex-${TAG}.zip" \
|
||||||
"$GITEA_API/repos/$REPO/releases/$release_id/_attachments"
|
"$GITEA_API/repos/$REPO/releases/$release_id/assets")
|
||||||
|
if [ "$resp" != "200" ] && [ "$resp" != "201" ]; then
|
||||||
|
echo "::error::asset upload returned HTTP $resp: $(cat /tmp/att.json)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
cat /tmp/att.json
|
||||||
|
echo
|
||||||
Reference in new issue
Block a user