92 lines
3.0 KiB
YAML
92 lines
3.0 KiB
YAML
name: Release
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
tags:
|
|
- 'v*'
|
|
|
|
permissions:
|
|
contents: write
|
|
|
|
jobs:
|
|
build:
|
|
name: Build & Release
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Determine Version Tag & Generate Notes
|
|
id: versioning
|
|
run: |
|
|
PREV_TAG=$(git tag -l "v*" --sort=-v:refname | head -n1)
|
|
if [ -z "$PREV_TAG" ]; then
|
|
PREV_TAG=""
|
|
fi
|
|
|
|
if [[ "${{ github.ref }}" == refs/tags/v* ]]; then
|
|
TAG="${GITHUB_REF#refs/tags/}"
|
|
else
|
|
if [ -z "$PREV_TAG" ]; then
|
|
TAG="v1.0.0"
|
|
else
|
|
VER_NUM="${PREV_TAG#v}"
|
|
IFS='.' read -r MAJOR MINOR PATCH <<< "$VER_NUM"
|
|
PATCH=$((PATCH + 1))
|
|
TAG="v${MAJOR}.${MINOR}.${PATCH}"
|
|
fi
|
|
echo "Auto incremented patch version to $TAG"
|
|
|
|
git config user.name "github-actions[bot]"
|
|
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
git tag "$TAG"
|
|
git push origin "$TAG"
|
|
fi
|
|
echo "tag=$TAG" >> $GITHUB_OUTPUT
|
|
|
|
# 生成有意义的变更日志内容
|
|
echo "### 🚀 What's Changed in ${TAG}" > release_notes.md
|
|
echo "" >> release_notes.md
|
|
if [ -n "$PREV_TAG" ]; then
|
|
git log "${PREV_TAG}..HEAD" --pretty=format:"- %s (%h by @%an)" >> release_notes.md
|
|
else
|
|
git log -n 10 --pretty=format:"- %s (%h by @%an)" >> release_notes.md
|
|
fi
|
|
echo "" >> release_notes.md
|
|
echo "" >> release_notes.md
|
|
echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/${PREV_TAG}...${TAG}" >> release_notes.md
|
|
cat release_notes.md
|
|
|
|
- name: Set up Go
|
|
uses: actions/setup-go@v5
|
|
with:
|
|
go-version: '1.22'
|
|
|
|
- name: Build Hub & Agent
|
|
run: |
|
|
mkdir -p dist
|
|
# Linux AMD64
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-s -w" -o dist/vps-commander-hub-linux-amd64 ./cmd/hub
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-s -w" -o dist/vps-commander-agent-linux-amd64 ./cmd/agent
|
|
|
|
# Linux ARM64
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -trimpath -ldflags "-s -w" -o dist/vps-commander-hub-linux-arm64 ./cmd/hub
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -trimpath -ldflags "-s -w" -o dist/vps-commander-agent-linux-arm64 ./cmd/agent
|
|
|
|
# Checksums
|
|
cd dist
|
|
sha256sum * > checksums.txt
|
|
cd ..
|
|
|
|
- name: Create GitHub Release
|
|
uses: softprops/action-gh-release@v2
|
|
with:
|
|
tag_name: ${{ steps.versioning.outputs.tag }}
|
|
name: Release ${{ steps.versioning.outputs.tag }}
|
|
body_path: release_notes.md
|
|
files: |
|
|
dist/* |