Skip to content

Commit cfb0d27

Browse files
committed
build: 增加二进制build构建
1 parent 4714c94 commit cfb0d27

4 files changed

Lines changed: 135 additions & 4 deletions

File tree

.github/workflows/docker-beta.yml

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ name: Docker CI (beta)
22

33
on:
44
push:
5-
# branches:
6-
# - "*-beta"
5+
branches:
6+
- "*-beta" # 启用分支推送触发,但会检查是否有 tag
77
tags:
88
- "v*.*.*.beta*"
99
- "v*.*.*-beta*"
@@ -17,6 +17,8 @@ jobs:
1717
steps:
1818
- name: Checkout
1919
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0 # 获取完整的 git 历史,包括 tags
2022

2123
- name: Set up QEMU
2224
uses: docker/setup-qemu-action@v3
@@ -34,12 +36,35 @@ jobs:
3436
- name: Extract version
3537
id: vars
3638
run: |
39+
# 检查当前 commit 是否有 beta tag
40+
CURRENT_TAG=$(git tag --points-at HEAD | grep -E '^v.*\.beta.*$' | head -1)
41+
3742
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
38-
VERSION=${GITHUB_REF#refs/tags/}
43+
# 直接由 tag 触发
44+
RAW_VERSION=${GITHUB_REF#refs/tags/}
45+
elif [[ -n "$CURRENT_TAG" ]]; then
46+
# 分支推送但当前 commit 有 beta tag
47+
RAW_VERSION=$CURRENT_TAG
3948
else
49+
# 普通分支推送,使用 commit hash
4050
VERSION=${GITHUB_SHA::7}-beta
51+
echo "version=$VERSION" >> $GITHUB_OUTPUT
52+
exit 0
53+
fi
54+
55+
# 格式化版本号:v2.0.0.beta8 -> 2.0.0-beta8
56+
if [[ $RAW_VERSION =~ ^v([0-9]+\.[0-9]+\.[0-9]+)\.beta([0-9]+)$ ]]; then
57+
VERSION="${BASH_REMATCH[1]}-beta${BASH_REMATCH[2]}"
58+
elif [[ $RAW_VERSION =~ ^v([0-9]+\.[0-9]+\.[0-9]+)-beta([0-9]+)$ ]]; then
59+
VERSION="${BASH_REMATCH[1]}-beta${BASH_REMATCH[2]}"
60+
else
61+
# 如果格式不匹配,直接去掉 v 前缀
62+
VERSION=${RAW_VERSION#v}
63+
VERSION=${VERSION/.beta/-beta}
4164
fi
65+
4266
echo "version=$VERSION" >> $GITHUB_OUTPUT
67+
echo "raw_version=$RAW_VERSION" >> $GITHUB_OUTPUT
4368
4469
- name: Prepare metadata
4570
id: meta
@@ -62,7 +87,8 @@ jobs:
6287

6388
- name: Output version info
6489
run: |
65-
echo "🏷 Version: ${{ steps.vars.outputs.version }}"
90+
echo "🏷 Raw Version: ${{ steps.vars.outputs.raw_version }}"
91+
echo "🏷 Formatted Version: ${{ steps.vars.outputs.version }}"
6692
echo "📦 Image Tags:"
6793
echo " ghcr.io/${{ steps.meta.outputs.repo }}:${{ steps.vars.outputs.version }}"
6894
echo " ghcr.io/${{ steps.meta.outputs.repo }}:beta"

.github/workflows/release-beta.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Release Beta
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*.*.*.beta*"
7+
- "v*.*.*-beta*"
8+
9+
jobs:
10+
goreleaser:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: write
14+
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Set up Go
22+
uses: actions/setup-go@v5
23+
with:
24+
go-version-file: go.mod
25+
cache: true
26+
27+
- name: Run GoReleaser
28+
uses: goreleaser/goreleaser-action@v6
29+
with:
30+
distribution: goreleaser
31+
version: 'latest'
32+
args: release --clean
33+
env:
34+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*.*.*"
7+
- "!v*.*.*-beta*"
8+
- "!v*.*.*.beta*"
9+
10+
jobs:
11+
goreleaser:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: write
15+
16+
# 过滤掉 beta 标签
17+
if: ${{ !contains(github.ref, 'beta') }}
18+
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Set up Go
26+
uses: actions/setup-go@v5
27+
with:
28+
go-version-file: go.mod
29+
cache: true
30+
31+
- name: Run GoReleaser
32+
uses: goreleaser/goreleaser-action@v6
33+
with:
34+
distribution: goreleaser
35+
version: 'latest'
36+
args: release --clean
37+
env:
38+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.goreleaser.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
version: 2
2+
3+
builds:
4+
- env:
5+
- CGO_ENABLED=0
6+
main: ./cmd/server
7+
binary: nodepassdash
8+
goos:
9+
- darwin
10+
- linux
11+
- windows
12+
goarch:
13+
- amd64
14+
- arm64 # armv8 (64位)
15+
- arm # armv6/armv7 (32位)
16+
goarm: # ARM 版本 (仅对 GOARCH=arm 有效)
17+
- 6 # armv6 (树莓派 1)
18+
- 7 # armv7 (树莓派 2/3/4 32位系统)
19+
flags:
20+
- -trimpath
21+
ldflags:
22+
- -s -w -X main.Version={{ .Tag }}
23+
tags:
24+
- sqlite_omit_load_extension
25+
26+
archives:
27+
- format: tar.gz
28+
format_overrides:
29+
- goos: windows
30+
format: zip
31+
32+
release:
33+
prerelease: auto

0 commit comments

Comments
 (0)