CI: create a tagged Gitea release after every prod deployment
Tag v<yyyy.mm.dd>-<hash>, body lists the commits since the previous release; skipped when the release already exists (redeploy). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -135,3 +135,27 @@ jobs:
|
||||
(grep -q '^TAG=' .env && sed -i 's/^TAG=.*/TAG=$tag/' .env || echo 'TAG=$tag' >> .env) && \
|
||||
docker compose pull -q && docker compose up -d --remove-orphans --wait && \
|
||||
docker image prune -f >/dev/null"
|
||||
# A release (and its tag, e.g. v2026.11.17-163612e) for every deployment,
|
||||
# listing the commits since the previous one.
|
||||
- name: Release
|
||||
env:
|
||||
TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
API: ${{ github.server_url }}/api/v1/repos/${{ github.repository }}
|
||||
run: |
|
||||
set -eu
|
||||
apk add --no-cache -q curl jq
|
||||
git fetch -q --unshallow --tags origin
|
||||
short=$(echo "${{ github.sha }}" | cut -c1-7)
|
||||
name="v$(date -u +%Y.%m.%d)-$short"
|
||||
if curl -fsS -o /dev/null -H "Authorization: token $TOKEN" "$API/releases/tags/$name" 2>/dev/null; then
|
||||
echo "release $name already exists (redeploy)"; exit 0
|
||||
fi
|
||||
prev=$(git describe --tags --abbrev=0 --match 'v*' HEAD 2>/dev/null || true)
|
||||
if [ -n "$prev" ]; then range="$prev..HEAD"; since="since $prev"; else range="-20 HEAD"; since="(last 20 commits)"; fi
|
||||
changes=$(git log --no-merges --pretty='- %s (%h)' $range)
|
||||
body=$(printf 'Deployed to production on %s UTC.\nImages: `registry.sagifer.com/sagifer/sorsfonalak-*:%s`\n\nChanges %s:\n%s\n' \
|
||||
"$(date -u '+%Y-%m-%d %H:%M')" "$(echo "${{ github.sha }}" | cut -c1-12)" "$since" "$changes")
|
||||
jq -n --arg tag "$name" --arg sha "${{ github.sha }}" --arg body "$body" \
|
||||
'{tag_name: $tag, target_commitish: $sha, name: $tag, body: $body}' \
|
||||
| curl -fsS -X POST -H "Authorization: token $TOKEN" -H 'Content-Type: application/json' -d @- "$API/releases" \
|
||||
| jq -r '"created release " + .name + ": " + .html_url'
|
||||
|
||||
Reference in New Issue
Block a user