Repository navigation
383 lines (348 loc) · 13.1 KB
/
Copy pathstackql-exec-test.yml
File metadata and controls
383 lines (348 loc) · 13.1 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
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
name: 'stackql-exec tests'
on:
push:
branches:
- main
pull_request:
jobs:
unit-tests:
strategy:
fail-fast: false
matrix:
target:
- { os: ubuntu-24.04, arch: x64 }
- { os: ubuntu-24.04-arm, arch: arm64 }
- { os: windows-2025, arch: x64 }
- { os: windows-11-arm, arch: arm64 }
- { os: macos-15-intel, arch: x64 }
- { os: macos-15, arch: arm64 }
runs-on: ${{ matrix.target.os }}
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: '24'
architecture: ${{ matrix.target.arch }}
- name: Verify native Node architecture
env:
EXPECTED_ARCH: ${{ matrix.target.arch }}
run: node -e "const assert = require('assert/strict'); assert.equal(process.arch, process.env.EXPECTED_ARCH); assert.equal(process.env.RUNNER_ARCH.toLowerCase(), process.env.EXPECTED_ARCH);"
- run: npm ci --ignore-scripts
- run: npm test -- --runInBand
smoke-tests:
name: Smoke (${{ matrix.target.os }}, ${{ matrix.install }})
runs-on: ${{ matrix.target.os }}
strategy:
fail-fast: false
matrix:
target:
- { os: ubuntu-24.04, arch: X64 }
- { os: ubuntu-24.04-arm, arch: ARM64 }
- { os: windows-2025, arch: X64 }
- { os: windows-11-arm, arch: ARM64 }
- { os: macos-15-intel, arch: X64 }
- { os: macos-15, arch: ARM64 }
install: [automatic, wrapped, plain]
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v6
- name: Verify runner and clean installation
env:
EXPECTED_ARCH: ${{ matrix.target.arch }}
run: |
test "$RUNNER_ARCH" = "$EXPECTED_ARCH"
if command -v stackql; then
echo 'Expected a runner without StackQL installed'
exit 1
fi
- name: Preinstall StackQL
if: matrix.install != 'automatic'
uses: stackql/setup-stackql@v2
with:
use_wrapper: ${{ matrix.install == 'wrapped' }}
- name: Exercise a Windows wrapper path containing spaces
if: runner.os == 'Windows' && matrix.install == 'wrapped'
uses: actions/github-script@v8
with:
script: |
const fs = require('fs');
const path = require('path');
const target = path.join(process.env.RUNNER_TEMP, 'StackQL Tools');
fs.mkdirSync(target);
for (const name of ['stackql', 'stackql-bin.exe']) {
fs.copyFileSync(path.join(process.env.STACKQL_CLI_PATH, name), path.join(target, name));
}
core.exportVariable('STACKQL_CLI_PATH', target);
core.addPath(target);
- name: Execute a multiline query
id: inline
uses: ./
with:
query: |
SELECT
'stackql smoke' AS result;
- name: Verify installation mode
env:
INSTALL_MODE: ${{ matrix.install }}
run: |
if [[ "$RUNNER_OS" == 'macOS' || "$INSTALL_MODE" == 'plain' ]]; then
test -z "${STACKQL_CLI_PATH:-}"
else
test -n "${STACKQL_CLI_PATH:-}"
fi
- name: Verify native Windows binary architecture
if: runner.os == 'Windows'
shell: pwsh
run: |
$binary = if ($env:STACKQL_CLI_PATH) {
Join-Path $env:STACKQL_CLI_PATH 'stackql-bin.exe'
} else {
(Get-Command stackql.exe).Source
}
$bytes = [IO.File]::ReadAllBytes($binary)
$pe = [BitConverter]::ToInt32($bytes, 0x3c)
$machine = [BitConverter]::ToUInt16($bytes, $pe + 4)
$expected = if ($env:RUNNER_ARCH -eq 'ARM64') { 0xaa64 } else { 0x8664 }
if ($machine -ne $expected) { throw 'Installed binary does not match runner architecture' }
- name: Verify native Linux or macOS binary architecture
if: runner.os != 'Windows'
run: |
binary="$(command -v stackql)"
if [[ -n "${STACKQL_CLI_PATH:-}" ]]; then
binary="$STACKQL_CLI_PATH/stackql-bin"
fi
if [[ "$RUNNER_OS" == 'macOS' ]]; then
arch=x86_64
if [[ "$RUNNER_ARCH" == 'ARM64' ]]; then arch=arm64; fi
lipo "$binary" -verify_arch "$arch"
else
arch='x86-64'
if [[ "$RUNNER_ARCH" == 'ARM64' ]]; then arch='ARM aarch64'; fi
file "$binary" | grep -E "ELF 64-bit.*$arch"
fi
- name: Create query and data files in a path containing spaces
id: fixtures
uses: actions/github-script@v8
with:
script: |
const fs = require('fs');
const path = require('path');
const dir = path.join(process.env.RUNNER_TEMP, 'StackQL queries');
fs.mkdirSync(dir);
const query = path.join(dir, 'query file.iql');
const data = path.join(dir, 'query data.jsonnet');
fs.writeFileSync(query, "SELECT '{{ .value }}' AS result;");
fs.writeFileSync(data, '{value: std.extVar("VALUE")}');
core.setOutput('query', query);
core.setOutput('data', data);
- name: Execute a query file with data and variables
id: file
uses: ./
with:
query_file_path: ${{ steps.fixtures.outputs.query }}
data_file_path: ${{ steps.fixtures.outputs.data }}
vars: VALUE=stackql smoke
- name: Dry run a query file with data and variables
id: dryrun
uses: ./
with:
query_file_path: ${{ steps.fixtures.outputs.query }}
data_file_path: ${{ steps.fixtures.outputs.data }}
vars: VALUE=stackql smoke
dry_run: true
- name: Execute a CSV query
id: csv
uses: ./
with:
query: SELECT 'stackql smoke' AS result;
query_output: csv
- name: Execute a table query
id: table
uses: ./
with:
query: SELECT 'stackql smoke' AS result;
query_output: table
- name: Execute a text query
id: text
uses: ./
with:
query: SELECT 'stackql smoke' AS result;
query_output: text
- name: Assert action outputs
uses: actions/github-script@v8
env:
RESULTS: ${{ toJSON(steps) }}
with:
script: |
const assert = require('assert/strict');
const steps = JSON.parse(process.env.RESULTS);
const output = id => steps[id].outputs['stackql-query-results'];
for (const id of ['inline', 'file', 'dryrun', 'csv', 'table', 'text']) {
assert.ok(output(id), `${id} returned no results`);
assert.ok(!steps[id].outputs['stackql-query-error'], `${id} returned an error`);
}
for (const id of ['inline', 'file']) {
const rows = JSON.parse(output(id));
assert.equal(rows.length, 1);
const value = rows[0].result;
if (value !== null && typeof value === 'object') {
assert.deepEqual(value, {String: 'stackql smoke', Valid: true});
} else {
assert.equal(value, 'stackql smoke');
}
}
assert.deepEqual(JSON.parse(output('dryrun')), [{query: "SELECT 'stackql smoke' AS result;"}]);
for (const id of ['csv', 'text']) {
assert.equal(output(id).replace(/\r\n/g, '\n').trim(), 'result\nstackql smoke');
}
assert.match(output('table'), /\|\s*result\s*\|/);
assert.match(output('table'), /\|\s*stackql smoke\s*\|/);
stackql-exec-google-example:
strategy:
fail-fast: false
matrix:
os: [ubuntu-24.04, ubuntu-24.04-arm, windows-2025, windows-11-arm, macos-15-intel, macos-15]
runs-on: ${{matrix.os}}
name: 'StackQL exec Google '
steps:
- name: Checkout
uses: actions/checkout@v6
#
# run a query that does not return data (using the `is_command` input)
#
- name: pull providers
id: stackql-command
uses: ./
with:
is_command: true
query: "REGISTRY PULL github;
REGISTRY PULL google;"
#
# run a query using the `query` input
#
- name: github query example using the query input
id: stackql-query
uses: ./
with:
query: |
select visibility, count(*) as number_of_repos
from github.repos.repos
where org = 'stackql'
group by visibility
env:
STACKQL_GITHUB_USERNAME: ${{ secrets.STACKQL_GITHUB_USERNAME }}
STACKQL_GITHUB_PASSWORD: ${{ secrets.STACKQL_GITHUB_PASSWORD }}
# `csv` output
- name: github query example using the query input (csv output)
id: stackql-query-csv-output
uses: ./
with:
query_output: csv
query: |
select visibility, count(*) as number_of_repos
from github.repos.repos
where org = 'stackql'
group by visibility
env:
STACKQL_GITHUB_USERNAME: ${{ secrets.STACKQL_GITHUB_USERNAME }}
STACKQL_GITHUB_PASSWORD: ${{ secrets.STACKQL_GITHUB_PASSWORD }}
# `table` output
- name: github query example using the query input (table output)
id: stackql-query-table-output
uses: ./
with:
query_output: table
query: |
select visibility, count(*) as number_of_repos
from github.repos.repos
where org = 'stackql'
group by visibility
env:
STACKQL_GITHUB_USERNAME: ${{ secrets.STACKQL_GITHUB_USERNAME }}
STACKQL_GITHUB_PASSWORD: ${{ secrets.STACKQL_GITHUB_PASSWORD }}
# `text` output
- name: github query example using the query input (text output)
id: stackql-query-text-output
uses: ./
with:
query_output: text
query: |
select visibility, count(*) as number_of_repos
from github.repos.repos
where org = 'stackql'
group by visibility
env:
STACKQL_GITHUB_USERNAME: ${{ secrets.STACKQL_GITHUB_USERNAME }}
STACKQL_GITHUB_PASSWORD: ${{ secrets.STACKQL_GITHUB_PASSWORD }}
#
# run a query using the `query_file_path` input
#
- name: google query example with query file
id: stackql-query-file
uses: ./
with:
query_file_path: './stackql_scripts/google-instances-by-status.iql'
env:
GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}
#
# run a query using the `query_file_path` and `vars` inputs
#
- name: google query example with query file using vars
id: stackql-query-file-with-vars
uses: ./
with:
query_file_path: './stackql_scripts/google-instances-by-status-with-inline-jsonnet-block.iql'
vars: GOOGLE_PROJECT=${{ env.GOOGLE_PROJECT }},GOOGLE_ZONE=${{ env.GOOGLE_ZONE }}
env:
GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}
GOOGLE_PROJECT: ${{ vars.GOOGLE_PROJECT }}
GOOGLE_ZONE: ${{ vars.GOOGLE_ZONE }}
#
# run a query using the `query_file_path`, `data_file_path` and `vars` inputs (dry-run)
#
- name: google query example with query file and data file using vars (dry-run)
id: stackql-query-file-with-data-file-and-vars-dry-run
uses: ./
with:
query_file_path: './stackql_scripts/google-instances-by-status-with-external-data-file.iql'
data_file_path: './stackql_scripts/google-instances-by-status-with-external-data-file.jsonnet'
vars: GOOGLE_PROJECT=${{ env.GOOGLE_PROJECT }},GOOGLE_ZONE=${{ env.GOOGLE_ZONE }}
dry_run: true
env:
GOOGLE_PROJECT: ${{ vars.GOOGLE_PROJECT }}
GOOGLE_ZONE: ${{ vars.GOOGLE_ZONE }}
#
# run a query using the `query_file_path`, `data_file_path` and `vars` inputs
#
- name: google query example with query file and data file using vars
id: stackql-query-file-with-data-file-and-vars
uses: ./
with:
query_file_path: './stackql_scripts/google-instances-by-status-with-external-data-file.iql'
data_file_path: './stackql_scripts/google-instances-by-status-with-external-data-file.jsonnet'
vars: GOOGLE_PROJECT=${{ env.GOOGLE_PROJECT }},GOOGLE_ZONE=${{ env.GOOGLE_ZONE }}
env:
GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}
GOOGLE_PROJECT: ${{ vars.GOOGLE_PROJECT }}
GOOGLE_ZONE: ${{ vars.GOOGLE_ZONE }}
- name: validate stackql outputs
shell: bash
run: |
echo "stackql-command:"
echo "${{ steps.stackql-command.outputs.stackql-command-output }}"
echo "stackql-query:"
echo "${{ steps.stackql-query.outputs.stackql-query-results }}"
echo "stackql-query-csv-output:"
echo "${{ steps.stackql-query-csv-output.outputs.stackql-query-results }}"
echo "stackql-query-table-output:"
echo "${{ steps.stackql-query-table-output.outputs.stackql-query-results }}"
echo "stackql-query-text-output:"
echo "${{ steps.stackql-query-text-output.outputs.stackql-query-results }}"
echo "stackql-query-file:"
echo "${{ steps.stackql-query-file.outputs.stackql-query-results }}"
echo "stackql-query-file-with-vars:"
echo "${{ steps.stackql-query-file-with-vars.outputs.stackql-query-results }}"
echo "stackql-query-file-with-data-file-and-vars:"
echo "${{ steps.stackql-query-file-with-data-file-and-vars.outputs.stackql-query-results }}"