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