From 343f647770629d4e9cac9a20aef8b6cd9536b890 Mon Sep 17 00:00:00 2001 From: Keith Solomon Date: Tue, 11 Aug 2026 13:15:31 -0500 Subject: [PATCH] Call Gitea REST API directly for releases (Gitea Actions compat) --- .github/workflows/release.yml | 64 +++++++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 6 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 07dac1c..9377a6a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -69,12 +69,64 @@ jobs: path: dist/projects-portfolio-*.zip if-no-files-found: error - - name: Create GitHub release + - name: Create release env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} + REPO: ${{ github.repository }} + TAG: ${{ github.ref_name }} run: | set -euo pipefail - gh release create "$GITHUB_REF_NAME" \ - --title "$GITHUB_REF_NAME" \ - --generate-notes \ - dist/projects-portfolio-*.zip + if [ -z "${GITEA_TOKEN:-}" ]; then + echo "::error::GITEA_TOKEN secret is not set. Create a personal access token in Gitea with 'write:repository' scope and add it as a repository secret named GITEA_TOKEN." >&2 + exit 1 + fi + + API="https://git.keithsolomon.net/api/v1" + + # Build the JSON payload with python (no jq dependency). + payload=$(TAG="$TAG" python3 -c ' + import json, os, sys + tag = os.environ["TAG"] + body = ( + "Automated release.\n\n" + "Built from commit " + os.environ.get("GITHUB_SHA", "unknown") + ".\n\n" + "See the workflow run for the artifact." + ) + print(json.dumps({ + "tag_name": tag, + "name": tag, + "body": body, + "draft": False, + "prerelease": False, + })) + ') + + # 1. Create the release (Gitea doesn't auto-generate notes). + release_json=$(curl -fsS -X POST \ + -H "Authorization: token ${GITEA_TOKEN}" \ + -H "Content-Type: application/json" \ + -d "$payload" \ + "${API}/repos/${REPO}/releases") + + # 2. Extract the release id (Gitea returns the full release object). + release_id=$(TAG="$TAG" python3 -c ' + import json, sys + data = json.loads(sys.stdin.read()) + print(data.get("id", "")) + ' <<<"$release_json") + + if [ -z "$release_id" ]; then + echo "::error::Failed to create release. Response: $release_json" >&2 + exit 1 + fi + echo "Created release id=$release_id" + + # 3. Upload the zip as a release asset. + zip_path=( dist/projects-portfolio-*.zip ) + zip_path="${zip_path[0]}" + curl -fsS -X POST \ + -H "Authorization: token ${GITEA_TOKEN}" \ + -H "Content-Type: application/zip" \ + --data-binary "@${zip_path}" \ + "${API}/repos/${REPO}/releases/${release_id}/assets?name=$(basename "$zip_path")" + echo "Uploaded asset: $(basename "$zip_path")"