-
Notifications
You must be signed in to change notification settings - Fork 75
307 lines (270 loc) · 10.1 KB
/
build.yaml
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
name: "azqr-build"
on:
workflow_dispatch:
push:
paths-ignore:
- docs/**
branches:
- main
- release-*
tags:
- v*
pull_request:
paths-ignore:
- docs/**
branches:
- main
- release-*
permissions: read-all
jobs:
build:
name: Build ${{ matrix.target_os }}_${{ matrix.target_arch }} binaries
runs-on: ${{ matrix.os }}
permissions:
contents: read
packages: write
env:
GOVER: '1.21'
GOLANGCILINT_VER: v1.54
GOOS: ${{ matrix.target_os }}
GOARCH: ${{ matrix.target_arch }}
GOPROXY: https://proxy.golang.org
ARCHIVE_OUTDIR: dist/archives
PROJECT_NAME: azqr
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
target_arch: [amd64, arm, arm64]
include:
- os: ubuntu-latest
target_os: linux
filename: azqr
- os: windows-latest
target_os: windows
filename: azqr.exe
- os: macOS-latest
target_os: darwin
filename: azqr
exclude:
- os: windows-latest
target_arch: arm
- os: windows-latest
target_arch: arm64
- os: macOS-latest
target_arch: arm
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Go ${{ env.GOVER }}
uses: actions/setup-go@v4
with:
go-version: ${{ env.GOVER }}
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
- name: Setup MinVer
run: |
dotnet tool install --global minver-cli --version 4.2.0
- name: golangci-lint
if: matrix.target_os == 'linux' && matrix.target_arch == 'amd64'
uses: golangci/golangci-lint-action@v3
with:
version: ${{ env.GOLANGCILINT_VER }}
skip-pkg-cache: true
args: --timeout 3m --verbose
- name: Run go mod tidy & check diff
if: matrix.target_os == 'linux' && matrix.target_arch == 'amd64'
run: |
go mod tidy
git diff --exit-code ./go.mod
git diff --exit-code ./go.sum
- name: Run Go vet
if: matrix.target_os == 'linux' && matrix.target_arch == 'amd64'
run: |
go vet ./...
- name: Run Tests
if: matrix.target_os == 'linux' && matrix.target_arch == 'amd64'
env:
COVERAGE_OPTS: "-coverprofile=coverage.txt -covermode=atomic"
run: |
go install gotest.tools/gotestsum@latest
CGO_ENABLED=0 gotestsum --jsonfile ./test_report_unit.json --format standard-quiet -- ./... $COVERAGE_OPTS --tags=unit
go test ./...
- name: Codecov
if: matrix.target_os == 'linux' && matrix.target_arch == 'amd64'
uses: codecov/codecov-action@v3
- name: Calculate Version
run: |
echo "MINVERVERSIONOVERRIDE=$($HOME/.dotnet/tools/minver -t v. -m 0.1 -d preview)" >> $GITHUB_ENV
if: matrix.os != 'windows-latest'
- name: Calculate Version Windows
run: |
echo "MINVERVERSIONOVERRIDE=$(minver -t v. -m 0.1 -d preview)" >> $env:GITHUB_ENV
if: matrix.os == 'windows-latest'
- name: output folder variable linux & mac
if: matrix.target_os != 'windows'
run: |
echo AZQR_OUTPUT_FOLDER=${{ env.ARCHIVE_OUTDIR }}/${{ matrix.target_os }}/${{ matrix.target_arch }} >> $GITHUB_ENV
- name: output folder variable windows
if: matrix.target_os == 'windows'
run: |
echo AZQR_OUTPUT_FOLDER=${{ env.ARCHIVE_OUTDIR }}/${{ matrix.target_os }}/${{ matrix.target_arch }} >> $env:GITHUB_ENV
- name: Create output folder
run: |
mkdir -p ${{ env.AZQR_OUTPUT_FOLDER }}
- name: Run build and archive non windows binaries
if: matrix.target_os != 'windows'
run: |
GOOS=${{ matrix.target_os }} GOARCH=${{ matrix.target_arch }} go build -ldflags "-s -w -X 'github.com/Azure/azqr/cmd/azqr.version=${{ env.MINVERVERSIONOVERRIDE }}'" -o ${{ env.AZQR_OUTPUT_FOLDER }}/${{ matrix.filename }} ./cmd/main.go
- name: Run build and archive windows binaries
if: matrix.target_os == 'windows'
run: |
go build -ldflags "-s -w -X 'github.com/Azure/azqr/cmd/azqr.version=${{ env.MINVERVERSIONOVERRIDE }}'" -o ${{ env.AZQR_OUTPUT_FOLDER }}/${{ matrix.filename }} ./cmd/main.go
- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ env.PROJECT_NAME }}-${{ matrix.os }}-${{ matrix.target_arch }}
path: ${{ env.AZQR_OUTPUT_FOLDER }}/${{ matrix.filename }}
release:
name: Create Release
needs: build
if: github.event_name != 'pull_request' && startswith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get changes since lastest tag
run: |
echo "AZQR_CHANGE_LOG=$(git log $(git describe --tags --abbrev=0)..HEAD --oneline)" >> $GITHUB_ENV
- name: release
uses: actions/create-release@v1
id: create_release
with:
tag_name: ${{ github.ref }}
release_name: ${{ env.MINVERVERSIONOVERRIDE }}
body: ${{ env.AZQR_CHANGE_LOG }}
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ github.token }}
publish:
name: Publish binaries
needs: release
permissions:
contents: write
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
target_arch: [amd64, arm, arm64]
exclude:
- os: windows-latest
target_arch: arm
- os: windows-latest
target_arch: arm64
- os: macOS-latest
target_arch: arm
if: github.event_name != 'pull_request' && startswith(github.ref, 'refs/tags/v')
env:
ARTIFACT_DIR: ${{ github.workspace }}/release
PROJECT_NAME: azqr
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Artifact Name linux & mac
if: matrix.target_os != 'windows'
run: |
echo AZQR_ARTIFACT_NAME=${{ env.PROJECT_NAME }}-${{ matrix.os }}-${{ matrix.target_arch }} >> $GITHUB_ENV
- name: Artifact Name windows
if: matrix.target_os == 'windows'
run: |
echo AZQR_ARTIFACT_NAME=${{ env.PROJECT_NAME }}-${{ matrix.os }}-${{ matrix.target_arch }} >> $env:GITHUB_ENV
- name: download artifacts - ${{ env.AZQR_ARTIFACT_NAME }}
uses: actions/download-artifact@v3
with:
name: ${{ env.AZQR_ARTIFACT_NAME }}
path: ${{ env.ARTIFACT_DIR }}/${{ env.AZQR_ARTIFACT_NAME }}/
- name: Create sha256 Checksums for linux and mac
if: matrix.os != 'windows-latest'
run: |
sha256sum ${{ env.ARTIFACT_DIR }}/${{ env.AZQR_ARTIFACT_NAME }}/azqr > ${{ env.ARTIFACT_DIR }}/${{ env.AZQR_ARTIFACT_NAME }}.sha256
- name: Create sha256 Checksums for windows
if: matrix.os == 'windows-latest'
run: |
sha256sum ${{ env.ARTIFACT_DIR }}/${{ env.AZQR_ARTIFACT_NAME }}/azqr.exe > ${{ env.ARTIFACT_DIR }}/${{ env.AZQR_ARTIFACT_NAME }}.exe.sha256
- name: upload linux & mac artifacts
if: matrix.os != 'windows-latest'
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ needs.release.outputs.upload_url }}
asset_path: ${{ env.ARTIFACT_DIR }}/${{ env.AZQR_ARTIFACT_NAME }}/azqr
asset_name: ${{ env.AZQR_ARTIFACT_NAME }}
asset_content_type: application/octet-stream
- name: upload linux & mac sha256
if: matrix.os != 'windows-latest'
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ needs.release.outputs.upload_url }}
asset_path: ${{ env.ARTIFACT_DIR }}/${{ env.AZQR_ARTIFACT_NAME }}.sha256
asset_name: ${{ env.AZQR_ARTIFACT_NAME }}.sha256
asset_content_type: application/octet-stream
- name: upload windows artifact
if: matrix.os == 'windows-latest'
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ needs.release.outputs.upload_url }}
asset_path: ${{ env.ARTIFACT_DIR }}/${{ env.AZQR_ARTIFACT_NAME }}/azqr.exe
asset_name: ${{ env.AZQR_ARTIFACT_NAME }}.exe
asset_content_type: application/octet-stream
- name: upload windows sha256
if: matrix.os == 'windows-latest'
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ needs.release.outputs.upload_url }}
asset_path: ${{ env.ARTIFACT_DIR }}/${{ env.AZQR_ARTIFACT_NAME }}.exe.sha256
asset_name: ${{ env.AZQR_ARTIFACT_NAME }}.exe.sha256
asset_content_type: application/octet-stream
bump-winget:
name: bump-winget
needs: publish
permissions:
contents: write
if: github.event_name != 'pull_request' && startswith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
- name: Setup MinVer
run: |
dotnet tool install --global minver-cli --version 4.2.0
- name: Calculate Version
run: |
echo "MINVERVERSIONOVERRIDE=$($HOME/.dotnet/tools/minver -t v. -m 0.1 -d preview)" >> $GITHUB_ENV
- name: Trigger Bump Winget
uses: peter-evans/repository-dispatch@v2
with:
event-type: bump-winget
client-payload: '{"version": "${{ env.MINVERVERSIONOVERRIDE }}"}'