-
Notifications
You must be signed in to change notification settings - Fork 8
211 lines (184 loc) · 6.68 KB
/
.common.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
on:
workflow_call:
inputs:
packages:
description: Packages (comma-separated values)
type: string
default: ${{ github.workflow }}
test:
description: Test update
type: boolean
force:
description: Force update
type: boolean
cleanup:
description: Optional cleanup script to run at the beginning of tests
type: string
uninstall:
description: Uninstall package
type: boolean
default: true
test_cases:
description: |
List of test cases
- {one-line script}
- {title}
{multi-line script}
type: string
jobs:
update:
name: Update ${{ github.workflow }}
runs-on: windows-latest
timeout-minutes: 20
env:
# Set au version to use or omit to use the latest. Specify branch name to use development version from Github
au_version: release
steps:
- name: Set up git
if: ${{ !inputs.test }}
run: |
git config --global user.name "GitHub Actions Bot"
git config --global user.email "<>"
git config --global core.safecrlf false
- name: Checkout
uses: actions/checkout@v4
- name: Install AU
run: |
git clone -q https://github.com/Thilas/chocolatey-au.git -b release "$env:TEMP/au"
. "$env:TEMP/au/scripts/Install-AU.ps1" $env:au_version
- name: Update packages
id: updates
run: |
"Chocolatey v$(choco --version)"
$names = $env:packages -replace " ","" -split ","
$force = $env:force -eq "true"
[array] $packages = ./update_all.ps1 -Name $names -Force:$force | ForEach-Object {
$_ | ConvertTo-Json -Compress
}
$packagesJson = ConvertTo-Json $packages -Compress
"Packages = $packagesJson"
if ($force -and $names.Length -ne $packages.Length) {
throw "Some expected packages were not updated."
}
"packages=$packagesJson" >> $env:GITHUB_OUTPUT
env:
packages: ${{ inputs.packages }}
force: ${{ inputs.test || inputs.force }}
github_user_repo: ${{ github.repository }}
github_api_key: ${{ secrets.GITHUB_TOKEN }}
au_push: ${{ !inputs.test }}
api_key: ${{ secrets.CHOCOLATEY_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish report
if: ${{ always() && hashFiles('report.md') }}
run: Get-Content "report.md" >> $env:GITHUB_STEP_SUMMARY
- name: Prepare Packages artifact
if: ${{ always() && hashFiles('**/*.nupkg') }}
run: |
New-Item Packages -ItemType Directory
Get-ChildItem *.nupkg -Recurse | Move-Item -Destination Packages
- name: Upload Packages artifact
if: ${{ always() && hashFiles('Packages/*.nupkg') }}
uses: actions/upload-artifact@v4
with:
name: Packages
path: Packages/*.nupkg
- name: Upload Test artifact
if: ${{ hashFiles('Packages/*.nupkg') }}
uses: actions/upload-artifact@v4
with:
name: Test
path: test.ps1
outputs:
updates: ${{ steps.updates.outputs.packages }}
test:
needs: [update]
if: ${{ needs.update.outputs.updates != 'null' }}
strategy:
fail-fast: false
matrix:
package: ${{ fromJSON(needs.update.outputs.updates) }}
os:
- windows-2019
# - windows-2022
name: Test ${{ fromJSON(matrix.package).name }} ${{ fromJSON(matrix.package).version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
timeout-minutes: 20
env:
package_name: ${{ fromJSON(matrix.package).name }}
package_version: ${{ fromJSON(matrix.package).version }}
steps:
- name: Cleanup environment
run: |
"Chocolatey v$(choco --version)"
choco list --exact --limit-output $env:package_name | Tee-Object -Variable installed
if ($installed) {
choco uninstall -y --no-progress $env:package_name
}
if ($env:cleanup) {
Invoke-Expression $env:cleanup
}
env:
cleanup: ${{ inputs.cleanup }}
- name: Download Packages artifact
uses: actions/download-artifact@v4
with:
name: Packages
- name: Download Test artifact
uses: actions/download-artifact@v4
with:
name: Test
- name: Tests before install
if: ${{ inputs.test_cases }}
run: ./test.ps1 -Inverse
env:
test_cases: ${{ inputs.test_cases }}
screenshot_prefix: desktop
- name: Install package
run: |
$debug = if ($env:RUNNER_DEBUG) { "--verbose --debug" }
choco install -y --no-progress $env:package_name --version $env:package_version --source "'.;https://community.chocolatey.org/api/v2/'" $debug
if ($LASTEXITCODE -in 1641, 3010) { exit 0 }
timeout-minutes: 10
- name: Determine package information path
id: information
run: |
$path = Join-Path $env:ChocolateyInstall ".chocolatey/$env:package_name.$env:package_version"
$path = $path -replace "\\", "/"
Get-ChildItem $path
"path=$path" >> $env:GITHUB_OUTPUT
- name: Upload Information artifact
uses: actions/upload-artifact@v4
with:
name: Information ${{ env.package_name }} ${{ env.package_version }} on ${{ matrix.os }}
path: ${{ steps.information.outputs.path }}
- name: Tests after install
if: ${{ inputs.test_cases }}
run: ./test.ps1
env:
test_cases: ${{ inputs.test_cases }}
screenshot_prefix: desktop
- name: Uninstall package
if: ${{ inputs.uninstall }}
run: |
$debug = if ($env:RUNNER_DEBUG) { "--verbose --debug" }
choco uninstall -y --no-progress --remove-dependencies $env:package_name $debug
if ($LASTEXITCODE -in 1605, 1614, 1641, 3010) { exit 0 }
timeout-minutes: 10
- name: Tests after uninstall
if: ${{ inputs.test_cases }}
run: ./test.ps1 -Inverse
env:
test_cases: ${{ inputs.test_cases }}
screenshot_prefix: desktop
- name: Take failure screenshot
if: ${{ failure() }}
run: |
choco install -y --no-progress nircmd
nircmd savescreenshotfull desktop.png
- name: Upload failure screenshot into Information artifact
if: ${{ failure() }}
uses: actions/upload-artifact@v4
with:
name: Information ${{ env.package_name }} ${{ env.package_version }} on ${{ matrix.os }}
path: desktop*.png