- Extract complete tag message body in workflow using git format - Pass tag message via TAG_MESSAGE environment variable - Update goreleaser config to use .Env.TAG_MESSAGE instead of .TagBody - Fix release notes being truncated to first paragraph only
190 lines
5.3 KiB
YAML
190 lines
5.3 KiB
YAML
name: Release
|
||
|
||
on:
|
||
push:
|
||
tags:
|
||
- 'v*'
|
||
|
||
permissions:
|
||
contents: write
|
||
packages: write
|
||
|
||
jobs:
|
||
# Update VERSION file with tag version
|
||
update-version:
|
||
runs-on: ubuntu-latest
|
||
steps:
|
||
- name: Checkout
|
||
uses: actions/checkout@v4
|
||
|
||
- name: Update VERSION file
|
||
run: |
|
||
VERSION=${GITHUB_REF#refs/tags/v}
|
||
echo "$VERSION" > backend/cmd/server/VERSION
|
||
echo "Updated VERSION file to: $VERSION"
|
||
|
||
- name: Upload VERSION artifact
|
||
uses: actions/upload-artifact@v4
|
||
with:
|
||
name: version-file
|
||
path: backend/cmd/server/VERSION
|
||
retention-days: 1
|
||
|
||
build-frontend:
|
||
runs-on: ubuntu-latest
|
||
steps:
|
||
- name: Checkout
|
||
uses: actions/checkout@v4
|
||
|
||
- name: Setup Node.js
|
||
uses: actions/setup-node@v4
|
||
with:
|
||
node-version: '20'
|
||
cache: 'npm'
|
||
cache-dependency-path: frontend/package-lock.json
|
||
|
||
- name: Install dependencies
|
||
run: npm ci
|
||
working-directory: frontend
|
||
|
||
- name: Build frontend
|
||
run: npm run build
|
||
working-directory: frontend
|
||
|
||
- name: Upload frontend artifact
|
||
uses: actions/upload-artifact@v4
|
||
with:
|
||
name: frontend-dist
|
||
path: backend/internal/web/dist/
|
||
retention-days: 1
|
||
|
||
release:
|
||
needs: [update-version, build-frontend]
|
||
runs-on: ubuntu-latest
|
||
steps:
|
||
- name: Checkout
|
||
uses: actions/checkout@v4
|
||
with:
|
||
fetch-depth: 0
|
||
|
||
- name: Download VERSION artifact
|
||
uses: actions/download-artifact@v4
|
||
with:
|
||
name: version-file
|
||
path: backend/cmd/server/
|
||
|
||
- name: Download frontend artifact
|
||
uses: actions/download-artifact@v4
|
||
with:
|
||
name: frontend-dist
|
||
path: backend/internal/web/dist/
|
||
|
||
- name: Setup Go
|
||
uses: actions/setup-go@v5
|
||
with:
|
||
go-version: '1.24'
|
||
cache-dependency-path: backend/go.sum
|
||
|
||
- name: Get tag message
|
||
id: tag_message
|
||
run: |
|
||
# 获取完整的 tag message(跳过第一行标题)
|
||
TAG_MESSAGE=$(git tag -l --format='%(contents:body)' ${GITHUB_REF#refs/tags/})
|
||
# 使用 EOF 分隔符处理多行内容
|
||
echo "message<<EOF" >> $GITHUB_OUTPUT
|
||
echo "$TAG_MESSAGE" >> $GITHUB_OUTPUT
|
||
echo "EOF" >> $GITHUB_OUTPUT
|
||
|
||
- name: Run GoReleaser
|
||
uses: goreleaser/goreleaser-action@v6
|
||
with:
|
||
version: '~> v2'
|
||
args: release --clean --skip=validate
|
||
env:
|
||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||
TAG_MESSAGE: ${{ steps.tag_message.outputs.message }}
|
||
|
||
# ===========================================================================
|
||
# Docker Build and Push
|
||
# ===========================================================================
|
||
docker:
|
||
needs: [update-version, build-frontend]
|
||
runs-on: ubuntu-latest
|
||
steps:
|
||
- name: Checkout
|
||
uses: actions/checkout@v4
|
||
|
||
- name: Download VERSION artifact
|
||
uses: actions/download-artifact@v4
|
||
with:
|
||
name: version-file
|
||
path: backend/cmd/server/
|
||
|
||
- name: Download frontend artifact
|
||
uses: actions/download-artifact@v4
|
||
with:
|
||
name: frontend-dist
|
||
path: backend/internal/web/dist/
|
||
|
||
# Extract version from tag
|
||
- name: Extract version
|
||
id: version
|
||
run: |
|
||
VERSION=${GITHUB_REF#refs/tags/v}
|
||
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
||
echo "Version: $VERSION"
|
||
|
||
# Set up Docker Buildx for multi-platform builds
|
||
- name: Set up QEMU
|
||
uses: docker/setup-qemu-action@v3
|
||
|
||
- name: Set up Docker Buildx
|
||
uses: docker/setup-buildx-action@v3
|
||
|
||
# Login to DockerHub
|
||
- name: Login to DockerHub
|
||
uses: docker/login-action@v3
|
||
with:
|
||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||
|
||
# Extract metadata for Docker
|
||
- name: Extract Docker metadata
|
||
id: meta
|
||
uses: docker/metadata-action@v5
|
||
with:
|
||
images: |
|
||
weishaw/sub2api
|
||
tags: |
|
||
type=semver,pattern={{version}}
|
||
type=semver,pattern={{major}}.{{minor}}
|
||
type=semver,pattern={{major}}
|
||
type=raw,value=latest,enable={{is_default_branch}}
|
||
|
||
# Build and push Docker image
|
||
- name: Build and push Docker image
|
||
uses: docker/build-push-action@v5
|
||
with:
|
||
context: .
|
||
file: ./Dockerfile
|
||
platforms: linux/amd64,linux/arm64
|
||
push: true
|
||
tags: ${{ steps.meta.outputs.tags }}
|
||
labels: ${{ steps.meta.outputs.labels }}
|
||
build-args: |
|
||
VERSION=${{ steps.version.outputs.version }}
|
||
COMMIT=${{ github.sha }}
|
||
DATE=${{ github.event.head_commit.timestamp }}
|
||
cache-from: type=gha
|
||
cache-to: type=gha,mode=max
|
||
|
||
# Update DockerHub description (optional)
|
||
- name: Update DockerHub description
|
||
uses: peter-evans/dockerhub-description@v4
|
||
with:
|
||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||
repository: weishaw/sub2api
|
||
short-description: "Sub2API - AI API Gateway Platform"
|
||
readme-filepath: ./deploy/DOCKER.md
|