Repository navigation
152 lines (131 loc) · 4.49 KB
/
Copy pathdev.yml
File metadata and controls
152 lines (131 loc) · 4.49 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
name: Build Dev
on:
push:
branches:
- main
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
# ===== Windows =====
- os: windows-latest
goos: windows
goarch: amd64
platform: windows-amd64
ext: .exe
# ===== Linux =====
- os: ubuntu-latest
goos: linux
goarch: amd64
platform: linux-amd64
ext: ""
- os: ubuntu-22.04
goos: linux
goarch: arm64
platform: linux-arm64
ext: ""
- os: ubuntu-22.04
goos: linux
goarch: arm
goarm: "7"
platform: linux-armv7
ext: ""
# ===== macOS =====
- os: macos-15-intel
goos: darwin
goarch: amd64
platform: darwin-amd64
ext: ""
- os: macos-latest
goos: darwin
goarch: arm64
platform: darwin-arm64
ext: ""
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: src/go.mod
# 检查类步骤显式声明 bash:Windows 运行器的默认 shell 是 PowerShell,而这几步写的是 bash 语法
# The check steps declare bash explicitly: the default shell of a Windows runner is PowerShell while these steps are written in bash syntax
- name: Format check
shell: bash
working-directory: src
run: |
unformatted=$(gofmt -l .)
if [ -n "$unformatted" ]; then
echo "gofmt reported unformatted files:"
echo "$unformatted"
exit 1
fi
- name: Vet
shell: bash
working-directory: src
run: go vet ./...
- name: Test
shell: bash
working-directory: src
run: go test ./...
# 竞态检测需要 CGO 与 C 工具链,Windows/macOS 运行器不保证具备,故只在 Linux 上执行
# Race detection needs CGO and a C toolchain, which Windows/macOS runners do not guarantee, so it runs on Linux only
- name: Test (race)
if: runner.os == 'Linux'
shell: bash
working-directory: src
run: go test -race ./...
- name: Compute version
id: version
shell: bash
run: |
RAW=$(git describe --tags --always --long 2>/dev/null || echo "")
if echo "$RAW" | grep -Eq '^.+-[0-9]+-g[a-f0-9]+$'; then
VER=$(echo "$RAW" | sed -E 's/^(.+)-([0-9]+)-(g[a-f0-9]+)$/\1-beta\2-\3/')
elif echo "$RAW" | grep -Eq '^[a-f0-9]+$'; then
VER="0.0.0-beta0-g${RAW}"
else
VER="$RAW"
fi
echo "VERSION=${VER}" >> "$GITHUB_OUTPUT"
echo "Computed version: ${VER}"
- name: Build
shell: bash
run: |
export CGO_ENABLED=0
export GOOS=${{ matrix.goos }}
export GOARCH=${{ matrix.goarch }}
[ -n "${{ matrix.goarm }}" ] && export GOARM=${{ matrix.goarm }}
cd src
go build \
-ldflags "-s -w -X main.version=${{ steps.version.outputs.VERSION }}" \
-o ../dist/taskpush${{ matrix.ext }} \
./cmd/taskpush
- name: Rename binary
shell: bash
run: |
mkdir -p dist
mv dist/taskpush${{ matrix.ext }} \
dist/TaskPush-${{ steps.version.outputs.VERSION }}-${{ matrix.platform }}${{ matrix.ext }}
- name: Package (Linux / macOS)
if: runner.os != 'Windows'
run: |
cd dist
zip ../TaskPush-${{ steps.version.outputs.VERSION }}-${{ matrix.platform }}.zip \
TaskPush-${{ steps.version.outputs.VERSION }}-${{ matrix.platform }}${{ matrix.ext }}
- name: Package (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
Compress-Archive -Path "dist\TaskPush-${{ steps.version.outputs.VERSION }}-${{ matrix.platform }}${{ matrix.ext }}" `
-DestinationPath "TaskPush-${{ steps.version.outputs.VERSION }}-${{ matrix.platform }}.zip"
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: TaskPush-${{ steps.version.outputs.VERSION }}-${{ matrix.platform }}
path: TaskPush-${{ steps.version.outputs.VERSION }}-${{ matrix.platform }}.zip