Compare commits
5 Commits
6d8263c5b5
...
34a69620f5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
34a69620f5 | ||
|
|
f90c76911a | ||
| 8eccea96ec | |||
|
|
7ee4f58bfd | ||
|
|
cc99aa815b |
@ -125,22 +125,28 @@ jobs:
|
|||||||
RELEASE_TAG: ${{ needs.autotag.outputs.release_tag }}
|
RELEASE_TAG: ${{ needs.autotag.outputs.release_tag }}
|
||||||
run: |
|
run: |
|
||||||
set -eu
|
set -eu
|
||||||
# Use the tag output from autotag — never rely on git describe
|
|
||||||
CURRENT_TAG="${RELEASE_TAG}"
|
CURRENT_TAG="${RELEASE_TAG}"
|
||||||
echo "Building changelog for $CURRENT_TAG"
|
echo "Building changelog for $CURRENT_TAG"
|
||||||
|
|
||||||
|
# Verify the tag is present locally after fetch
|
||||||
|
if ! git rev-parse "refs/tags/${CURRENT_TAG}" >/dev/null 2>&1; then
|
||||||
|
echo "ERROR: tag ${CURRENT_TAG} not found locally after fetch"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
git-cliff --config cliff.toml --output CHANGELOG.md
|
git-cliff --config cliff.toml --output CHANGELOG.md
|
||||||
PREV_TAG=$(git tag --sort=-version:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' \
|
PREV_TAG=$(git tag --sort=-version:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' \
|
||||||
| grep -v "^${CURRENT_TAG}$" | head -1 || echo "")
|
| grep -v "^${CURRENT_TAG}$" | head -1 || echo "")
|
||||||
if [ -n "$PREV_TAG" ]; then
|
if [ -n "$PREV_TAG" ]; then
|
||||||
git-cliff --config cliff.toml --tag "$CURRENT_TAG" --strip all > /tmp/release_body.md || true
|
git-cliff --config cliff.toml --tag "$CURRENT_TAG" --strip all > /tmp/release_body.md || true
|
||||||
else
|
else
|
||||||
echo "=== No previous tag found, generating from git commits ==="
|
echo "No previous tag found, generating from git commits"
|
||||||
git log --pretty=format:"- %s" > /tmp/release_body.md || true
|
git log --pretty=format:"- %s" > /tmp/release_body.md || true
|
||||||
fi
|
fi
|
||||||
echo "=== Release body preview ==="
|
echo "=== Release body preview ==="
|
||||||
cat /tmp/release_body.md
|
cat /tmp/release_body.md
|
||||||
|
|
||||||
- name: Update Gitea release body
|
- name: Create or update Gitea release
|
||||||
env:
|
env:
|
||||||
RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }}
|
RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }}
|
||||||
RELEASE_TAG: ${{ needs.autotag.outputs.release_tag }}
|
RELEASE_TAG: ${{ needs.autotag.outputs.release_tag }}
|
||||||
@ -148,18 +154,41 @@ jobs:
|
|||||||
set -eu
|
set -eu
|
||||||
TAG="${RELEASE_TAG}"
|
TAG="${RELEASE_TAG}"
|
||||||
API="http://172.0.0.29:3000/api/v1/repos/$GITHUB_REPOSITORY"
|
API="http://172.0.0.29:3000/api/v1/repos/$GITHUB_REPOSITORY"
|
||||||
RELEASE_ID=$(curl -sf "$API/releases/tags/$TAG" \
|
|
||||||
-H "Authorization: token $RELEASE_TOKEN" | jq -r '.id')
|
# Try to find an existing release for this tag
|
||||||
|
RELEASE_ID=$(curl -s "$API/releases/tags/$TAG" \
|
||||||
|
-H "Authorization: token $RELEASE_TOKEN" | jq -r '.id // empty')
|
||||||
|
|
||||||
|
if [ -z "$RELEASE_ID" ]; then
|
||||||
|
# First run: changelog job owns release creation so build jobs
|
||||||
|
# never race against a missing release object
|
||||||
|
echo "Creating release $TAG..."
|
||||||
|
RELEASE_ID=$(jq -n \
|
||||||
|
--arg tag "$TAG" \
|
||||||
|
--arg name "TFTSR $TAG" \
|
||||||
|
--rawfile body /tmp/release_body.md \
|
||||||
|
'{tag_name: $tag, name: $name, body: $body, draft: false}' \
|
||||||
|
| curl -sf -X POST "$API/releases" \
|
||||||
|
-H "Authorization: token $RELEASE_TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
--data @- \
|
||||||
|
| jq -r '.id')
|
||||||
|
echo "✓ Release created (id=$RELEASE_ID)"
|
||||||
|
else
|
||||||
|
# Re-run: patch the body only
|
||||||
|
echo "Updating existing release $TAG (id=$RELEASE_ID)..."
|
||||||
|
jq -n --rawfile body /tmp/release_body.md '{body: $body}' \
|
||||||
|
| curl -sf -X PATCH "$API/releases/$RELEASE_ID" \
|
||||||
|
-H "Authorization: token $RELEASE_TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
--data @-
|
||||||
|
echo "✓ Release body updated"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -z "$RELEASE_ID" ] || [ "$RELEASE_ID" = "null" ]; then
|
if [ -z "$RELEASE_ID" ] || [ "$RELEASE_ID" = "null" ]; then
|
||||||
echo "ERROR: Could not find release for tag $TAG"
|
echo "ERROR: Failed to create or locate release for $TAG"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
BODY=$(jq -n --rawfile note /tmp/release_body.md '{body: $note}')
|
|
||||||
curl -sf -X PATCH "$API/releases/$RELEASE_ID" \
|
|
||||||
-H "Authorization: token $RELEASE_TOKEN" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d "$BODY"
|
|
||||||
echo "✓ Release body updated"
|
|
||||||
|
|
||||||
- name: Commit CHANGELOG.md to master
|
- name: Commit CHANGELOG.md to master
|
||||||
env:
|
env:
|
||||||
@ -167,14 +196,21 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
TAG="${RELEASE_TAG}"
|
TAG="${RELEASE_TAG}"
|
||||||
# Validate tag format to prevent shell injection in commit message / JSON
|
|
||||||
if ! echo "$TAG" | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+$'; then
|
if ! echo "$TAG" | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+$'; then
|
||||||
echo "ERROR: Unexpected tag format: $TAG"
|
echo "ERROR: Unexpected tag format: $TAG"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
git add CHANGELOG.md
|
git add CHANGELOG.md
|
||||||
git commit -m "chore: update CHANGELOG.md for ${TAG} [skip ci]" || echo "No changes to commit"
|
# Only commit if CHANGELOG.md actually changed — avoids ambiguous
|
||||||
git push origin master
|
# exit-code handling from 'git commit || echo' with set -e
|
||||||
|
if git diff --staged --quiet; then
|
||||||
|
echo "No CHANGELOG.md changes to commit"
|
||||||
|
else
|
||||||
|
git commit -m "chore: update CHANGELOG.md for ${TAG} [skip ci]"
|
||||||
|
fi
|
||||||
|
# HEAD:master works in detached HEAD state; 'git push origin master'
|
||||||
|
# would fail because there is no local branch named master
|
||||||
|
git push origin HEAD:master
|
||||||
echo "✓ CHANGELOG.md committed to master"
|
echo "✓ CHANGELOG.md committed to master"
|
||||||
|
|
||||||
- name: Upload CHANGELOG.md as release asset
|
- name: Upload CHANGELOG.md as release asset
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user