-
Notifications
You must be signed in to change notification settings - Fork 13
565 lines (474 loc) · 19.3 KB
/
ci.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
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
name: CI
on:
push:
branches:
- master
pull_request:
types: [ opened, synchronize, reopened ]
workflow_dispatch:
workflow_call:
inputs:
ref:
description: "The commit SHA to build"
required: false
type: string
env:
conan-version: 1.43.4
jobs:
preflight:
name: preflight
runs-on: ubuntu-20.04
outputs:
ref: ${{ steps.get-commit.outputs.ref }}
version: ${{ steps.get-version.outputs.version }}
rust-channel: ${{ steps.rust-toolchain.outputs.rust-channel }}
rust-profile: ${{ steps.rust-profile.outputs.rust-profile }}
jetsocat-build-matrix: ${{ steps.setup-matrix.outputs.jetsocat-build-matrix }}
gateway-build-matrix: ${{ steps.setup-matrix.outputs.gateway-build-matrix }}
steps:
- name: Setup matrix
id: setup-matrix
shell: pwsh
env:
SECRET_VALUE: ${{ secrets.ARTIFACTORY_READ_TOKEN }}
run: |
$Jobs = @()
$Archs = @( 'x86_64' )
$Platforms = @( 'linux' )
if ($Env:SECRET_VALUE -Eq '') {
echo "::warning::Secrets not available, some jobs will be skipped"
} else {
$Platforms += 'windows'
}
$Platforms | ForEach-Object {
$Runner = switch ($_) { 'windows' { 'windows-2022' } 'linux' { 'ubuntu-20.04' } }
foreach ($Arch in $Archs) {
$Jobs += @{
arch = $Arch
os = $_
runner = $Runner }
}
}
$GatewayMatrix = ConvertTo-JSON $Jobs -Compress
echo "gateway-build-matrix=$GatewayMatrix" >> $Env:GITHUB_OUTPUT
$Jobs = @()
$Archs += 'arm64'
$Platforms += 'macos'
$Platforms | ForEach-Object {
$Runner = switch ($_) { 'windows' { 'windows-2022' } 'macos' { 'macos-11' } 'linux' { 'ubuntu-20.04' } }
foreach ($Arch in $Archs) {
if ($Arch -Eq 'arm64' -And $_ -Eq 'linux') {
continue
}
$Jobs += @{
arch = $Arch
os = $_
runner = $Runner }
}
}
$JetsocatMatrix = ConvertTo-JSON $Jobs -Compress
echo "jetsocat-build-matrix=$JetsocatMatrix" >> $Env:GITHUB_OUTPUT
## The SHA to build might be passed via workflow_call, otherwise the current commit is used
- name: Get commit
id: get-commit
shell: pwsh
run: |
$Ref = '${{ inputs.ref }}'
if (-Not $Ref) {
$Ref = '${{ github.sha }}'
}
echo "ref=$Ref" >> $Env:GITHUB_OUTPUT
- name: Checkout ${{ github.repository }}
uses: actions/checkout@v3
with:
ref: ${{ steps.get-commit.outputs.ref }}
- name: Get version
id: get-version
shell: pwsh
run: |
$Version = Get-Content VERSION -TotalCount 1
echo "version=$Version" >> $Env:GITHUB_OUTPUT
- name: Configure rust toolchain
id: rust-toolchain
shell: pwsh
run: |
$Channel = (Get-Content 'rust-toolchain.toml' | Select -Skip 1 | ConvertFrom-StringData).channel
rustup toolchain install $Channel
rustup component add rustfmt
echo "rust-channel=$Channel" >> $Env:GITHUB_OUTPUT
- name: Check formatting
run: |
cargo fmt --all -- --check
if ! [ $? -eq 0 ] ; then
echo "::error::Bad formatting, please run 'cargo +stable fmt --all'"
exit 1
fi
- name: Configure rust profile
id: rust-profile
shell: pwsh
run: |
$CargoProfile = "release"
if ("${{ github.ref }}" -Eq "refs/heads/master") {
echo "::notice::Building production profile"
$CargoProfile = "production"
}
echo "rust-profile=$CargoProfile" >> $Env:GITHUB_OUTPUT
- name: Upload version artifact
uses: actions/upload-artifact@v3
with:
name: version
path: VERSION
test:
name: test [${{ matrix.os }} ${{ matrix.arch }}]
runs-on: ${{ matrix.runner }}
needs: preflight
strategy:
matrix:
arch: [ x86_64 ]
os: [ windows, linux ]
include:
- os: windows
runner: windows-2022
- os: linux
runner: ubuntu-20.04
steps:
- name: Checkout ${{ github.repository }}
uses: actions/checkout@v3
with:
ref: ${{ needs.preflight.outputs.ref }}
- name: Configure rust toolchain
run: rustup toolchain install ${{ needs.preflight.outputs.rust-channel }}
- name: Configure Linux runner
if: matrix.os == 'linux'
run: |
sudo apt-get update
sudo apt-get -o Acquire::Retries=3 install libsystemd-dev
- name: Test
shell: pwsh
run: ./ci/tlk.ps1 test -Platform ${{ matrix.os }} -Architecture ${{ matrix.arch }} -CargoProfile ${{ needs.preflight.outputs.rust-profile }}
jetsocat:
name: jetsocat [${{ matrix.os }} ${{ matrix.arch }}]
runs-on: ${{ matrix.runner }}
needs: preflight
env:
CONAN_LOGIN_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
CONAN_PASSWORD: ${{ secrets.ARTIFACTORY_READ_TOKEN }}
strategy:
matrix:
include: ${{ fromJson(needs.preflight.outputs.jetsocat-build-matrix) }}
steps:
- name: Checkout ${{ github.repository }}
uses: actions/checkout@v3
with:
ref: ${{ needs.preflight.outputs.ref }}
- name: Configure rust toolchain
run: rustup toolchain install ${{ needs.preflight.outputs.rust-channel }}
- name: Configure Linux runner
if: matrix.os == 'linux'
run: |
sudo apt-get update
sudo apt-get -o Acquire::Retries=3 install python3-wget python3-setuptools
- name: Fix ring dependency for Windows ARM64
if: runner.os == 'Windows' && matrix.arch == 'arm64'
shell: pwsh
run: |
rustup target add aarch64-pc-windows-msvc
'ring = { git = "https://github.com/awakecoding/ring", branch = "0.16.20_alpha" }' | % {
Add-Content -Path "./Cargo.toml" -Value $_
}
$VSINSTALLDIR = $(vswhere.exe -latest -requires Microsoft.VisualStudio.Component.VC.Llvm.Clang -property installationPath)
$VCINSTALLDIR = Join-Path $VSINSTALLDIR "VC"
$LLVM_ROOT = Join-Path $VCINSTALLDIR "Tools\Llvm\x64"
echo "PATH=$Env:PATH;${LLVM_ROOT}\bin" >> $Env:GITHUB_ENV
# HACK: workaround for when the runner is macOS 11.7.1
# Without this step, we sometimes get this error when installing conan:
#
# > DEPRECATION: conan is being installed using the legacy ‘setup.py install’ method, because
# > it does not have a ‘pyproject.toml’ and the ‘wheel’ package is not installed. pip 23.1
# > will enforce this behaviour change. A possible replacement is to enable the
# > ‘--use-pep517’ option.
#
# The intallation is successful, yet conan can’t be used afterward.
- name: Pin Python version
if: runner.os == 'macOS'
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Configure macOS (arm) runner
if: matrix.os == 'macos' && matrix.arch == 'arm64'
run: |
sudo rm -rf /Library/Developer/CommandLineTools
rustup target add aarch64-apple-darwin
- name: Configure conan
if: matrix.os == 'windows'
run: |
pip3 install conan==${{ env.conan-version }} --upgrade
conan config install --type=git -sf settings https://github.com/Devolutions/conan-public
conan remote clean
conan remote add artifactory https://devolutions.jfrog.io/devolutions/api/conan/conan-local
- name: Build
id: build
shell: pwsh
run: |
$StagingPath = Join-Path $Env:RUNNER_TEMP "staging"
$TargetOutputPath = Join-Path $StagingPath ${{ matrix.os }} ${{ matrix.arch }}
$ExecutableFileName = 'jetsocat_${{ runner.os }}_${{ needs.preflight.outputs.version }}_${{ matrix.arch }}'
if ($Env:RUNNER_OS -eq "Windows") {
$ExecutableFileName = "$($ExecutableFileName).exe"
$Env:CARGO_NO_DEFAULT_FEATURES = "true"
$Env:CARGO_FEATURES = "native-tls"
}
$Env:TARGET_OUTPUT_PATH = $TargetOutputPath
$Env:JETSOCAT_EXECUTABLE = Join-Path $TargetOutputPath $ExecutableFileName
$Env:CARGO_PACKAGE = "jetsocat"
./ci/tlk.ps1 build -Platform ${{ matrix.os }} -Architecture ${{ matrix.arch }} -CargoProfile ${{ needs.preflight.outputs.rust-profile }}
echo "staging-path=$StagingPath" >> $Env:GITHUB_OUTPUT
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: jetsocat
path: ${{ steps.build.outputs.staging-path }}
jetsocat-lipo:
name: jetsocat macos universal
runs-on: ubuntu-20.04
needs: [preflight, jetsocat]
steps:
- uses: actions/download-artifact@v3
with:
name: jetsocat
- name: Configure runner
run: |
wget -q https://github.com/awakecoding/llvm-prebuilt/releases/download/v2021.2.4/cctools-x86_64-ubuntu-20.04.tar.xz
tar -xf cctools-x86_64-ubuntu-20.04.tar.xz -C /tmp
sudo mv /tmp/cctools-x86_64-ubuntu-20.04/bin/lipo /usr/local/bin
rm -r cctools-x86_64-ubuntu-20.04.tar.xz
- name: Lipo
shell: pwsh
run: |
$OutputPath = Join-Path "macos" "universal"
New-Item -ItemType Directory -Path $OutputPath | Out-Null
$Binaries = Get-ChildItem -Recurse -Path "macos" -Filter "jetsocat_*" | Foreach-Object { $_.FullName } | Select -Unique
$LipoCmd = $(@('lipo', '-create', '-output', (Join-Path -Path $OutputPath -ChildPath "jetsocat_macOS_${{ needs.preflight.outputs.version }}_universal")) + $Binaries) -Join ' '
Write-Host $LipoCmd
Invoke-Expression $LipoCmd
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: jetsocat
path: .
devolutions-gateway:
name: devolutions-gateway [${{ matrix.os }} ${{ matrix.arch }}]
runs-on: ${{ matrix.runner }}
needs: preflight
env:
CONAN_LOGIN_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
CONAN_PASSWORD: ${{ secrets.ARTIFACTORY_READ_TOKEN }}
strategy:
matrix:
include: ${{ fromJson(needs.preflight.outputs.gateway-build-matrix) }}
steps:
- name: Checkout ${{ github.repository }}
uses: actions/checkout@v3
with:
ref: ${{ needs.preflight.outputs.ref }}
- name: Load dynamic variables
id: load-variables
shell: pwsh
run: |
$PackageVersion = "${{ needs.preflight.outputs.version }}"
$StagingPath = Join-Path $Env:RUNNER_TEMP "staging"
$TargetOutputPath = Join-Path $StagingPath ${{ matrix.os }} ${{ matrix.arch }}
$ExecutableFileName = "DevolutionsGateway_${{ runner.os }}_${PackageVersion}_${{ matrix.arch }}"
if ($Env:RUNNER_OS -eq "Windows") {
$ExecutableFileName = "$($ExecutableFileName).exe"
$PackageFileName = "DevolutionsGateway-${{ matrix.arch }}-${PackageVersion}.msi"
$PSModuleOutputPath = Join-Path $StagingPath PowerShell
$DGatewayPSModulePath = Join-Path $PSModuleOutputPath DevolutionsGateway
$DGatewayPackage = Join-Path $TargetOutputPath $PackageFileName
echo "psmodule-output-path=$PSModuleOutputPath" >> $Env:GITHUB_OUTPUT
echo "dgateway-psmodule-output-path=$DGatewayPSModulePath" >> $Env:GITHUB_OUTPUT
echo "dgateway-package=$DGatewayPackage" >> $Env:GITHUB_OUTPUT
}
$DGatewayExecutable = Join-Path $TargetOutputPath $ExecutableFileName
echo "staging-path=$StagingPath" >> $Env:GITHUB_OUTPUT
echo "target-output-path=$TargetOutputPath" >> $Env:GITHUB_OUTPUT
echo "dgateway-executable=$DGatewayExecutable" >> $Env:GITHUB_OUTPUT
- name: Configure rust toolchain
run: rustup toolchain install ${{ needs.preflight.outputs.rust-channel }}
- name: Configure Linux runner
if: matrix.os == 'linux'
run: |
sudo apt-get update
sudo apt-get -o Acquire::Retries=3 install python3-wget python3-setuptools libsystemd-dev dh-make
# WiX is installed on Windows runners but not in the PATH
- name: Configure Windows runner
if: matrix.os == 'windows'
run: echo "C:\Program Files (x86)\WiX Toolset v3.11\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- name: Configure conan
if: matrix.os == 'windows'
run: |
pip3 install conan==${{ env.conan-version }} --upgrade
conan config install --type=git -sf settings https://github.com/Devolutions/conan-public
conan remote clean
conan remote add artifactory https://devolutions.jfrog.io/devolutions/api/conan/conan-local
- name: Build
shell: pwsh
env:
TARGET_OUTPUT_PATH: ${{ steps.load-variables.outputs.target-output-path }}
DGATEWAY_EXECUTABLE: ${{ steps.load-variables.outputs.dgateway-executable }}
CARGO_PACKAGE: devolutions-gateway
run: ./ci/tlk.ps1 build -Platform ${{ matrix.os }} -Architecture ${{ matrix.arch }} -CargoProfile ${{ needs.preflight.outputs.rust-profile }}
- name: Build PowerShell module
if: matrix.os == 'windows'
env:
PSMODULE_OUTPUT_PATH: ${{ steps.load-variables.outputs.psmodule-output-path }}
run: .\powershell\build.ps1
- name: Add msbuild to PATH
if: matrix.os == 'windows'
uses: microsoft/[email protected]
- name: Package
shell: pwsh
env:
TARGET_OUTPUT_PATH: ${{ steps.load-variables.outputs.target-output-path }}
DGATEWAY_EXECUTABLE: ${{ steps.load-variables.outputs.dgateway-executable }}
run: |
if ($Env:RUNNER_OS -eq "Windows") {
$Env:DGATEWAY_PACKAGE = "${{ steps.load-variables.outputs.dgateway-package }}"
$Env:DGATEWAY_PSMODULE_PATH = "${{ steps.load-variables.outputs.dgateway-psmodule-output-path }}"
}
./ci/tlk.ps1 package -Platform ${{ matrix.os }} -Architecture ${{ matrix.arch }} -CargoProfile ${{ needs.preflight.outputs.rust-profile }}
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: devolutions-gateway
path: ${{ steps.load-variables.outputs.staging-path }}
upload-git-log:
name: Upload git-log output
runs-on: ubuntu-20.04
if: ${{ github.ref == 'refs/heads/master' }}
needs:
- preflight
steps:
- name: Checkout ${{ github.repository }}
uses: actions/checkout@v3
with:
ref: ${{ needs.preflight.outputs.ref }}
fetch-depth: 10
- name: Generate git log
shell: pwsh
run: git log --max-count=10 > ./git-log.txt
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: git-log
path: ./git-log.txt
onedrive:
name: OneDrive
runs-on: ubuntu-20.04
if: ${{ github.ref == 'refs/heads/master' }}
needs:
- preflight
- devolutions-gateway
- jetsocat
- jetsocat-lipo
- upload-git-log
steps:
- name: Check out Devolutions/actions
uses: actions/checkout@v3
with:
repository: Devolutions/actions
ref: v1
token: ${{ secrets.DEVOLUTIONSBOT_TOKEN }}
path: ./.github/workflows
## Fetch current date and time
- name: Get current timestamp
id: timestamp
run: echo "timestamp=$(date +'%Y%m%d%H%M')" >> $GITHUB_OUTPUT
## Devolutions Toolbox is required for OneDrive uploading
- name: Install Devolutions Toolbox
uses: ./.github/workflows/toolbox-install
with:
github_token: ${{ secrets.DEVOLUTIONSBOT_TOKEN }}
## Download back the artifacts produced by the other jobs
- uses: actions/download-artifact@v3
with:
name: jetsocat
path: ${{ runner.temp }}/artifacts_raw
- uses: actions/download-artifact@v3
with:
name: devolutions-gateway
path: ${{ runner.temp }}/artifacts_raw
- uses: actions/download-artifact@v3
with:
name: git-log
path: ${{ runner.temp }}/artifacts_raw
## Do the actual upload :tada:
- name: Prepare upload
id: prepare
shell: pwsh
run: |
$version="${{ needs.preflight.outputs.version }}"
$ref="${{ needs.preflight.outputs.ref }}"
$shortRef=$ref.Substring(0, 8)
$sourceFolder = "${{ runner.temp }}/artifacts_raw"
$destinationFolder = "${{ runner.temp }}/artifacts"
Write-Host "version = $version"
Write-Host "ref = $ref"
echo "version=$version" >> $Env:GITHUB_OUTPUT
echo "short-ref=$shortRef" >> $Env:GITHUB_OUTPUT
echo "files-to-upload=$destinationFolder" >> $Env:GITHUB_OUTPUT
New-Item -Path "$destinationFolder" -ItemType "directory"
$allFiles = Get-ChildItem -Path "$sourceFolder" -Exclude PowerShell | Get-ChildItem -Recurse | Where { -Not $_.Mode.StartsWith('d') }
Write-Host
foreach ($file in $allFiles) {
$dir = $file.Directory
$name = $file.Name
$source = "$dir/$name"
$destination = "$destinationFolder/$name"
Write-Host "$source --> $destination"
Move-Item -Path "$source" -Destination "$destination"
}
- name: Upload to OneDrive
uses: ./.github/workflows/onedrive-upload
with:
azure_client_id: ${{ secrets.ONEDRIVE_AUTOMATION_CLIENT_ID }}
azure_client_secret: ${{ secrets.ONEDRIVE_AUTOMATION_CLIENT_SECRET }}
conflict_behavior: replace
destination_path: /Gateway/${{ steps.prepare.outputs.version }}-${{ steps.timestamp.outputs.timestamp }}-${{ steps.prepare.outputs.short-ref }}
remote: prereleases
source_path: ${{ steps.prepare.outputs.files-to-upload }}
dotnet-utils-tests:
name: dotnet utils tests
runs-on: windows-2022
needs: preflight
steps:
- name: Checkout ${{ github.repository }}
uses: actions/checkout@v3
with:
ref: ${{ needs.preflight.outputs.ref }}
- name: Test
shell: pwsh
run: |
Set-PSDebug -Trace 1
dotnet test utils/dotnet/GatewayUtils.sln
powershell-tests:
name: PowerShell module tests
runs-on: windows-2022
needs: preflight
steps:
- name: Checkout ${{ github.repository }}
uses: actions/checkout@v3
with:
ref: ${{ needs.preflight.outputs.ref }}
- name: Install Pester module
id: prepare
shell: pwsh
run: Install-Module Pester -Force
- name: Build module
shell: pwsh
run: |
./powershell/build.ps1
- name: Pester
shell: pwsh
run: |
./powershell/run-tests.ps1