diff --git a/.forgejo/workflows/release.yml b/.forgejo/workflows/release.yml index b43fe5e..06e7109 100644 --- a/.forgejo/workflows/release.yml +++ b/.forgejo/workflows/release.yml @@ -1,9 +1,16 @@ name: release on: - release: - types: [published] - workflow_dispatch: # allows manual runs from ui + push: + branches: + - main + tags: + - 'v*' + workflow_dispatch: + inputs: + tag: + description: 'Tag to release (empty = build only)' + required: false jobs: build: @@ -35,18 +42,29 @@ jobs: zig build -Dtarget=x86_64-windows-gnu -Doptimize=ReleaseFast mv zig-out/bin/sandbox.exe lofivor-windows-x86_64.exe - - name: Upload to release + - name: Create release and upload + if: startsWith(github.ref, 'refs/tags/') || github.event.inputs.tag != '' env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + FORGEJO_TOKEN: ${{ secrets.FORGEJO_TOKEN }} run: | - RELEASE_ID="${{ github.event.release.id }}" - API_URL="${{ github.api_url }}/repos/${{ github.repository }}/releases/${RELEASE_ID}/assets" + TAG="${{ github.event.inputs.tag || github.ref_name }}" + API_BASE="${{ github.server_url }}/api/v1" + REPO="${{ github.repository }}" + # create release + RELEASE_ID=$(curl -sf -X POST \ + -H "Authorization: token ${FORGEJO_TOKEN}" \ + -H "Content-Type: application/json" \ + -d "{\"tag_name\": \"${TAG}\", \"name\": \"${TAG}\"}" \ + "${API_BASE}/repos/${REPO}/releases" | jq -r '.id') + + echo "Created release ${RELEASE_ID}" + + # upload assets for file in lofivor-linux-x86_64 lofivor-windows-x86_64.exe; do echo "Uploading $file..." - curl -X POST \ - -H "Authorization: token ${GITHUB_TOKEN}" \ - -H "Content-Type: application/octet-stream" \ - --data-binary @"$file" \ - "${API_URL}?name=${file}" + curl -sf -X POST \ + -H "Authorization: token ${FORGEJO_TOKEN}" \ + -F "attachment=@${file}" \ + "${API_BASE}/repos/${REPO}/releases/${RELEASE_ID}/assets?name=${file}" done