55 tags :
66 - ' v*' # 只有以 v 开头的 tag 才会触发
77
8+ permissions :
9+ contents : write
10+
811jobs :
912 build :
10- runs-on : windows-latest
13+ runs-on : ${{ matrix.os }}
14+ strategy :
15+ fail-fast : false
16+ matrix :
17+ include :
18+ - os : windows-latest
19+ goos : windows
20+ arch : amd64
21+ ext : " .exe"
22+ archive_ext : " .zip"
23+ - os : ubuntu-latest
24+ goos : linux
25+ arch : amd64
26+ ext : " "
27+ archive_ext : " .tar.gz"
28+ - os : macos-latest
29+ goos : darwin
30+ arch : amd64
31+ ext : " "
32+ archive_ext : " .tar.gz"
1133
1234 steps :
1335 - name : Checkout code
@@ -18,21 +40,71 @@ jobs:
1840 with :
1941 go-version : ' 1.22'
2042
21- - name : Install make
43+ - name : Install zip (Linux)
44+ if : matrix.goos == 'linux'
45+ run : sudo apt-get update && sudo apt-get install -y zip
46+ shell : bash
47+
48+ - name : Install make (Windows)
49+ if : matrix.goos == 'windows'
2250 run : choco install make
2351 shell : pwsh
2452
25- - name : Install zip
53+ - name : Install zip (Windows)
54+ if : matrix.goos == 'windows'
2655 run : choco install zip
2756 shell : pwsh
2857
29- - name : Build release
58+ - name : Prepare build directory
59+ if : matrix.goos != 'windows'
60+ shell : bash
61+ run : |
62+ set -euo pipefail
63+ mkdir -p build/server/downloads
64+ cp server.config.json build/server/server.config.json
65+
66+ - name : Build server
67+ if : matrix.goos != 'windows'
68+ shell : bash
69+ env :
70+ GOOS : ${{ matrix.goos }}
71+ GOARCH : ${{ matrix.arch }}
72+ run : |
73+ set -euo pipefail
74+ go build -o build/server/evs-server${{ matrix.ext }} ./cmd/server/main.go
75+
76+ - name : Package artifact
77+ if : matrix.goos != 'windows'
78+ shell : bash
79+ run : |
80+ set -euo pipefail
81+ VERSION="${GITHUB_REF_NAME}"
82+ BASENAME="evs-server-${VERSION}-${{ matrix.goos }}-${{ matrix.arch }}"
83+ cd build/server
84+ if [ "${{ matrix.archive_ext }}" = ".zip" ]; then
85+ zip -r "../${BASENAME}.zip" "evs-server${{ matrix.ext }}" "server.config.json" "downloads/"
86+ else
87+ tar czf "../${BASENAME}.tar.gz" "evs-server${{ matrix.ext }}" "server.config.json" "downloads/"
88+ fi
89+ echo "ARCHIVE_PATH=build/${BASENAME}${{ matrix.archive_ext }}" >> $GITHUB_ENV
90+
91+ - name : Build release (Windows)
92+ if : matrix.goos == 'windows'
3093 run : make release
3194 shell : pwsh
3295
3396 - name : Upload Release Artifacts
97+ if : matrix.goos == 'windows'
3498 uses : softprops/action-gh-release@v2
3599 with :
36100 files : dist/evs_*.zip
37101 env :
38102 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
103+
104+ - name : Upload Release Artifacts (Linux/macOS)
105+ if : matrix.goos != 'windows'
106+ uses : softprops/action-gh-release@v2
107+ with :
108+ files : ${{ env.ARCHIVE_PATH }}
109+ env :
110+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments