Skip to content

Commit ef16014

Browse files
shawn-bluceclaude
andcommitted
fix(ci): fix build workflow and add auto-release
- Fix BUILDTAG format in release.yml (use quotes for static flag) - Fix tag push to use force flag to avoid conflicts - Add build.yml workflow for automatic builds on push to master - Auto-create releases with version format: YYYY-MM-DD-commit-hash 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 316d440 commit ef16014

File tree

2 files changed

+133
-3
lines changed

2 files changed

+133
-3
lines changed

.github/workflows/build.yml

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
pull_request:
7+
branches: [ "master" ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
jobs:
15+
- { goos: darwin, goarch: arm64, output: arm64 }
16+
- { goos: darwin, goarch: amd64, output: amd64 }
17+
- { goos: linux, goarch: arm64, output: arm64 }
18+
- { goos: linux, goarch: amd64, output: amd64 }
19+
20+
steps:
21+
-
22+
uses: actions/checkout@v4
23+
24+
-
25+
name: Set up Go
26+
uses: actions/setup-go@v5
27+
with:
28+
go-version: '1.22'
29+
30+
-
31+
name: Set variables
32+
run: |
33+
echo "BUILDTIME=$(date)" >> $GITHUB_ENV
34+
echo "CGO_ENABLED=0" >> $GITHUB_ENV
35+
echo "BUILDHASH=$(git rev-parse HEAD)" >> $GITHUB_ENV
36+
echo "BUILDTAG=-extldflags '-static'" >> $GITHUB_ENV
37+
echo "VERSION=$(date +'%Y-%m-%d')-$(git rev-parse --short HEAD)" >> $GITHUB_ENV
38+
shell: bash
39+
40+
-
41+
name: Test
42+
run: |
43+
go test ./...
44+
45+
-
46+
name: Build
47+
env:
48+
GOOS: ${{matrix.jobs.goos}}
49+
GOARCH: ${{matrix.jobs.goarch}}
50+
run: |
51+
echo $CGO_ENABLED
52+
go build -v -trimpath -ldflags "${BUILDTAG} -X 'eat/cmd/version.BuildHash=${BUILDHASH}' -X 'eat/cmd/version.BuildTime=${BUILDTIME}' -w -s -buildid=" -o eat.out
53+
54+
-
55+
name: Package binary
56+
run: |
57+
if [ "${{matrix.jobs.goos}}" = "windows" ]; then
58+
mv eat.out eat-${{matrix.jobs.goos}}-${{matrix.jobs.output}}.exe
59+
zip -r eat-${{matrix.jobs.goos}}-${{matrix.jobs.output}}-${VERSION}.zip eat-${{matrix.jobs.goos}}-${{matrix.jobs.output}}.exe
60+
else
61+
mv eat.out eat-${{matrix.jobs.goos}}-${{matrix.jobs.output}}
62+
gzip -c eat-${{matrix.jobs.goos}}-${{matrix.jobs.output}} > eat-${{matrix.jobs.goos}}-${{matrix.jobs.output}}-${VERSION}.gz
63+
fi
64+
65+
-
66+
name: Upload artifacts
67+
uses: actions/upload-artifact@v4
68+
with:
69+
name: eat-${{ matrix.jobs.goos }}-${{ matrix.jobs.output }}
70+
path: |
71+
eat*.gz
72+
eat*.zip
73+
74+
create_release:
75+
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
76+
permissions: write-all
77+
needs: [ build ]
78+
runs-on: ubuntu-latest
79+
steps:
80+
-
81+
name: Checkout
82+
uses: actions/checkout@v4
83+
with:
84+
ref: master
85+
fetch-depth: '0'
86+
87+
-
88+
name: Set version
89+
run: |
90+
echo "VERSION=$(date +'%Y-%m-%d')-$(git rev-parse --short HEAD)" >> $GITHUB_ENV
91+
echo "BUILD_TIME=$(date -u +'%Y-%m-%d %H:%M:%S UTC')" >> $GITHUB_ENV
92+
echo "FULL_COMMIT=$(git rev-parse HEAD)" >> $GITHUB_ENV
93+
94+
-
95+
name: Create tag
96+
run: |
97+
git tag -f ${{ env.VERSION }}
98+
git push origin ${{ env.VERSION }} --force
99+
env:
100+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
101+
102+
-
103+
uses: actions/download-artifact@v4
104+
with:
105+
path: dist/
106+
merge-multiple: true
107+
108+
-
109+
name: Display structure of downloaded files
110+
run: ls -R
111+
working-directory: dist/
112+
113+
-
114+
name: Create Release
115+
uses: softprops/action-gh-release@v2
116+
with:
117+
tag_name: ${{ env.VERSION }}
118+
files: dist/*
119+
body: |
120+
## ${{ env.VERSION }}
121+
122+
**构建时间**: ${{ env.BUILD_TIME }}
123+
**Commit**: ${{ env.FULL_COMMIT }}
124+
125+
### 下载说明
126+
127+
- macOS arm64: 适用于 Apple Silicon (M1/M2/M3)
128+
- macOS amd64: 适用于 Intel Mac
129+
- Linux arm64: 适用于 ARM64 Linux 系统
130+
- Linux amd64: 适用于 x86_64 Linux 系统

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ jobs:
8686
echo "BUILDTIME=$(date)" >> $GITHUB_ENV
8787
echo "CGO_ENABLED=0" >> $GITHUB_ENV
8888
echo "BUILDHASH=$(git rev-parse HEAD)" >> $GITHUB_ENV
89-
echo "BUILDTAG=-extldflags --static" >> $GITHUB_ENV
89+
echo "BUILDTAG=-extldflags '-static'" >> $GITHUB_ENV
9090
9191
-
9292
name: Setup NDK
@@ -171,8 +171,8 @@ jobs:
171171
-
172172
name: Tag the commit
173173
run: |
174-
git tag ${{ github.event.inputs.version }}
175-
git push origin ${{ github.event.inputs.version }}
174+
git tag -f ${{ github.event.inputs.version }}
175+
git push origin ${{ github.event.inputs.version }} --force
176176
env:
177177
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
178178

0 commit comments

Comments
 (0)