-
Notifications
You must be signed in to change notification settings - Fork 41
387 lines (334 loc) · 13.2 KB
/
build.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
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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
# Heavyweight build and test
name: Build and Publish
on:
push:
branches:
- main
paths-ignore:
- docs/
workflow_dispatch:
jobs:
set-version-number:
name: Set version number
runs-on: ubuntu-latest
outputs:
nuGetVersion: ${{ steps.gitversion.outputs.nuGetVersionV2 }}
semVer: ${{ steps.gitversion.outputs.fullSemVer }}
is-release: ${{ steps.gitversion.outputs.CommitsSinceVersionSource == 0 }}
#is-release: 'true'
steps:
- name: Setup .NET 8
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v0.11.0
with:
versionSpec: '5.x'
- name: Determine Version
id: gitversion
uses: gittools/actions/gitversion/execute@v0.11.0
build-netcore-tool:
needs: set-version-number
name: Build .NET Core (global) tool
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET 8
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
#run: dotnet pack ./grate/grate.csproj -c release -p:PackAsTool=true -p:PackageOutputPath=/tmp/grate/nupkg
run: dotnet pack ./src/grate/grate.csproj -p:SelfContained=false -p:PackAsTool=true -p:PackageOutputPath=/tmp/grate/nupkg
env:
VERSION: ${{ needs.set-version-number.outputs.nuGetVersion }}
- name: Upload published tool artifact
uses: actions/upload-artifact@v3
if: ${{ needs.set-version-number.outputs.is-release == 'true' }}
with:
name: grate-dotnet-tool-${{ needs.set-version-number.outputs.nuGetVersion }}
path: /tmp/grate/nupkg/*
- name: Push to Nuget.org
if: ${{ needs.set-version-number.outputs.is-release == 'true' }}
run: dotnet nuget push /tmp/grate/nupkg/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{secrets.NUGET_ORG_KEY}} --skip-duplicate
build-nuget-package:
needs: set-version-number
name: Build Nuget
runs-on: ubuntu-latest
strategy:
matrix:
package: [
"grate.core",
"grate.mariadb",
"grate.oracle",
"grate.postgresql",
"grate.sqlite",
"grate.sqlserver"
]
steps:
- uses: actions/checkout@v4
- name: Setup .NET 8
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Pack Nuget package ${{ matrix.package }}
run: dotnet pack ./src/${{ matrix.package }} -c Release --include-symbols -o /tmp/grate/nupkg /p:Version=${{ env.VERSION }}
env:
VERSION: ${{ needs.set-version-number.outputs.nuGetVersion }}
- name: Push to Nuget.org
if: ${{ needs.set-version-number.outputs.is-release == 'true' }}
run: dotnet nuget push /tmp/grate/nupkg/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{secrets.NUGET_ORG_KEY}} --skip-duplicate
build-standalone:
name: Build cli
needs: set-version-number
runs-on: ubuntu-latest
strategy:
matrix:
arch: [ "win-x64", "win-x86", "win-arm64",
"linux-musl-x64", "linux-musl-arm64", "linux-x64", "linux-arm64",
"osx-x64", "osx-arm64"
]
steps:
- uses: actions/checkout@v4
- name: Setup .NET 8
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Publish self-contained ${{ matrix.arch }}
run: dotnet publish ./src/grate/grate.csproj -f net8.0 -r ${{ matrix.arch }} -c release --self-contained -p:SelfContained=true -o ./publish/${{ matrix.arch }}/self-contained
env:
VERSION: ${{ needs.set-version-number.outputs.nuGetVersion }}
- name: Publish .NET 6/7/8 dependent ${{ matrix.arch }}
run: dotnet publish ./src/grate/grate.csproj -r ${{ matrix.arch }} -c release --no-self-contained -o ./publish/${{ matrix.arch }}/dependent
env:
VERSION: ${{ needs.set-version-number.outputs.nuGetVersion }}
- name: Upload self-contained ${{ matrix.arch }}
#if: ${{ needs.set-version-number.outputs.is-release == 'true' }}
uses: actions/upload-artifact@v3
with:
name: grate-${{ matrix.arch }}-self-contained-${{ needs.set-version-number.outputs.nuGetVersion }}
path: ./publish/${{ matrix.arch }}/self-contained/*
- name: Upload .net dependent ${{ matrix.arch }}
if: ${{ needs.set-version-number.outputs.is-release == 'true' }}
uses: actions/upload-artifact@v3
with:
name: grate-${{ matrix.arch }}-framework-dependent-${{ needs.set-version-number.outputs.nuGetVersion }}
path: ./publish/${{ matrix.arch }}/dependent/*
build-msi:
name: Build MSI
needs:
- set-version-number
- build-standalone
runs-on: windows-latest
if: ${{ needs.set-version-number.outputs.is-release == 'true' }}
strategy:
matrix:
arch: [ "win-x64", "win-arm64" ]
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v3
with:
name: grate-${{ matrix.arch }}-self-contained-${{ needs.set-version-number.outputs.nuGetVersion }}
path: ${{ matrix.arch }}/
- name: Create msi
if: ${{ needs.set-version-number.outputs.is-release == 'true' }}
run: ./installers/msi/Create-Installer.ps1 -grateExe ./${{ matrix.arch }}/grate.exe -Version "${{ needs.set-version-number.outputs.nuGetVersion }}"
env:
VERSION: ${{ needs.set-version-number.outputs.nuGetVersion }}
- name: Upload MSI ${{ matrix.arch }}
uses: actions/upload-artifact@v3
with:
name: grate-msi-${{ matrix.arch }}-${{ needs.set-version-number.outputs.nuGetVersion }}
path: ./installers/msi/tmp/*.msi
build-docker-image:
name: Build and push docker image
needs:
- set-version-number
#- build-standalone ## no need, we build directly from source
runs-on: ubuntu-latest
if: ${{ needs.set-version-number.outputs.is-release == 'true' }}
env:
#REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
FULL_IMAGE_NAME: ${{ github.repository }}
steps:
- uses: actions/checkout@v4
# - uses: actions/download-artifact@v3 # download from another artifact is not a good idea, we need to build directly from source
# with:
# name: grate-linux-musl-x64-self-contained-${{ needs.set-version-number.outputs.nuGetVersion }}
# path: installers/docker/
- name: Log in to the Container registry
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d
with:
#registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner}}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81
with:
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{version}},value=${{ needs.set-version-number.outputs.semVer }}
type=ref,event=tag
#images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
images: ${{ env.IMAGE_NAME }}
- name: Build and push Docker image
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56
with:
file: ./installers/docker/Dockerfile
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-deb:
name: Build Debian package
needs:
- set-version-number
- build-standalone
runs-on: ubuntu-latest
if: ${{ needs.set-version-number.outputs.is-release == 'true' }}
strategy:
matrix:
arch: [ "linux-arm64", "linux-x64" ]
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v3
with:
name: grate-${{ matrix.arch }}-self-contained-${{ needs.set-version-number.outputs.nuGetVersion }}
path: ${{ matrix.arch }}/
- id: get-arch
name: Get architecture
run: |
arch=$(echo ${{ matrix.arch }} | cut -d- -f2 | sed 's/x64/amd64/')
echo "::set-output name=arch::$arch"
- name: Create dpkg # Linux with powershell script? really?
if: ${{ needs.set-version-number.outputs.is-release == 'true' }}
run: ./installers/deb/Create-Package.ps1 -grateExe ./${{ matrix.arch }}/grate -Version "${{ needs.set-version-number.outputs.nuGetVersion }}" -arch ${{ steps.get-arch.outputs.arch}}
env:
VERSION: ${{ needs.set-version-number.outputs.nuGetVersion }}
- name: Upload .dpkg ${{ steps.get-arch.outputs.arch }}
uses: actions/upload-artifact@v3
with:
name: grate_${{ needs.set-version-number.outputs.nuGetVersion }}-1_${{ steps.get-arch.outputs.arch}}.deb
path: ./installers/deb/grate_${{ needs.set-version-number.outputs.nuGetVersion }}-1_${{ steps.get-arch.outputs.arch }}.deb
# build-winget:
# name: Winget - Update package manifest in the OWC
# needs:
# - set-version-number
# - build-msi
# runs-on: windows-latest
# if: ${{ needs.set-version-number.outputs.is-release == 'true' }}
# steps:
# - name: Winget-Create
# run: |
# $version = "$($env:version)"
# # Download wingetcreate
# iwr https://aka.ms/wingetcreate/latest -OutFile wingetcreate.exe
# $packageUrl="https://github.com/erikbra/grate/releases/download/$version/grate-$version.msi"
# echo "Running ./wingetcreate.exe update erikbra.grate -u $packageUrl -v $version -t `"$env:WINGET_GH_PAT`" --submit"
# ./wingetcreate.exe update erikbra.grate -u $packageUrl -v $version -t "$env:WINGET_GH_PAT" --submit
# env:
# WINGET_GH_PAT: ${{ secrets.WINGET_GH_PAT }}
# #version: "1.4.0"
# version: "${{ needs.set-version-number.outputs.nuGetVersion }}"
test:
name: Run tests
runs-on: ubuntu-latest
strategy:
matrix:
category: [ "Basic_tests", "SqlServer", "PostgreSQL", "MariaDB", "Sqlite", "Oracle" ]
steps:
- uses: actions/checkout@v4
- name: Setup .NET 8
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Test
run: >
dotnet test
unittests/${{ matrix.category }}
--logger:"xunit;LogFilePath=/tmp/test-results/${{ matrix.category }}.xml" --
-MaxCpuCount 2
env:
LogLevel: Warning
TZ: UTC
integration-test:
name: Tests cli
needs:
- set-version-number
- build-standalone
strategy:
matrix:
#os: [windows-latest, ubuntu-latest, macos-latest]
# category: [ "CommandLine.SqlServer", "CommandLine.PostgreSQL",
# "CommandLine.MariaDB", "CommandLine.Sqlite", "CommandLine.Oracle" ]
category:
- CommandLine.SqlServer
- CommandLine.PostgreSQL
- CommandLine.MariaDB
- CommandLine.Sqlite
- CommandLine.Oracle
#include:
os:
# - os: windows-latest
# executable: grate.exe
# - name: windows-latest
# arch: win-x64
# executable: grate.exe
# - os: linux-latest
# executable: grate
- name: linux-latest
arch: linux-x64
executable: grate
# - os: macos-latest
# executable: grate
# - name: macos-latest
# arch: osx-x64
# executable: grate
# - name: macos-14
# arch: osx-x64
# executable: grate
#arch: [ "linux", "win", "macos" ]
# arch: [ "win-x64", "win-x86", "win-arm64",
# "linux-musl-x64", "linux-musl-arm64", "linux-x64", "linux-arm64",
# "osx-x64", "osx-arm64"
# ]
runs-on: ${{ matrix.os.name }}
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v3
with:
name: grate-${{ matrix.os.arch }}-self-contained-${{ needs.set-version-number.outputs.nuGetVersion }}
#name: grate-linux-musl-x64-self-contained-${{ needs.set-version-number.outputs.nuGetVersion }}
path: executables/${{ matrix.os.arch }}
- name: Setup .NET 8
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: chmod u+x
run: chmod u+x $GrateExecutablePath
if: ${{ matrix.os.arch != 'win-x64' }}
env:
GrateExecutablePath: ${{ github.workspace }}/executables/${{ matrix.os.arch }}/${{ matrix.os.executable }}
#GrateExecutablePath: ${{ github.workspace }}/executables/${{ matrix.arch }}/grate
- name: Test
run: >
dotnet test
unittests/CommandLine/${{ matrix.category }}
--logger:"xunit;LogFilePath=/tmp/test-results/${{ matrix.os.arch }}/${{ matrix.category }}.xml" --
-MaxCpuCount 2
env:
LogLevel: Warning
GrateExecutablePath: ${{ github.workspace }}/executables/${{ matrix.os.arch }}/${{ matrix.os.executable }}
#GrateExecutablePath: ${{ github.workspace }}/executables/${{ matrix.arch }}/grate
TZ: UTC