From 6da984775001ba0184c0f6cba73ff3558955778d Mon Sep 17 00:00:00 2001 From: timmy Date: Tue, 4 Aug 2026 14:32:54 +0000 Subject: [PATCH] fix: create releases through Gitea API --- .gitea/workflows/release.yml | 49 +++++++++++++++++++--------------- tests/test_release_workflow.py | 24 +++++++++++++++++ 2 files changed, 51 insertions(+), 22 deletions(-) create mode 100644 tests/test_release_workflow.py diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index b78a523..d4296ac 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -6,30 +6,35 @@ on: workflow_dispatch: jobs: - tag-release: + release-candidate: runs-on: ubuntu-latest - if: github.event_name == 'push' + permissions: + contents: write steps: - uses: actions/checkout@v4 - with: { fetch-depth: 0 } - - name: Auto-tag - run: | - set -e - TAG="0.0.${{ github.run_number }}" - git tag "$TAG" || true - git push origin "$TAG" || true - echo "tag=$TAG" >> "$GITHUB_OUTPUT" + with: + fetch-depth: 0 - draft-rc: - runs-on: ubuntu-latest - needs: tag-release - steps: - - uses: actions/checkout@v4 - with: { fetch-depth: 0 } - - name: Draft release - run: | - set -e - TAG="${{ needs.tag-release.outputs.tag }}" - gh release create "$TAG" --draft --title "RC $TAG" --notes "Automated release candidate for $TAG." || true + - name: Create Gitea tag and release candidate env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + set -euo pipefail + TAG="v0.1.0-rc.${{ github.run_number }}" + TARGET="${{ github.sha }}" + TAG_URL="${{ github.server_url }}/api/v1/repos/${{ github.repository }}/tags" + RELEASE_URL="${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases" + + printf '{"tag_name":"%s","target":"%s","message":"Automated release candidate %s"}\n' \ + "$TAG" "$TARGET" "$TAG" > /tmp/tag.json + curl --fail-with-body -sS -X POST "$TAG_URL" \ + -H "Authorization: token $TOKEN" \ + -H "Content-Type: application/json" \ + --data-binary @/tmp/tag.json + + printf '{"tag_name":"%s","target_commitish":"%s","name":"Release Candidate %s","body":"Automated release candidate for commit %s.","draft":false,"prerelease":true}\n' \ + "$TAG" "$TARGET" "$TAG" "$TARGET" > /tmp/release.json + curl --fail-with-body -sS -X POST "$RELEASE_URL" \ + -H "Authorization: token $TOKEN" \ + -H "Content-Type: application/json" \ + --data-binary @/tmp/release.json diff --git a/tests/test_release_workflow.py b/tests/test_release_workflow.py new file mode 100644 index 0000000..ccdc053 --- /dev/null +++ b/tests/test_release_workflow.py @@ -0,0 +1,24 @@ +from pathlib import Path + + +WORKFLOW = Path(".gitea/workflows/release.yml") + + +def test_release_workflow_uses_gitea_api_not_github_cli(): + text = WORKFLOW.read_text() + assert "gh release" not in text + assert "/api/v1/repos/${{ github.repository }}/tags" in text + assert "/api/v1/repos/${{ github.repository }}/releases" in text + + +def test_release_workflow_targets_merge_commit_and_marks_rc(): + text = WORKFLOW.read_text() + assert 'TARGET="${{ github.sha }}"' in text + assert '"prerelease":true' in text + assert '"draft":false' in text + + +def test_release_workflow_fails_on_api_error(): + text = WORKFLOW.read_text() + assert "curl --fail-with-body" in text + assert "|| true" not in text