From 7e5b878a9c49a6395cd67c35d9bb68551cbb4d7e Mon Sep 17 00:00:00 2001 From: "Z.To" Date: Sat, 11 Apr 2026 02:24:44 +0800 Subject: [PATCH] chore: add release workflow with auto changelog --- .gitea/workflows/release.yaml | 38 ++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/.gitea/workflows/release.yaml b/.gitea/workflows/release.yaml index f808dcf..b82e417 100644 --- a/.gitea/workflows/release.yaml +++ b/.gitea/workflows/release.yaml @@ -11,30 +11,38 @@ jobs: container: image: hub.gaomia.site/titor/bun:latest steps: + - name: Install git + run: apt-get update && apt-get install -y git + - name: Checkout run: | git clone https://${{ secrets.release_token }}@hub.gaomia.site/titor/mio.git /workspace/mio cd /workspace/mio - cp -r /workspace/mio/* /workspace/ || true - cp -r /workspace/mio/.* /workspace/ 2>/dev/null || true - - name: Install dependencies + - name: Create source archive run: | - cd /workspace - bun install - - - name: Build - run: | - cd /workspace - bun run build + git archive --format=zip -o mio-source.zip HEAD - name: Release env: GITEA_TOKEN: ${{ secrets.release_token }} run: | + cd /workspace/mio TAG_NAME="${GITHUB_REF#refs/tags/}" - RELEASE_BODY=$(git tag -l --format='%(contents)' "$TAG_NAME" 2>/dev/null || echo "Release $TAG_NAME") + PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "") + + if [ -n "$PREV_TAG" ]; then + CHANGES=$(git log --pretty=format:"- %s (%h)" "$PREV_TAG..HEAD" 2>/dev/null || echo "") + else + CHANGES=$(git log --pretty=format:"- %s (%h)" -n 20 2>/dev/null || echo "") + fi + + if [ -n "$CHANGES" ]; then + RELEASE_BODY="## Changes\n\n$CHANGES" + else + RELEASE_BODY="Release $TAG_NAME" + fi RELEASE_RESPONSE=$(curl -s -X POST "https://hub.gaomia.site/api/v1/repos/titor/mio/releases" \ -H "Authorization: token ${GITEA_TOKEN}" \ @@ -43,8 +51,6 @@ jobs: RELEASE_ID=$(echo "$RELEASE_RESPONSE" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2) - for f in mio.exe; do - [ -f "$f" ] && curl -s -X POST "https://hub.gaomia.site/api/v1/repos/titor/mio/releases/${RELEASE_ID}/assets" \ - -H "Authorization: token ${GITEA_TOKEN}" \ - -F "attachment=@$f" - done \ No newline at end of file + curl -s -X POST "https://hub.gaomia.site/api/v1/repos/titor/mio/releases/${RELEASE_ID}/assets" \ + -H "Authorization: token ${GITEA_TOKEN}" \ + -F "attachment=@mio-source.zip" \ No newline at end of file