-
Notifications
You must be signed in to change notification settings - Fork 8
347 lines (313 loc) · 10.7 KB
/
Copy pathtest.yml
File metadata and controls
347 lines (313 loc) · 10.7 KB
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
name: Test
on:
push:
workflow_dispatch: {}
permissions:
contents: read
concurrency:
group: test-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
lint-shell:
name: Lint shell
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
persist-credentials: false
- name: Syntax check
run: |
bash -n scripts/setup.sh
sh -n installer/install.sh
- name: Install ShellCheck
run: sudo apt-get update && sudo apt-get install -y shellcheck
- name: ShellCheck
run: |
shellcheck --severity=style scripts/setup.sh
shellcheck --shell=sh --severity=style installer/install.sh
lint-powershell:
name: Lint PowerShell
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
persist-credentials: false
- name: Install PSScriptAnalyzer
shell: pwsh
run: Install-Module -Name PSScriptAnalyzer -Scope CurrentUser -Force -SkipPublisherCheck
- name: PSScriptAnalyzer
shell: pwsh
run: |
Invoke-ScriptAnalyzer -Path scripts/setup.ps1 -Settings PSGallery -EnableExit
Invoke-ScriptAnalyzer -Path installer/install.ps1 -Settings PSGallery -EnableExit
- name: AST parse check
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
foreach ($file in @("scripts/setup.ps1", "installer/install.ps1")) {
$tokens = $null
$errors = $null
[void][System.Management.Automation.Language.Parser]::ParseFile($file, [ref]$tokens, [ref]$errors)
if ($errors.Count -gt 0) {
foreach ($e in $errors) {
Write-Error "${file}: $e"
}
throw "AST parse errors found"
}
Write-Output "OK: $file"
}
installer-drift:
name: Vendored installer drift check
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
persist-credentials: false
- name: Verify vendored installer checksums
working-directory: installer
run: |
test -s VERSION
sha256sum -c SHA256SUMS
test-install:
name: Install (${{ matrix.os }})
permissions:
contents: read
id-token: write # required whenever OIDC inputs are set
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- ubuntu-24.04-arm
- macos-latest
- windows-latest
runs-on: ${{ matrix.os }}
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
persist-credentials: false
# OIDC inputs only configure environment variables; no token exchange
# happens until an authenticated CLI command runs, so placeholder
# values are enough to test the install path without secrets.
- name: Install Cloudsmith CLI
id: setup
uses: ./
with:
oidc-namespace: placeholder-namespace
oidc-service-slug: placeholder-service
- name: Check installation
shell: bash
env:
OUTPUT_CLI_VERSION: ${{ steps.setup.outputs.cli-version }}
OUTPUT_TARGET: ${{ steps.setup.outputs.target }}
OUTPUT_CLI_PATH: ${{ steps.setup.outputs.cli-path }}
OUTPUT_BIN_DIRECTORY: ${{ steps.setup.outputs.bin-directory }}
run: |
set -euo pipefail
command -v cloudsmith
cloudsmith --version
test -n "$OUTPUT_CLI_VERSION"
test -n "$OUTPUT_TARGET"
test -n "$OUTPUT_CLI_PATH"
test -n "$OUTPUT_BIN_DIRECTORY"
cloudsmith --version | tr -d '\r' | grep -Fx "CLI Package Version: $OUTPUT_CLI_VERSION"
- name: Check exported environment
shell: bash
run: |
set -euo pipefail
test "$CLOUDSMITH_ORG" = "placeholder-namespace"
test "$CLOUDSMITH_SERVICE_SLUG" = "placeholder-service"
test "$CLOUDSMITH_OIDC_AUDIENCE" = "https://github.com/$GITHUB_REPOSITORY_OWNER"
test-pinned-version:
name: Install pinned version
permissions:
contents: read
id-token: write # required whenever OIDC inputs are set
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
persist-credentials: false
- name: Install Cloudsmith CLI
id: setup
uses: ./
with:
# Latest version published to the pre-release test repository.
# Bump to the first production release when the vendored installer
# is updated to point at the production repository.
cli-version: "1.20.1"
install-directory: ${{ github.workspace }}/.cloudsmith-cli
oidc-namespace: placeholder-namespace
oidc-service-slug: placeholder-service
oidc-audience: test-audience
- name: Check installation
shell: bash
env:
OUTPUT_CLI_VERSION: ${{ steps.setup.outputs.cli-version }}
OUTPUT_CLI_PATH: ${{ steps.setup.outputs.cli-path }}
run: |
set -euo pipefail
test "$OUTPUT_CLI_VERSION" = "1.20.1"
case "$OUTPUT_CLI_PATH" in
"$GITHUB_WORKSPACE/.cloudsmith-cli/"*) ;;
*) echo "unexpected cli-path: $OUTPUT_CLI_PATH"; exit 1 ;;
esac
test "$CLOUDSMITH_OIDC_AUDIENCE" = "test-audience"
cloudsmith --version | tr -d '\r' | grep -Fx "CLI Package Version: 1.20.1"
test-input-validation:
name: Input validation
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
persist-credentials: false
- name: No authentication inputs should fail
id: no-auth
continue-on-error: true
uses: ./
- name: Incomplete OIDC pair should fail
id: partial-oidc
continue-on-error: true
uses: ./
with:
oidc-namespace: placeholder-namespace
- name: verify-auth with a bad API key should fail
id: bad-key
continue-on-error: true
uses: ./
with:
api-key: placeholder-invalid-key
verify-auth: "true"
- name: Check outcomes
env:
NO_AUTH_OUTCOME: ${{ steps.no-auth.outcome }}
PARTIAL_OIDC_OUTCOME: ${{ steps.partial-oidc.outcome }}
BAD_KEY_OUTCOME: ${{ steps.bad-key.outcome }}
run: |
set -euo pipefail
test "$NO_AUTH_OUTCOME" = "failure"
test "$PARTIAL_OIDC_OUTCOME" = "failure"
test "$BAD_KEY_OUTCOME" = "failure"
auth-gate:
name: Check auth test configuration
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
has-api-key: ${{ steps.check.outputs.has-api-key }}
steps:
- name: Check secrets
id: check
env:
API_KEY: ${{ secrets.CLOUDSMITH_API_KEY }}
run: |
if [ -n "$API_KEY" ]; then
echo "has-api-key=true" >> "$GITHUB_OUTPUT"
else
echo "has-api-key=false" >> "$GITHUB_OUTPUT"
fi
test-auth-api-key:
name: API key auth (${{ matrix.os }})
needs: auth-gate
if: needs.auth-gate.outputs.has-api-key == 'true'
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
export-auth-token: "true"
oidc-auth-only: "false"
# Exercise the deprecated alias as well as the preferred input.
- os: macos-latest
export-auth-token: "false"
oidc-auth-only: "true"
- os: windows-latest
export-auth-token: "true"
oidc-auth-only: "false"
runs-on: ${{ matrix.os }}
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
persist-credentials: false
- name: Install and authenticate
id: setup
uses: ./
with:
api-key: ${{ secrets.CLOUDSMITH_API_KEY }}
export-auth-token: ${{ matrix.export-auth-token }}
oidc-auth-only: ${{ matrix.oidc-auth-only }}
verify-auth: "true"
- name: Check exported token
shell: bash
env:
EXPECTED_API_KEY: ${{ secrets.CLOUDSMITH_API_KEY }}
OUTPUT_TOKEN: ${{ steps.setup.outputs.oidc-token }}
run: |
set -euo pipefail
test "$CLOUDSMITH_API_KEY" = "$EXPECTED_API_KEY"
test "$CLOUDSMITH_USERNAME" = "token"
test "$OUTPUT_TOKEN" = "$EXPECTED_API_KEY"
- name: whoami from PATH
shell: bash
run: cloudsmith whoami
test-auth-oidc:
name: OIDC auth (${{ matrix.os }})
if: vars.CLOUDSMITH_NAMESPACE != '' && vars.CLOUDSMITH_SERVICE_SLUG != ''
permissions:
contents: read
id-token: write # the CLI exchanges the ID token for a Cloudsmith token
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
export-auth-token: "true"
oidc-auth-only: "false"
# Exercise the deprecated alias as well as the preferred input.
- os: macos-latest
export-auth-token: "false"
oidc-auth-only: "true"
- os: windows-latest
export-auth-token: "true"
oidc-auth-only: "false"
runs-on: ${{ matrix.os }}
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
persist-credentials: false
- name: Install and authenticate
id: setup
uses: ./
with:
oidc-namespace: ${{ vars.CLOUDSMITH_NAMESPACE }}
oidc-service-slug: ${{ vars.CLOUDSMITH_SERVICE_SLUG }}
export-auth-token: ${{ matrix.export-auth-token }}
oidc-auth-only: ${{ matrix.oidc-auth-only }}
verify-auth: "true"
- name: Check exported token
shell: bash
env:
OUTPUT_TOKEN: ${{ steps.setup.outputs.oidc-token }}
run: |
set -euo pipefail
test -n "$OUTPUT_TOKEN"
test "$CLOUDSMITH_API_KEY" = "$OUTPUT_TOKEN"
test "$CLOUDSMITH_USERNAME" = "token"
- name: whoami from PATH
shell: bash
run: cloudsmith whoami