Skip to content

Commit a6155a6

Browse files
authored
Merge pull request #23 from stackql/feature/updates
use stackql-exec
2 parents 457ac31 + 817a6db commit a6155a6

File tree

7 files changed

+147
-319
lines changed

7 files changed

+147
-319
lines changed

.github/workflows/stackql-assert.yml renamed to .github/workflows/stackql-assert-test.yml

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: 'StackQL Assert'
1+
name: 'stackql-assert'
22

33
on:
44
push:
@@ -15,7 +15,16 @@ jobs:
1515

1616
steps:
1717
- name: Checkout
18-
uses: actions/checkout@v3
18+
uses: actions/[email protected]
19+
20+
#
21+
# Pull required providers
22+
#
23+
- name: pull required providers
24+
uses: stackql/[email protected]
25+
with:
26+
is_command: true
27+
query: "REGISTRY PULL google; REGISTRY PULL github"
1928

2029
#
2130
# Example `test_query` with `expected_rows`
@@ -24,7 +33,6 @@ jobs:
2433
uses: ./
2534
with:
2635
test_query: |
27-
REGISTRY PULL google;
2836
SELECT name
2937
FROM google.compute.instances
3038
WHERE project = 'stackql-demo' AND zone = 'australia-southeast1-a' AND name = 'stackql-demo-001';

.github/workflows/test.yml

-18
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
REGISTRY PULL github;
21
SELECT name FROM github.repos.repos WHERE org = '{{ .org }}' AND name = '{{ .repo }}';

README.md

