-
Notifications
You must be signed in to change notification settings - Fork 0
145 lines (126 loc) · 4.15 KB
/
Copy pathrelease.yml
File metadata and controls
145 lines (126 loc) · 4.15 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
name: Build & Release
# 发版机制参考 forks(ci-release 主题知识):tag 驱动,版本语义由 tag 唯一定义。
# 与 forks 的差异:byte-code 前端非 Go embed(静态服务读 resource/public),
# 因此前端只构建一次、五平台 matrix 仅做 Go 交叉编译与组包(forks 每平台重复编前端)。
on:
push:
tags: ['v*']
workflow_dispatch:
inputs:
tag:
description: '要发布的 tag(v 前缀),如 v0.1.0'
required: true
jobs:
# 前端构建一次,产物经 artifact 供各平台组包
frontend:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: pnpm/action-setup@v4
with:
version: 10
- uses: actions/setup-node@v6
with:
node-version: 22
cache: pnpm
cache-dependency-path: web/pnpm-lock.yaml
- name: Build frontend
run: |
cd web
pnpm install --frozen-lockfile
pnpm run build
- name: Upload dist
uses: actions/upload-artifact@v4
with:
name: frontend-dist
path: web/dist/
build:
needs: frontend
runs-on: ubuntu-latest
permissions:
contents: write
strategy:
matrix:
include:
- goos: linux
goarch: amd64
- goos: linux
goarch: arm64
- goos: windows
goarch: amd64
- goos: darwin
goarch: amd64
- goos: darwin
goarch: arm64
steps:
- uses: actions/checkout@v6
- uses: actions/setup-go@v5
with:
go-version: '1.25'
cache: true
- name: Download frontend dist
uses: actions/download-artifact@v4
with:
name: frontend-dist
path: web/dist
- name: Build binary
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 0
run: |
# dispatch 模式 ref 是分支名,版本必须来自入参;tag push 模式取 ref
VERSION=${{ inputs.tag || github.ref_name }}
VERSION=${VERSION#v}
BINARY=bytecode
if [ "$GOOS" = "windows" ]; then
BINARY=bytecode.exe
fi
go build -ldflags="-s -w -X github.com/cicbyte/byte-code/internal/version.Version=$VERSION" -o $BINARY .
# 二进制不自包含(非 embed):resource/(前端产物 + SQL 迁移)与配置样例随包分发
- name: Package
run: |
mkdir -p pkg/resource
cp -r web/dist pkg/resource/public
cp -r resource/sql pkg/resource/sql
cp manifest/config/config.yaml pkg/config.example.yaml
cp ${{ matrix.goos == 'windows' && 'bytecode.exe' || 'bytecode' }} pkg/
tar -czf bytecode_${{ matrix.goos }}_${{ matrix.goarch }}.tar.gz -C pkg .
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: bytecode_${{ matrix.goos }}_${{ matrix.goarch }}
path: bytecode_${{ matrix.goos }}_${{ matrix.goarch }}.tar.gz
release:
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
# cliff 生成发版说明需要全历史与 tag
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Generate changelog
uses: orhun/git-cliff-action@v4
id: cliff
with:
config: cliff.toml
args: --latest --strip header
env:
# OUTPUT 设定后 action 把 changelog 写入该文件(多行内容经文件
# 传给 release 更稳;此时 outputs.changelog 是文件路径)
OUTPUT: CHANGELOG.md
GITHUB_REPO: ${{ github.repository }}
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true
- name: Create release
uses: softprops/action-gh-release@v2
with:
# dispatch 模式(ref=master)必须显式指定 tag
tag_name: ${{ inputs.tag || github.ref_name }}
files: artifacts/*.tar.gz
body_path: CHANGELOG.md