Files
goon_plugin/.github/workflows/release.yml
T
kfj001 c2659dcb1d
CI / test (pull_request) Successful in 5m45s
ci: make release step idempotent + fix Gitea asset upload
- resolve-or-create the release by tag to avoid the 409 'Release is has no Tag'
  when a release already exists for the tag (e.g. one made manually in the UI)
- use POST /releases/{id}/assets with multipart field 'attachment'
  (was the obsolete /_attachments route with field 'file')
2026-08-31 00:31:40 -07:00

81 lines
2.8 KiB
YAML

name: Release
on:
push:
tags:
- 'v*'
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Package dist.zip
shell: bash
run: |
cd dist
zip -r "../vidplex-${{ github.ref_name }}.zip" .
- name: Create Gitea release
shell: bash
env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
GITEA_API: ${{ secrets.GITEA_API || 'http://192.168.1.74:30008/api/v1' }}
REPO: ${{ github.repository }}
TAG: ${{ github.ref_name }}
run: |
if [ -z "$GITEA_TOKEN" ]; then
echo "::warning::GITEA_TOKEN secret is not set; skipping release creation. Add it in Gitea repo Settings > Secrets (repo scope)."
exit 0
fi
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 "Content-Type: application/json" \
-d "{\"tag_name\": \"$TAG\", \"name\": \"$TAG\", \"body\": \"Automated release build for $TAG\"}" \
"$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
echo "Uploading asset to release $release_id."
resp=$(curl -s -o /tmp/att.json -w "%{http_code}" -X POST \
-H "Authorization: token $GITEA_TOKEN" \
-F "attachment=@vidplex-${TAG}.zip" \
"$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