-
Notifications
You must be signed in to change notification settings - Fork 88
259 lines (233 loc) · 8.23 KB
/
go.yml
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
name: Go
on:
pull_request: {}
push:
branches: [master]
tags:
- v*
jobs:
test-linux:
name: Test (Linux)
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v3
with:
go-version: 1.19.x
- name: Check out code into the Go module directory
uses: actions/checkout@v3
- uses: golangci/golangci-lint-action@v3
- run: make convention
- run: make cover
- run: test "$(gofmt -l . | wc -l)" = 0
- uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: .profile.cov
test-windows:
name: Test (Windows)
# Please do not specify `windows-latest`
# Build process is complex then need to check operation.
runs-on: windows-2022
steps:
- uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: 1.19.x
- uses: golangci/golangci-lint-action@v3
with:
args: --timeout 5m
- uses: actions/cache@v3
with:
path: |
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**\go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Run Test
run: |
go test -short ./...
shell: bash
build-linux:
name: Build (Linux)
runs-on: ubuntu-latest
needs: test-linux
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')
env:
DEBIAN_FRONTEND: noninteractive
steps:
# before-deploy
- name: Set up Go 1.x
uses: actions/setup-go@v3
with:
go-version: 1.19.x
- name: Check out code into the Go module directory
uses: actions/checkout@v3
- name: Install debian packaging utils, binutils
run: sudo apt-get update && sudo apt-get install -y devscripts debhelper fakeroot binutils-mips-linux-gnu binutils-aarch64-linux-gnu binutils-arm-linux-gnueabihf
- run: docker pull mackerel/docker-mackerel-rpm-builder:c7
- run: make rpm deb rpm-kcps deb-kcps rpm-stage deb-stage tgz
- run: make crossbuild
- uses: actions/upload-artifact@v3
with:
name: linux-build-artifacts
path: |
rpmbuild/RPMS/*/*.rpm
packaging/*.deb
snapshot/*.zip
snapshot/*.tar.gz
build/*.tar.gz
# Note:
# Mackerel-agent requires cgo for using Windows native API.
# So we need also to install 32bit MSYS2 and msys2 shell to compile
# 32bit mackerel-agent.
# The virtual environment of GitHub Actions includes 64bit MSYS2
# but msys2 shell is not contained in its environment.
# Therefore we installs msys2 on each 32bit and 64bit platforms.
build-windows:
name: Build (Windows)
runs-on: windows-2022
needs: test-windows
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')
strategy:
matrix:
GOARCH: ["amd64", "386"]
include:
- GOARCH: amd64
PLATFORM_ID: x64
MSYS: MINGW64
- GOARCH: 386
PLATFORM_ID: x86
MSYS: MINGW32
env:
GOARCH: ${{ matrix.GOARCH }}
CGO_ENABLED: 1
CC_FOR_windows_386: i686-w64-mingw32-gcc
steps:
- uses: actions/checkout@v3
- name: Setup MINGW
uses: msys2/setup-msys2@v2
with:
msystem: ${{ matrix.MSYS }}
path-type: inherit
install: mingw-w64-i686-gcc
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: 1.19.x
- uses: actions/cache@v3
with:
path: |
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**\go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Build mackerel-agent
run: |
commit=$(git rev-parse --short HEAD)
mkdir build/
go build -o build/mackerel-agent.exe -ldflags="-X main.gitcommit=$commit" github.com/mackerelio/mackerel-agent
go build -o build/mackerel-agent-kcps.exe -ldflags="-X main.gitcommit=$commit -X github.com/mackerelio/mackerel-agent/config.apibase=http://198.18.0.16" github.com/mackerelio/mackerel-agent
shell: msys2 {0}
- name: Build mackerel-agent-plugins
run: |
cd wix
for p in $(./pluginlist.sh)
do
name=$(basename "$p")
go build -o "../build/$name.exe" "$p"
done
shell: msys2 {0}
- name: Build tools
run: |
cd wix
go build -o ../build/wrapper.exe wrapper/wrapper_windows.go wrapper/install.go
go build -o ../build/replace.exe replace/replace_windows.go replace/shell_windows.go
go build -o ../build/generate_wxs.exe generate_wxs/generate_wxs.go
shell: msys2 {0}
- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: windows-build-artifacts-${{ matrix.PLATFORM_ID }}
path: |
build/
windows-installer:
name: Make Installer (Windows)
runs-on: windows-2022
needs: build-windows
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')
strategy:
matrix:
include:
- PLATFORM_ID: x86
- PLATFORM_ID: x64
MSI_SUFFIX: -x64
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: windows-build-artifacts-${{ matrix.PLATFORM_ID }}
path: build/
- uses: actions/github-script@v6
with:
script: |
const script = require('./_tools/parse_version.js')
await script({github, context, core})
id: parse_version
- name: Build Installer
run: ./wix/build.bat "${{ steps.parse_version.outputs.VERSION }}"
env:
PLATFORM_ID: ${{ matrix.PLATFORM_ID }}
MSI_SUFFIX: ${{ matrix.MSI_SUFFIX }}
- name: Signing Installer
run: |
mkdir $env:RUNNER_TEMP/sign/
[IO.File]::WriteAllBytes("$env:RUNNER_TEMP/sign/cert.p12", [Convert]::FromBase64String("${{ secrets.WINDOWS_CERT_PFX_BASE64 }}"))
$SIGNTOOL = "C:/Program Files (x86)/Windows Kits/10/bin/10.0.19041.0/x86/signtool.exe";
& "$SIGNTOOL" sign /fd sha256 /t "http://timestamp.sectigo.com" /f "$env:RUNNER_TEMP/sign/cert.p12" /p "${{ secrets.WINDOWS_CERT_PFX_PASS }}" /v "build/mackerel-agent${{ matrix.MSI_SUFFIX }}.msi"
& "$SIGNTOOL" sign /fd sha256 /t "http://timestamp.sectigo.com" /f "$env:RUNNER_TEMP/sign/cert.p12" /p "${{ secrets.WINDOWS_CERT_PFX_PASS }}" /v "build/mackerel-agent-k${{ matrix.MSI_SUFFIX }}.msi"
- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: windows-packages-${{ matrix.PLATFORM_ID }}
path: |
build/*.msi
release:
name: Release to GitHub Releases
runs-on: ubuntu-latest
needs: [build-linux, windows-installer]
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/download-artifact@v3
with:
name: linux-build-artifacts
path: artifacts/
- uses: actions/download-artifact@v3
with:
name: windows-packages-x86
path: artifacts/
- uses: actions/download-artifact@v3
with:
name: windows-packages-x64
path: artifacts/
- uses: mackerelio/staging-release-update-action@main
if: github.ref == 'refs/heads/master'
with:
directory: artifacts/
github-token: ${{ secrets.GITHUB_TOKEN }}
tag: staging
- uses: mackerelio/create-release-action@main
if: startsWith(github.ref, 'refs/tags/v')
with:
directory: artifacts/
github-token: ${{ secrets.GITHUB_TOKEN }}
tag-prefix: "refs/tags/v"
bump-up-branch-prefix: "bump-version-"
- name: update homebrew-mackerel-agent
if: startsWith(github.ref, 'refs/tags/v')
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.MACKERELBOT_GITHUB_TOKEN }}
event-type: release
client-payload: '{"product": "mackerel-agent"}'
repository: mackerelio/homebrew-mackerel-agent