-
Notifications
You must be signed in to change notification settings - Fork 3
187 lines (165 loc) · 6.34 KB
/
Copy pathrelease.yml
File metadata and controls
187 lines (165 loc) · 6.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
name: Release
# 推送 v* 标签:构建发布产物并创建 GitHub Release,供在线升级消费
on:
push:
tags: ["v*"]
permissions:
contents: write
env:
NODE_VERSION: "24.20.0"
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v6
with:
fetch-depth: 0 # 需要完整历史与标签以生成提交历史 Release Note
- name: Extract version from tag
id: ver
run: echo "version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
# Release Note = CHANGELOG.md 中该版本的整理条目 + 自上个标签以来的完整提交记录
- name: Build release notes from CHANGELOG
env:
VERSION: ${{ steps.ver.outputs.version }}
run: |
set -euo pipefail
TAG="${GITHUB_REF_NAME}"
PREV="$(git describe --tags --match 'v*' --abbrev=0 "${TAG}^" 2>/dev/null || true)"
if [ -n "$PREV" ]; then RANGE="${PREV}..${TAG}"; else RANGE="${TAG}"; fi
# 完整提交历史(自上个 v 标签以来的全部非合并提交)
COMMITS="$(git log --no-merges -n 1000 --pretty=format:'- %s (%h)' "$RANGE")"
COUNT="$(printf '%s\n' "$COMMITS" | grep -c '^-' || true)"
# 抽取 CHANGELOG.md 中 `## [<version>]` 到下一个 `## [` 之间的整理条目
NOTES="$(awk -v ver="$VERSION" '
$0 ~ ("^## \\[" ver "\\]") { grab = 1; next }
grab && /^## \[/ { exit }
grab { print }
' CHANGELOG.md)"
STRIPPED="$(printf '%s' "$NOTES" | tr -d '[:space:]')"
{
if [ -n "$STRIPPED" ] && ! printf '%s' "$NOTES" | grep -q '待补充'; then
# 有整理好的 CHANGELOG:正文在前,完整提交记录折叠在后
printf '%s\n' "$NOTES"
echo
echo "---"
echo
echo "<details>"
echo "<summary>完整提交记录(${COUNT} 条)</summary>"
echo
printf '%s\n' "$COMMITS"
echo
echo "</details>"
echo
echo "完整更新日志见 [CHANGELOG.md](CHANGELOG.md)。"
else
# CHANGELOG 缺该版本条目:直接列出完整提交记录
echo "::warning::CHANGELOG.md 缺少 ${VERSION} 的有效条目,Release Note 仅含完整提交记录"
echo "### 变更记录(${COUNT} 条)"
echo
printf '%s\n' "$COMMITS"
fi
} > release-notes.md
echo "----- release-notes.md -----"
cat release-notes.md
# ── 前端 ──
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 9
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: pnpm
cache-dependency-path: app/web/pnpm-lock.yaml
- name: Build web (SSR standalone)
working-directory: app/web
env:
NEXT_DIST_DIR: .next-build
run: |
pnpm install --frozen-lockfile
pnpm exec tsc --noEmit
pnpm test
pnpm build
# ── 单文件(每个架构嵌入匹配的 Node.js + 同一份 Next.js) ──
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: server/go.mod
cache-dependency-path: server/go.sum
- name: Test backend
run: |
deploy/package-web-runtime.sh "$NODE_VERSION" linux amd64 server/internal/webbundle/assets/web-runtime.tar.gz
cd server
go test ./...
- name: Build backend binaries
env:
CGO_ENABLED: "0"
VERSION: ${{ steps.ver.outputs.version }}
run: |
mkdir -p release
LDFLAGS="-s -w \
-X 'knowforge/server/internal/app.Version=${VERSION}' \
-X 'knowforge/server/internal/app.Commit=${GITHUB_SHA::7}' \
-X 'knowforge/server/internal/app.BuildDate=$(date -u +%Y-%m-%dT%H:%M:%SZ)'"
for arch in amd64 arm64; do
deploy/package-web-runtime.sh "$NODE_VERSION" linux "$arch" server/internal/webbundle/assets/web-runtime.tar.gz
GOOS=linux GOARCH=$arch go -C server build -trimpath -ldflags "$LDFLAGS" \
-o ../release/knowforge-server-linux-$arch .
done
- name: Generate checksums
working-directory: release
run: sha256sum knowforge-server-linux-* > SHA256SUMS.txt
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
body_path: release-notes.md
files: |
release/knowforge-server-linux-amd64
release/knowforge-server-linux-arm64
release/SHA256SUMS.txt
# 多架构 Docker 镜像发布到 GitHub Packages(GHCR),随 v* 标签一起发布,供 docker pull 升级
docker:
name: Publish Docker image to GHCR
needs: release
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout source
uses: actions/checkout@v6
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# 由标签推导镜像 tag:完整版本、主.次,以及非预发布时的 latest
- name: Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest,enable=${{ !contains(github.ref_name, '-') }}
- name: Build and push image
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
platforms: linux/amd64,linux/arm64
push: true
build-args: |
NODE_VERSION=${{ env.NODE_VERSION }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max