Files
mio/.gitea/workflows/release.yaml
Z.To 7e5b878a9c
Some checks failed
Release / build (push) Failing after 2m24s
chore: add release workflow with auto changelog
2026-04-11 02:24:44 +08:00

56 lines
1.8 KiB
YAML

name: Release
on:
push:
tags:
- 'v*'
jobs:
build:
runs-on: ubuntu-latest
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
- name: Create source archive
run: |
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/}"
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}" \
-H "Content-Type: application/json" \
-d "{\"tag_name\":\"${TAG_NAME}\",\"name\":\"${TAG_NAME}\",\"body\":\"${RELEASE_BODY}\"}")
RELEASE_ID=$(echo "$RELEASE_RESPONSE" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
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"