-
Notifications
You must be signed in to change notification settings - Fork 1
330 lines (324 loc) · 13.3 KB
/
Copy pathmain.yaml
File metadata and controls
330 lines (324 loc) · 13.3 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
name: Build and Release
on:
workflow_dispatch:
jobs:
build:
name: Build and Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "stable"
- name: Build and Test on Default Platform
run: |
go build -v ./...
go test -v ./...
- name: Delete Existing Release Assets
run: |
release_id=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/oneclickvirt/cputest/releases/tags/output" | jq -r '.id')
if [ "$release_id" != "null" ]; then
echo "Deleting existing release assets..."
assets=$(curl -s -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/oneclickvirt/cputest/releases/$release_id/assets" | jq -r '.[] | .id')
for asset in $assets; do
echo "Deleting asset with ID: $asset"
curl -s -X DELETE -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/oneclickvirt/cputest/releases/assets/$asset"
done
sleep 30
else
echo "No existing release found, skipping asset deletion"
fi
release-binary:
name: Release Go Binary
runs-on: ubuntu-latest
needs: build
strategy:
fail-fast: false
matrix:
goos: [windows, freebsd, openbsd, netbsd, linux, darwin]
goarch: [amd64, 386]
exclude:
- goarch: 386
goos: darwin
- goarch: 386
goos: freebsd
- goarch: 386
goos: openbsd
- goarch: 386
goos: netbsd
include:
- goos: windows
goarch: arm64
- goos: windows
goarch: arm
goarm: 7
- goos: darwin
goarch: arm64
- goos: linux
goarch: arm
goarm: 7
- goos: linux
goarch: arm64
- goos: linux
goarch: riscv64
- goos: linux
goarch: mips64
- goos: linux
goarch: mips64le
- goos: linux
goarch: mipsle
- goos: linux
goarch: mips
- goos: linux
goarch: ppc64
- goos: linux
goarch: ppc64le
- goos: linux
goarch: s390x
- goos: freebsd
goarch: arm64
- goos: freebsd
goarch: arm
goarm: 7
- goos: openbsd
goarch: arm64
- goos: openbsd
goarch: arm
goarm: 7
- goos: netbsd
goarch: arm64
- goos: netbsd
goarch: arm
goarm: 7
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "stable"
- name: Install base build tools and cross compilers
run: |
sudo apt-get update
if [ "${{ runner.arch }}" == "ARM64" ]; then
sudo apt-get install -y build-essential clang lld llvm jq curl gcc-aarch64-linux-gnu
else
sudo apt-get install -y build-essential clang lld llvm jq curl gcc-multilib g++-multilib
fi
case "${{ matrix.goos }}-${{ matrix.goarch }}" in
linux-arm)
if [ "${{ runner.arch }}" != "ARM64" ]; then
sudo apt-get install -y gcc-arm-linux-gnueabihf
fi ;;
linux-arm64)
if [ "${{ runner.arch }}" != "ARM64" ]; then
sudo apt-get install -y gcc-aarch64-linux-gnu
fi ;;
linux-riscv64)
sudo apt-get install -y gcc-riscv64-linux-gnu ;;
linux-mips64)
sudo apt-get install -y gcc-mips64-linux-gnuabi64 ;;
linux-mips64le)
sudo apt-get install -y gcc-mips64el-linux-gnuabi64 ;;
linux-mipsle)
sudo apt-get install -y gcc-mipsel-linux-gnu ;;
linux-mips)
sudo apt-get install -y gcc-mips-linux-gnu ;;
linux-ppc64)
sudo apt-get install -y gcc-powerpc64-linux-gnu ;;
linux-ppc64le)
sudo apt-get install -y gcc-powerpc64le-linux-gnu ;;
windows-amd64|windows-386)
if [ "${{ runner.arch }}" != "ARM64" ]; then
sudo apt-get install -y gcc-mingw-w64-x86-64 gcc-mingw-w64-i686
fi ;;
freebsd-*|openbsd-*|netbsd-*)
sudo apt-get install -y clang lld ;;
*)
echo "No additional cross compiler needed" ;;
esac
- name: Determine CGO requirement
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
run: |
if [[ ("$GOARCH" == "386" || "$GOARCH" == "arm") && !(("$GOOS" == "freebsd" || "$GOOS" == "openbsd" || "$GOOS" == "netbsd" || "$GOOS" == "darwin") && ("$GOARCH" == "386" || "$GOARCH" == "arm")) && !("$GOOS" == "windows" && "$GOARCH" == "arm") ]]; then
echo "NEED_CGO=1" >> $GITHUB_ENV
elif [[ ("$GOARCH" == "amd64" || "$GOARCH" == "arm64" || "$GOARCH" == "riscv64" || "$GOARCH" == "mips64" || "$GOARCH" == "mips64le" || "$GOARCH" == "ppc64le") && !(("$GOOS" == "freebsd" || "$GOOS" == "openbsd" || "$GOOS" == "netbsd" || "$GOOS" == "darwin") && ("$GOARCH" == "amd64" || "$GOARCH" == "arm64")) && !("$GOOS" == "windows" && "$GOARCH" == "arm64") ]]; then
echo "NEED_CGO=1" >> $GITHUB_ENV
else
echo "NEED_CGO=0" >> $GITHUB_ENV
fi
- name: Set cross compiler
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
GOARM: ${{ matrix.goarm || '' }}
SYSROOT: ${{ env.SYSROOT || '' }}
run: |
set -e
if [ "$NEED_CGO" == "0" ]; then
echo "CGO_ENABLED=0" >> $GITHUB_ENV
else
echo "CGO_ENABLED=1" >> $GITHUB_ENV
case "${GOOS}-${GOARCH}" in
linux-arm)
if [ "${{ runner.arch }}" == "ARM64" ]; then
echo "CC=gcc" >> $GITHUB_ENV
else
echo "CC=arm-linux-gnueabihf-gcc" >> $GITHUB_ENV
fi ;;
linux-arm64)
if [ "${{ runner.arch }}" == "ARM64" ]; then
echo "CC=gcc" >> $GITHUB_ENV
else
echo "CC=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
fi ;;
linux-riscv64)
echo "CC=riscv64-linux-gnu-gcc" >> $GITHUB_ENV ;;
linux-mips64)
echo "CC=mips64-linux-gnuabi64-gcc" >> $GITHUB_ENV ;;
linux-mips64le)
echo "CC=mips64el-linux-gnuabi64-gcc" >> $GITHUB_ENV ;;
linux-mipsle)
echo "CC=mipsel-linux-gnu-gcc" >> $GITHUB_ENV ;;
linux-mips)
echo "CC=mips-linux-gnu-gcc" >> $GITHUB_ENV ;;
linux-ppc64)
echo "CC=powerpc64-linux-gnu-gcc" >> $GITHUB_ENV ;;
linux-ppc64le)
echo "CC=powerpc64le-linux-gnu-gcc" >> $GITHUB_ENV ;;
freebsd-arm)
echo "CC=clang --target=armv7-unknown-freebsd --sysroot=${SYSROOT}" >> $GITHUB_ENV ;;
freebsd-arm64)
echo "CC=clang --target=aarch64-unknown-freebsd --sysroot=${SYSROOT}" >> $GITHUB_ENV ;;
freebsd-amd64)
echo "CC=clang --target=x86_64-unknown-freebsd --sysroot=${SYSROOT}" >> $GITHUB_ENV ;;
windows-amd64)
if [ "${{ runner.arch }}" == "ARM64" ]; then
echo "CGO_ENABLED=0" >> $GITHUB_ENV
else
echo "CC=x86_64-w64-mingw32-gcc" >> $GITHUB_ENV
fi ;;
windows-386)
if [ "${{ runner.arch }}" == "ARM64" ]; then
echo "CGO_ENABLED=0" >> $GITHUB_ENV
else
echo "CC=i686-w64-mingw32-gcc" >> $GITHUB_ENV
fi ;;
darwin-amd64)
echo "CC=o64-clang" >> $GITHUB_ENV
echo "CXX=o64-clang++" >> $GITHUB_ENV ;;
darwin-arm64)
echo "CC=oa64-clang" >> $GITHUB_ENV
echo "CXX=oa64-clang++" >> $GITHUB_ENV ;;
*)
echo "Using default system compiler for ${GOOS}-${GOARCH}" ;;
esac
fi
- name: Download Geekbench binaries for embedding
run: |
# Version matrix (update these when new releases are available):
# GB4: x86_64 only
# GB5: x86_64 + aarch64/armv7
# GB6: x86_64 + aarch64/armv7 (preferred for modern platforms)
GB4_VER="4.4.4"
GB5_VER="5.5.1"
GB6_VER="6.7.1"
BASE="https://cdn.geekbench.com"
BINS="$GITHUB_WORKSPACE/cpu/geekbench_bins"
mkdir -p "$BINS"
case "${{ matrix.goos }}-${{ matrix.goarch }}" in
linux-amd64)
# Embed GB6 (latest) for x86_64
cd /tmp
wget -q "${BASE}/Geekbench-${GB6_VER}-Linux.tar.gz" -O gb.tar.gz \
|| { echo "Geekbench GB6 download failed, skipping embed"; exit 0; }
tar -xf gb.tar.gz
cp "Geekbench-${GB6_VER}-Linux/geekbench6" "$BINS/geekbench"
cp "Geekbench-${GB6_VER}-Linux/geekbench_x86_64" "$BINS/"
cp "Geekbench-${GB6_VER}-Linux/geekbench.plar" "$BINS/"
;;
linux-arm64)
# Embed GB6 ARM Preview (latest) for aarch64
cd /tmp
wget -q "${BASE}/Geekbench-${GB6_VER}-LinuxARMPreview.tar.gz" -O gb.tar.gz \
|| { echo "Geekbench GB6 ARM download failed, skipping embed"; exit 0; }
tar -xf gb.tar.gz
cp "Geekbench-${GB6_VER}-LinuxARMPreview/geekbench6" "$BINS/geekbench"
cp "Geekbench-${GB6_VER}-LinuxARMPreview/geekbench_aarch64" "$BINS/"
cp "Geekbench-${GB6_VER}-LinuxARMPreview/geekbench.plar" "$BINS/"
;;
linux-arm)
# Embed GB5 ARM Preview for armv7 (better glibc compatibility on 32-bit ARM)
cd /tmp
wget -q "${BASE}/Geekbench-${GB5_VER}-LinuxARMPreview.tar.gz" -O gb.tar.gz \
|| { echo "Geekbench GB5 ARM download failed, skipping embed"; exit 0; }
tar -xf gb.tar.gz
cp "Geekbench-${GB5_VER}-LinuxARMPreview/geekbench5" "$BINS/geekbench"
cp "Geekbench-${GB5_VER}-LinuxARMPreview/geekbench_aarch64" "$BINS/"
cp "Geekbench-${GB5_VER}-LinuxARMPreview/geekbench_armv7" "$BINS/"
cp "Geekbench-${GB5_VER}-LinuxARMPreview/geekbench.plar" "$BINS/"
;;
*)
# GB4 is x86_64-only and superseded by GB5/GB6; other platforms use PATH.
echo "No Geekbench binary to embed for ${{ matrix.goos }}/${{ matrix.goarch }}, will rely on PATH at runtime"
;;
esac
- name: Build Binary
env:
GOARM: ${{ matrix.goarm || '' }}
CC: ${{ env.CC }}
CXX: ${{ env.CXX }}
CGO_ENABLED: ${{ env.CGO_ENABLED }}
run: |
mkdir -p bin
cd cmd
output_file="../bin/cputest-${{ matrix.goos }}-${{ matrix.goarch }}"
echo "::group::Building for ${{ matrix.goos }}/${{ matrix.goarch }}"
set +e
if [ "$CGO_ENABLED" == "0" ]; then
CGO_ENABLED=0 GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} GOARM=$GOARM \
go build -o "$output_file" \
-v \
-ldflags="-s -w" \
-trimpath \
.
else
CGO_ENABLED=1 GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} GOARM=$GOARM \
go build -o "$output_file" \
-v \
-ldflags="-extldflags=-static -s -w" \
-trimpath \
.
fi
build_exit=$?
echo "::endgroup::"
if [ $build_exit -ne 0 ]; then
echo "::warning::Build failed for ${{ matrix.goos }}/${{ matrix.goarch }}"
rm -f "$output_file" 2>/dev/null
else
echo "Successfully built: $output_file"
fi
- name: Upload Artifact
if: success() || failure()
run: |
release_id=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/oneclickvirt/cputest/releases/tags/output" | jq -r '.id')
if [ -z "$release_id" ] || [ "$release_id" = "null" ]; then
echo "::error::Failed to get release ID"
exit 1
fi
bin_path="./bin/cputest-${{ matrix.goos }}-${{ matrix.goarch }}"
if [ -f "$bin_path" ]; then
echo "Uploading $bin_path to release..."
curl -s \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/octet-stream" \
--data-binary @"$bin_path" \
"https://uploads.github.com/repos/oneclickvirt/cputest/releases/$release_id/assets?name=$(basename "$bin_path")"
echo "Upload completed for $bin_path"
else
echo "::warning::Skipping upload for ${{ matrix.goos }}/${{ matrix.goarch }} - no build artifact"
fi