-
Notifications
You must be signed in to change notification settings - Fork 74
92 lines (85 loc) · 3.58 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
name: CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
check_nuspec:
runs-on: windows-2016
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Get changed files
id: files
uses: Ana06/get-changed-files@v2.1.0
with:
filter: 'packages/*/**'
- name: Check nuspec is modified for every modified package
# It runs only if there are modified files
if: steps.files.outputs.added_modified != ''
run: |
$changed_files = "${{ steps.files.outputs.added_modified }}".Split(" ")
$nuspecs = [string]@($changed_files | where { $_ -Like "*.nuspec" })
$others = @($changed_files | where { $_ -NotLike "*.nuspec" })
foreach ($file in $others) {
if ($file -match "packages/[^/]*") {
$package = $matches.0
if (!$nuspecs.contains($package)) {
Write-Error "The version in $package needs to be modified"
}
}
}
build_test_upload:
runs-on: ${{ matrix.os }}
needs: [check_nuspec]
strategy:
fail-fast: false
matrix:
os: [windows-2016, windows-2019, windows-2022]
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Get changed files
id: files
uses: Ana06/get-changed-files@v2.0.0
with:
filter: '*.nuspec'
- name: Build all modified packages into built_pkgs
id: build
# It runs only if there are modified files
if: steps.files.outputs.added_modified != ''
run: |
$root = Get-Location
$built_pkgs_dir = New-Item -ItemType Directory built_pkgs
$changed_files = "${{ steps.files.outputs.added_modified }} packages\common.vm\common.vm.nuspec".Split(" ")
foreach ($changed_file in $changed_files) {
Set-Location (Split-Path $root\$changed_file -Parent)
choco pack -out $built_pkgs_dir
if ($LASTEXITCODE -ne 0) { Exit 1 } # Abort with the first failing build
}
- name: Test all built packages
id: test
# Do not test if build was skipped
if: steps.build.outcome == 'success'
run: |
# https://github.com/chocolatey/choco/blob/5868c66a2a4ef104f92d11ec638066eac2570783/src/chocolatey/infrastructure.app/services/PowershellService.cs#L309
$validExitCodes = @(0, 1605, 1614, 1641, 3010)
$built_pkgs = Get-ChildItem built_pkgs | Foreach-Object {( [regex]::match($_.BaseName, '(.*?[.](?:vm)).*').Groups[1].Value)}
Set-Location built_pkgs
choco install common.vm -s .
foreach ($package in $built_pkgs) {
choco install $package -s "'.;https://www.myget.org/F/vm-packages/api/v2;https://community.chocolatey.org/api/v2/'" --no-progress
if ($validExitCodes -notcontains $LASTEXITCODE) { Exit 1 } # Abort with the first failing install
}
Exit 0
- name: Push all built packages to MyGet
# Only push packages on master if they were built (not if testing was skipped) and
# only with one version of Windows (otherwise it would be pushed 3 times)
if: steps.test.outcome == 'success' && github.event_name == 'push' && matrix.os == 'windows-2019'
run: |
$built_pkgs = Get-ChildItem built_pkgs
Set-Location built_pkgs
foreach ($package in $built_pkgs) {
cpush -s "https://www.myget.org/F/vm-packages/api/v2" -k ${{ secrets.MYGET_TOKEN }} $package
}