+14-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
1+
[![StackQL Assert](https://github.com/stackql/stackql-assert/actions/workflows/stackql-assert-test.yml/badge.svg)](https://github.com/stackql/stackql-assert/actions/workflows/stackql-assert-test.yml)
2+
13
# stackql-assert
24

35
The `stackql/stackql-assert` action is an composite action that runs a `stackql` query and checks if the result matches an expected result
46

57
# Usage
68

9+
> This action uses the [setup-stackql](https://github.com/marketplace/actions/stackql-studios-setup-stackql) and [stackql-exec](https://github.com/marketplace/actions/stackql-studios-stackql-exec) actions
10+
711
## Provider Authentication
812
Authentication to StackQL providers is done via environment variables source from GitHub Actions Secrets. To learn more about authentication, see the setup instructions for your provider or providers at the [StackQL Provider Registry Docs](https://stackql.io/registry).
913

1014
## Inputs
11-
- `test_query` - stackql query to execute **(need to supply either `test_query` or `test_query_file_path`)**
12-
- `test_query_file_path` - stackql query file to execute **(need to supply either `test_query` or `test_query_file_path`)**
13-
- `data_file_path` - (optional) path to data file to pass to the stackql query preprocessor (`json` or `jsonnet`)
14-
- `vars` - (optional) comma delimited list of variables to pass to the stackql query preprocessor (supported with `jsonnet` config blocks or `jsonnet` data files only), accepts `var1=val1,var2=val2`, can be used to source environment variables into stackql queries
15-
- `expected_rows` - (optional) Expected number of rows in the result.
16-
- `expected_results_str` - (optional) Expected result (`json`) from executing test query, support object string (overrides `expected_results_file_path`)
17-
- `expected_results_file_path` - (optional) Results file (`json`) that stores expected result, json is support
18-
- `auth_obj_path` - (optional) the path of json file that stores stackql AUTH string **(only required when using non-standard environment variable names)**
19-
- `auth_str` - (optional) stackql AUTH string **(only required when using non-standard environment variable names)**
15+
- **`test_query`** - stackql query to execute *(need to supply either `test_query` or `test_query_file_path`)*
16+
- **`test_query_file_path`** - stackql query file to execute *(need to supply either `test_query` or `test_query_file_path`)*
17+
- **`data_file_path`** - (optional) path to data file to pass to the stackql query preprocessor (`json` or `jsonnet`)
18+
- **`vars`** - (optional) comma delimited list of variables to pass to the stackql query preprocessor (supported with `jsonnet` config blocks or `jsonnet` data files only), accepts `var1=val1,var2=val2`, can be used to source environment variables into stackql queries
19+
- **`expected_rows`** - (optional) Expected number of rows in the result.
20+
- **`expected_results_str`** - (optional) Expected result (`json`) from executing test query, support object string (overrides `expected_results_file_path`)
21+
- **`expected_results_file_path`** - (optional) Results file (`json`) that stores expected result, json is support
22+
- **`auth_obj_path`** - (optional) the path of json file that stores stackql AUTH string *(only required when using non-standard environment variable names)*
23+
- **`auth_str`** - (optional) stackql AUTH string *(only required when using non-standard environment variable names)*
2024

2125
**__NOTE:__ one of `expected_rows`, `expected_results_str` or `expected_results_file_path` is required**
2226

@@ -28,7 +32,7 @@ Authentication to StackQL providers is done via environment variables source fro
2832
## Expected Result
2933
- Use `expected_results_str` or `expected_results_file_path` or `expected_rows` to pass the expected result to the action. The expected result (`expected_results_str` or `expected_results_file_path`) should be a valid `json` object. The action will compare the result with the expected result. If the result is not the same as the expected result, the action will fail the step.
3034
- Either `expected_results_str` or `expected_results_file_path` or `expected_rows` are required. If `expected_results_str` and `expected_results_file_path` are provided, `expected_results_str` will be used.
31-
- Expected result example can be found in [example workflow](./.github/workflows/stackql-assert.yml) and [example .json file](./.github/workflows/workflow_scripts)
35+
- Expected result example can be found in [example workflow](./.github/workflows/stackql-assert-test.yml) and [example .json file](./.github/workflows/workflow_scripts)
3236

3337
## Examples
3438
The following excerpts from a GitHub Actions workflow demonstrate how to use the `stackql/stackql-assert` action.
@@ -40,7 +44,6 @@ The following excerpts from a GitHub Actions workflow demonstrate how to use the
4044
uses: ./
4145
with:
4246
test_query: |
43-
REGISTRY PULL google;
4447
SELECT name
4548
FROM google.compute.instances
4649
WHERE project = 'stackql-demo' AND zone = 'australia-southeast1-a' AND name = 'stackql-demo-001';

action.yml

+31-82
Original file line numberDiff line numberDiff line change
@@ -1,120 +1,69 @@
11
name: 'StackQL Studios - StackQL Assert'
2-
description: 'run StackQL query to test and audit your infrastructure.'
2+
description: 'Run StackQL query to test and audit your infrastructure.'
33
author: 'Yuncheng Yang, StackQL Studios'
44
inputs:
55
test_query:
6-
description: stackql query to execute (need to supply either test_query or test_query_file_path)
6+
description: 'StackQL query to execute (supply either test_query or test_query_file_path)'
77
required: false
88
test_query_file_path:
9-
description: stackql query file to execute (need to supply either test_query or test_query_file_path)
9+
description: 'StackQL query file to execute (supply either test_query or test_query_file_path)'
1010
required: false
1111
data_file_path:
12-
description: path to data file to pass to the stackql query preprocessor (json or jsonnet file)
12+
description: 'Path to data file to pass to the StackQL query preprocessor (JSON or Jsonnet file)'
1313
required: false
1414
vars:
15-
description: comma delimited list of variables to pass to the stackql query preprocessor (supported with jsonnet config blocks or jsonnet data files only), accepts 'var1=val1,var2=val2', can be used to source environment variables into stackql queries
15+
description: 'Comma delimited list of variables to pass to the StackQL query preprocessor (supported with Jsonnet config blocks or Jsonnet data files only)'
1616
required: false
17-
expected_rows:
18-
description: expected number of rows from executing test query
17+
expected_rows:
18+
description: 'Expected number of rows from executing test query'
1919
required: false
2020
expected_results_str:
21-
description: expected result (as a json string) from executing test query, overrides expected_results_file_path
21+
description: 'Expected result (as a JSON string) from executing test query, overrides expected_results_file_path'
2222
required: false
2323
expected_results_file_path:
24-
description: json file with the expected result
24+
description: 'JSON file with the expected result'
2525
required: false
2626
auth_obj_path:
27-
description: the path of json file that stores stackql AUTH string (only required when using non-standard environment variable names)
27+
description: 'Path of JSON file that stores StackQL AUTH string (only required when using non-standard environment variable names)'
2828
required: false
2929
auth_str:
30-
description: stackql AUTH string (only required when using non-standard environment variable names)
30+
description: 'StackQL AUTH string (only required when using non-standard environment variable names)'
3131
required: false
3232

3333
runs:
3434
using: "composite"
3535
steps:
36-
- name: check if stackql is installed and set output
37-
id: check-stackql
38-
shell: bash
39-
run: |
40-
if command -v stackql &> /dev/null; then
41-
echo "stackql_installed=true" >> $GITHUB_OUTPUT
42-
else
43-
echo "stackql_installed=false" >> $GITHUB_OUTPUT
44-
fi
45-
46-
- name: setup stackql
47-
uses: stackql/[email protected]
48-
if: ${{steps.check-stackql.outputs.stackql_installed == 'false'}}
36+
- name: Setup StackQL
37+
uses: stackql/[email protected]
4938
with:
5039
use_wrapper: true
5140

52-
- name: setup auth
53-
if: (inputs.auth_obj_path != '') || (inputs.auth_str != '')
54-
id: setup-auth
55-
uses: actions/github-script@v6
56-
with:
57-
script: |
58-
const path = require('path');
59-
const utilsPath = path.join(process.env.GITHUB_ACTION_PATH, 'lib', 'utils.js')
60-
const {setupAuth} = require(utilsPath)
61-
setupAuth(core)
62-
env:
63-
AUTH_FILE_PATH: ${{ inputs.auth_obj_path }}
64-
AUTH_STR: ${{inputs.auth_str}}
65-
66-
- name: get stackql command
67-
uses: actions/github-script@v6
68-
with:
69-
script: |
70-
const path = require('path');
71-
const utilsPath = path.join(process.env.GITHUB_ACTION_PATH, 'lib', 'utils.js')
72-
const {getStackqlCommand} = require(utilsPath)
73-
getStackqlCommand(core)
74-
env:
75-
QUERY_FILE_PATH: ${{ inputs.test_query_file_path }}
76-
QUERY: ${{inputs.test_query}}
77-
DATA_FILE_PATH: ${{inputs.data_file_path}}
78-
VARS: ${{inputs.vars}}
79-
OUTPUT: 'json'
80-
81-
- name: dryrun stackql command
82-
id: dryrun-query
83-
shell: bash
84-
run: |
85-
${{ env.STACKQL_DRYRUN_COMMAND }}
86-
87-
- name: show rendered stackql query
88-
uses: actions/github-script@v6
41+
- name: Execute StackQL Command
42+
id: exec-query
43+
uses: stackql/[email protected]
8944
with:
90-
script: |
91-
const path = require('path');
92-
const utilsPath = path.join(process.env.GITHUB_ACTION_PATH, 'lib', 'utils.js')
93-
const {showStackQLQuery} = require(utilsPath)
94-
showStackQLQuery(core)
95-
env:
96-
DRYRUN_RESULT: ${{steps.dryrun-query.outputs.stdout}}
45+
query: ${{ inputs.test_query }}
46+
query_file_path: ${{ inputs.test_query_file_path }}
47+
data_file_path: ${{ inputs.data_file_path }}
48+
vars: ${{ inputs.vars }}
49+
auth_obj_path: ${{ inputs.auth_obj_path }}
50+
auth_str: ${{ inputs.auth_str }}
51+
dry_run: false
9752

98-
- name: execute stackql command
99-
id: exec-query
100-
shell: bash
101-
run: |
102-
${{ env.STACKQL_COMMAND }}
103-
104-
- name: Check results
105-
uses: actions/github-script@v6
53+
- name: Check Results
54+
uses: actions/[email protected]
10655
with:
10756
script: |
10857
const path = require('path');
109-
const assertPath = path.join(process.env.GITHUB_ACTION_PATH, 'stackql-assert.js')
58+
const assertPath = path.join(process.env.GITHUB_ACTION_PATH, 'lib', 'assert.js')
11059
const {assertResult} = require(assertPath)
11160
assertResult(core)
11261
env:
113-
RESULT: ${{steps.exec-query.outputs.stdout}}
62+
RESULT: ${{ steps.exec-query.outputs.stackql-query-results }}
11463
EXPECTED_RESULTS_STR: ${{ inputs.expected_results_str }}
115-
EXPECTED_RESULTS_FILE_PATH: ${{inputs.expected_results_file_path}}
116-
EXPECTED_ROWS: ${{inputs.expected_rows}}
117-
64+
EXPECTED_RESULTS_FILE_PATH: ${{ inputs.expected_results_file_path }}
65+
EXPECTED_ROWS: ${{ inputs.expected_rows }}
66+
11867
branding:
11968
icon: 'terminal'
120-
color: 'green'
69+
color: 'green'

0 commit comments

Comments
 (0)