diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index 7fd968d..f8b6d74 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -16,6 +16,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Setup Go uses: actions/setup-go@v5 @@ -25,6 +27,34 @@ jobs: - name: Build linux amd64 binary run: make build GOOS=linux GOARCH=amd64 + - name: Generate release notes + id: release_notes + env: + TAG_NAME: ${{ github.ref_name }} + run: | + set -euo pipefail + + if [ -z "${TAG_NAME}" ]; then + echo "missing tag name" >&2 + exit 1 + fi + + previous_tag="$(git describe --tags --abbrev=0 "${TAG_NAME}^" 2>/dev/null || true)" + + { + printf 'body<> "${GITHUB_OUTPUT}" + - name: Create or fetch release id: release env: @@ -32,6 +62,7 @@ jobs: REPOSITORY: ${{ github.repository }} API_URL: ${{ github.api_url }} GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} + RELEASE_BODY: ${{ steps.release_notes.outputs.body }} run: | set -euo pipefail @@ -44,6 +75,19 @@ jobs: repo="${REPOSITORY#*/}" release_url="${API_URL}/repos/${owner}/${repo}/releases/tags/${TAG_NAME}" create_url="${API_URL}/repos/${owner}/${repo}/releases" + payload="$(python3 - <<'PY' +import json +import os + +print(json.dumps({ + "tag_name": os.environ["TAG_NAME"], + "name": os.environ["TAG_NAME"], + "body": os.environ["RELEASE_BODY"], + "prerelease": False, + "draft": False, +})) +PY + )" http_code="$(curl -sS -o release.json -w '%{http_code}' \ -H "Authorization: token ${GITEA_TOKEN}" \ @@ -51,13 +95,22 @@ jobs: "${release_url}")" if [ "${http_code}" = "404" ]; then - payload="$(printf '{"tag_name":"%s","name":"%s","prerelease":false,"draft":false}' "${TAG_NAME}" "${TAG_NAME}")" http_code="$(curl -sS -o release.json -w '%{http_code}' \ -X POST \ -H "Authorization: token ${GITEA_TOKEN}" \ -H "Content-Type: application/json" \ -d "${payload}" \ "${create_url}")" + elif [ "${http_code}" -ge 200 ] && [ "${http_code}" -lt 300 ]; then + release_id="$(python3 -c 'import json; print(json.load(open("release.json", "r", encoding="utf-8"))["id"])')" + update_url="${API_URL}/repos/${owner}/${repo}/releases/${release_id}" + + http_code="$(curl -sS -o release.json -w '%{http_code}' \ + -X PATCH \ + -H "Authorization: token ${GITEA_TOKEN}" \ + -H "Content-Type: application/json" \ + -d "${payload}" \ + "${update_url}")" fi if [ "${http_code}" -lt 200 ] || [ "${http_code}" -ge 300 ]; then