Skip to content

Merge upstream changes (v7.2.113) with local modifications #257

Merge upstream changes (v7.2.113) with local modifications

Merge upstream changes (v7.2.113) with local modifications #257

Workflow file for this run

name: Build and Release
on:
push:
tags:
- 'fork/v*'
workflow_dispatch:
inputs:
tag:
description: '手动指定版本标签(例如: fork/v7.42.0)'
required: true
permissions:
contents: write
env:
GO_VERSION: '1.26'
jobs:
prepare-panel:
name: Prepare latest management panel
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Sync latest verified management panel
run: bash .github/scripts/sync-management-panel.sh
- name: Upload management panel assets
uses: actions/upload-artifact@v4
with:
name: management-panel-assets
path: |
internal/managementasset/assets/management.html.gz
internal/managementasset/assets/panel-manifest.json
if-no-files-found: error
retention-days: 1
build:
name: Build ${{ matrix.target }}
needs: prepare-panel
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- target: darwin-amd64
goos: darwin
goarch: amd64
output: cli-proxy-api-darwin-amd64
- target: darwin-arm64
goos: darwin
goarch: arm64
output: cli-proxy-api-darwin-arm64
- target: linux-amd64
goos: linux
goarch: amd64
output: cli-proxy-api-linux-amd64
- target: linux-arm64
goos: linux
goarch: arm64
output: cli-proxy-api-linux-arm64
- target: windows-amd64
goos: windows
goarch: amd64
output: cli-proxy-api-windows-amd64.exe
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Fetch tags
run: git fetch --force --tags
- name: Checkout dispatch tag
if: ${{ github.event_name == 'workflow_dispatch' }}
env:
RELEASE_TAG: ${{ github.event.inputs.tag }}
run: |
set -euo pipefail
case "$RELEASE_TAG" in
fork/v*) ;;
*) echo "release tag must match fork/v*" >&2; exit 1 ;;
esac
git checkout --detach "$RELEASE_TAG"
- name: Download management panel assets
uses: actions/download-artifact@v4
with:
name: management-panel-assets
path: internal/managementasset/assets
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Refresh models catalog
run: bash .github/scripts/refresh-model-catalogs.sh
- name: Generate build metadata
id: metadata
env:
DISPATCH_TAG: ${{ github.event.inputs.tag }}
run: |
set -euo pipefail
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
tag="$DISPATCH_TAG"
else
tag="${GITHUB_REF#refs/tags/}"
fi
case "$tag" in
fork/v*) ;;
*) echo "release tag must match fork/v*" >&2; exit 1 ;;
esac
{
echo "tag=$tag"
echo "version=${tag#fork/}"
echo "commit=$(git rev-parse --short HEAD)"
echo "build_date=$(date -u +%Y-%m-%dT%H:%M:%SZ)"
} >> "$GITHUB_OUTPUT"
- name: Build binary
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
OUTPUT: ${{ matrix.output }}
RELEASE_VERSION: ${{ steps.metadata.outputs.version }}
COMMIT: ${{ steps.metadata.outputs.commit }}
BUILD_DATE: ${{ steps.metadata.outputs.build_date }}
run: |
set -euo pipefail
rm -rf "dist/${GOOS}-${GOARCH}"
mkdir -p dist
CGO_ENABLED=0 GOOS="$GOOS" GOARCH="$GOARCH" go build \
-buildvcs=false \
-trimpath \
-ldflags="-s -w -X main.Version=${RELEASE_VERSION} -X main.Commit=${COMMIT} -X main.BuildDate=${BUILD_DATE}" \
-o "dist/$OUTPUT" ./cmd/server/
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.target }}
path: dist/${{ matrix.output }}
if-no-files-found: error
retention-days: 1
release:
name: Create GitHub Release
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Fetch tags
run: git fetch --force --tags
- name: Resolve release tag
id: metadata
env:
DISPATCH_TAG: ${{ github.event.inputs.tag }}
run: |
set -euo pipefail
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
tag="$DISPATCH_TAG"
else
tag="${GITHUB_REF#refs/tags/}"
fi
case "$tag" in
fork/v*) ;;
*) echo "release tag must match fork/v*" >&2; exit 1 ;;
esac
git checkout --detach "$tag"
{
echo "tag=$tag"
echo "version=${tag#fork/}"
} >> "$GITHUB_OUTPUT"
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: dist
merge-multiple: true
- name: Create checksums
working-directory: dist
run: |
set -euo pipefail
shopt -s nullglob
files=(cli-proxy-api-*)
if [ "${#files[@]}" -eq 0 ]; then
echo "No release binaries found" >&2
exit 1
fi
sha256sum "${files[@]}" | sort -k2 > checksums.txt
cat checksums.txt
- name: Generate release notes
env:
RELEASE_TAG: ${{ steps.metadata.outputs.tag }}
run: |
set -euo pipefail
prev_tag="$(git describe --tags --abbrev=0 "${RELEASE_TAG}^" 2>/dev/null || true)"
{
echo "## What's Changed"
echo
} > release_notes.md
if [ -n "$prev_tag" ]; then
git log "${prev_tag}..${RELEASE_TAG}" --pretty=format:"%h|%s" > commits.txt
features="$(grep -E '^[a-f0-9]+\|feat(\(.+\))?:' commits.txt || true)"
fixes="$(grep -E '^[a-f0-9]+\|fix(\(.+\))?:' commits.txt || true)"
refactors="$(grep -E '^[a-f0-9]+\|refactor(\(.+\))?:' commits.txt || true)"
others="$(grep -vE '^[a-f0-9]+\|(feat|fix|refactor|docs|test|ci|chore)(\(.+\))?:' commits.txt || true)"
if [ -n "$features" ]; then
echo "### Features" >> release_notes.md
echo "$features" | while IFS='|' read -r hash msg; do
echo "- $msg (\`$hash\`)" >> release_notes.md
done
echo >> release_notes.md
fi
if [ -n "$fixes" ]; then
echo "### Bug Fixes" >> release_notes.md
echo "$fixes" | while IFS='|' read -r hash msg; do
echo "- $msg (\`$hash\`)" >> release_notes.md
done
echo >> release_notes.md
fi
if [ -n "$refactors" ]; then
echo "### Refactors" >> release_notes.md
echo "$refactors" | while IFS='|' read -r hash msg; do
echo "- $msg (\`$hash\`)" >> release_notes.md
done
echo >> release_notes.md
fi
if [ -n "$others" ]; then
echo "### Other Changes" >> release_notes.md
echo "$others" | while IFS='|' read -r hash msg; do
echo "- $msg (\`$hash\`)" >> release_notes.md
done
echo >> release_notes.md
fi
else
echo "Initial release." >> release_notes.md
echo >> release_notes.md
fi
cat >> release_notes.md <<'NOTESEOF'
---
## Download
| Platform | Arch | File |
|----------|------|------|
| macOS | Intel | `cli-proxy-api-darwin-amd64` |
| macOS | Apple Silicon | `cli-proxy-api-darwin-arm64` |
| Linux | x86_64 | `cli-proxy-api-linux-amd64` |
| Linux | ARM64 | `cli-proxy-api-linux-arm64` |
| Windows | x86_64 | `cli-proxy-api-windows-amd64.exe` |
**Checksum**: See `checksums.txt` in release assets.
## Verify
```bash
sha256sum -c checksums.txt
```
NOTESEOF
- name: Create Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.metadata.outputs.tag }}
name: Release ${{ steps.metadata.outputs.tag }}
draft: false
prerelease: false
generate_release_notes: false
body_path: release_notes.md
files: |
dist/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}