Merge pull request 'feat: Fix release workflow: merged PR produced no tag or release' (#17) from timmy/16-fix-release-workflow-merged-pr-produced-no-tag-o into main
This commit is contained in:
commit
ce376aaa6e
|
|
@ -6,30 +6,35 @@ on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
tag-release:
|
release-candidate:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: github.event_name == 'push'
|
permissions:
|
||||||
|
contents: write
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with: { fetch-depth: 0 }
|
with:
|
||||||
- name: Auto-tag
|
fetch-depth: 0
|
||||||
run: |
|
|
||||||
set -e
|
|
||||||
TAG="0.0.${{ github.run_number }}"
|
|
||||||
git tag "$TAG" || true
|
|
||||||
git push origin "$TAG" || true
|
|
||||||
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
|
|
||||||
|
|
||||||
draft-rc:
|
- name: Create Gitea tag and release candidate
|
||||||
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
|
|
||||||
env:
|
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
|
||||||
|
|
|
||||||
24
tests/test_release_workflow.py
Normal file
24
tests/test_release_workflow.py
Normal file
|
|
@ -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
|
||||||
Loading…
Reference in New Issue
Block a user