1+ name : Release
2+
3+ on :
4+ push :
5+ tags :
6+ - ' v*'
7+
8+ jobs :
9+ build :
10+ name : Build and Release
11+ runs-on : ubuntu-latest
12+ strategy :
13+ matrix :
14+ include :
15+ # Linux
16+ - goos : linux
17+ goarch : amd64
18+ filename : webhookGo-linux-amd64
19+ - goos : linux
20+ goarch : arm64
21+ filename : webhookGo-linux-arm64
22+ - goos : linux
23+ goarch : 386
24+ filename : webhookGo-linux-386
25+ - goos : linux
26+ goarch : arm
27+ goarm : 7
28+ filename : webhookGo-linux-armv7
29+ # Windows
30+ - goos : windows
31+ goarch : amd64
32+ filename : webhookGo-windows-amd64.exe
33+ - goos : windows
34+ goarch : 386
35+ filename : webhookGo-windows-386.exe
36+ # macOS
37+ - goos : darwin
38+ goarch : amd64
39+ filename : webhookGo-darwin-amd64
40+ - goos : darwin
41+ goarch : arm64
42+ filename : webhookGo-darwin-arm64
43+ # FreeBSD
44+ - goos : freebsd
45+ goarch : amd64
46+ filename : webhookGo-freebsd-amd64
47+
48+ steps :
49+ - name : Checkout code
50+ uses : actions/checkout@v4
51+
52+ - name : Set up Go
53+ uses : actions/setup-go@v5
54+ with :
55+ go-version : ' 1.24.6'
56+
57+ - name : Cache Go modules
58+ uses : actions/cache@v4
59+ with :
60+ path : ~/go/pkg/mod
61+ key : ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
62+ restore-keys : |
63+ ${{ runner.os }}-go-
64+
65+ - name : Download dependencies
66+ run : go mod download
67+
68+ - name : Build
69+ env :
70+ GOOS : ${{ matrix.goos }}
71+ GOARCH : ${{ matrix.goarch }}
72+ GOARM : ${{ matrix.goarm }}
73+ CGO_ENABLED : 0
74+ run : |
75+ mkdir -p dist
76+ output_name="${{ matrix.filename }}"
77+ go build -ldflags="-s -w -X main.version=${{ github.ref_name }}" -o "dist/${output_name}" .
78+
79+ - name : Create archive
80+ run : |
81+ cd dist
82+ if [ "${{ matrix.goos }}" = "windows" ]; then
83+ zip "../${{ matrix.filename }}.zip" *
84+ else
85+ tar -czf "../${{ matrix.filename }}.tar.gz" *
86+ fi
87+
88+ - name : Upload artifacts
89+ uses : actions/upload-artifact@v4
90+ with :
91+ name : ${{ matrix.filename }}
92+ path : |
93+ ${{ matrix.filename }}.*
94+ retention-days : 30
95+
96+ release :
97+ name : Create Release
98+ needs : build
99+ runs-on : ubuntu-latest
100+ if : startsWith(github.ref, 'refs/tags/')
101+
102+ steps :
103+ - name : Checkout code
104+ uses : actions/checkout@v4
105+
106+ - name : Download all artifacts
107+ uses : actions/download-artifact@v4
108+ with :
109+ path : artifacts
110+
111+ - name : Prepare release assets
112+ run : |
113+ mkdir -p release-assets
114+ find artifacts -name "*.zip" -o -name "*.tar.gz" | while read file; do
115+ cp "$file" "release-assets/"
116+ done
117+ ls -la release-assets/
118+
119+ - name : Generate changelog
120+ id : changelog
121+ run : |
122+ # 获取上一个tag
123+ PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
124+ if [ -n "$PREVIOUS_TAG" ]; then
125+ echo "## 更新内容" > CHANGELOG.md
126+ echo "" >> CHANGELOG.md
127+ git log --pretty=format:"- %s (%h)" $PREVIOUS_TAG..HEAD >> CHANGELOG.md
128+ else
129+ echo "## 首次发布" > CHANGELOG.md
130+ echo "" >> CHANGELOG.md
131+ git log --pretty=format:"- %s (%h)" >> CHANGELOG.md
132+ fi
133+ echo "changelog<<EOF" >> $GITHUB_OUTPUT
134+ cat CHANGELOG.md >> $GITHUB_OUTPUT
135+ echo "EOF" >> $GITHUB_OUTPUT
136+
137+ - name : Create Release
138+ uses : softprops/action-gh-release@v2
139+ with :
140+ files : release-assets/*
141+ body : |
142+ # 🎉 Release ${{ github.ref_name }}
143+
144+ ${{ steps.changelog.outputs.changelog }}
145+
146+ ## 📦 下载
147+
148+ 选择适合您系统的二进制文件:
149+
150+ | 系统 | 架构 | 文件名 |
151+ |------|------|--------|
152+ | Linux | x86_64 | webhookGo-linux-amd64.tar.gz |
153+ | Linux | ARM64 | webhookGo-linux-arm64.tar.gz |
154+ | Linux | x86 (32位) | webhookGo-linux-386.tar.gz |
155+ | Linux | ARM v7 | webhookGo-linux-armv7.tar.gz |
156+ | Windows | x86_64 | webhookGo-windows-amd64.zip |
157+ | Windows | x86 (32位) | webhookGo-windows-386.zip |
158+ | macOS | x86_64 | webhookGo-darwin-amd64.tar.gz |
159+ | macOS | ARM64 (Apple Silicon) | webhookGo-darwin-arm64.tar.gz |
160+ | FreeBSD | x86_64 | webhookGo-freebsd-amd64.tar.gz |
161+
162+ ## 🚀 使用方法
163+
164+ 1. 下载适合您系统的压缩包
165+ 2. 解压后获得可执行文件
166+ 3. 根据需要配置 `defaultConfig.yml`
167+ 4. 运行 `./webhookGo` (Linux/macOS) 或 `webhookGo.exe` (Windows)
168+
169+ ---
170+
171+ **自动发布于** ${{ github.event.head_commit.timestamp }}
172+ draft : false
173+ prerelease : false
174+ generate_release_notes : false
175+ env :
176+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments