Skip to content

Commit d6eefab

Browse files
Merge pull request #11 from stackql/feat/update-readme-and-test-query-validation
updated README and change the execute.sh
2 parents 9862c42 + f9f9f14 commit d6eefab

File tree

3 files changed

+58
-6
lines changed

3 files changed

+58
-6
lines changed

README.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,48 @@
11
# stackql-assert
2-
Runs a unit test with a command, comparing the expected output with the actual output.
2+
3+
The `stackql/stackql-assert` action is a JavaScript action that sets up StackQL CLI in your GitHub Actions workflow by:
4+
5+
- Downloading a latest Stackql CLI and adding it to the `PATH`.
6+
- Setup AUTH env var in the Github Action
7+
8+
This action can be run on `ubuntu-latest`, `windows-latest`, and `macos-latest` GitHub Actions runners, and will install and expose the latest version of the `stackql` CLI on the runner environment.
9+
10+
# Usage
11+
12+
## AUTH
13+
> **Note**
14+
> stackql-assert action uses same auth setup as [stackql-exec](https://github.com/stackql/stackql-exec/blob/main/README.md)
15+
> [Learn more](https://stackql.io/docs/getting-started/authenticating) about authentication setup when running stackql
16+
17+
### Example auth string
18+
```
19+
{ "google": { "type": "service_account", "credentialsfilepath": "sa-key.json" },
20+
"github": { "type": "basic", "credentialsenvvar": "STACKQL_GITHUB_CREDS" }}
21+
```
22+
It can be passed with `auth_str` as a string, or stored in a file and pass filename to `auth-obj-path`
23+
- For "basic" auth, you need to set a environment variable with same name as the value of `credentialsenvvar` in the auth string for the Github Action step. You can use [Github Secrets](https://docs.github.com/en/actions/reference/encrypted-secrets) to store the value of the environment variable, and use env to pass it to the action. For example:
24+
```
25+
env:
26+
STACKQL_GITHUB_CREDS: ${{ secrets.STACKQL_GITHUB_CREDS }}
27+
```
28+
- For "service_account" auth, you need to store the credentials into a file; You can follow the example of `Prep Google Creds (bash)` step in the [example workflow](./.github/workflows/stackql-assert.yml)
29+
30+
## Test Query
31+
- Use `test_query` or `test_query_path` to pass the test query to the action. The test query should be a valid StackQL query. The action will run the query and check if the result is empty or not. If the result is empty, the action will fail the step.
32+
- Either `test_query` or `test_query_path` is required. If both are provided, `test_query` will be used.
33+
- query example can be found in [example workflow](./.github/workflows/stackql-assert.yml) and [example .iql file](./.github/workflows/workflow_scripts)
34+
35+
## Expected Result
36+
- Use `expected_results_str` or `expected_results_file_path` to pass the expected result to the action. The expected result 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.
37+
- Either `expected_results_str` or `expected_results_file_path` is required. If both are provided, `expected_results_str` will be used.
38+
- Expected result example can be found in [example workflow](./.github/workflows/stackql-assert.yml) and [example .json file](./.github/workflows/workflow_scripts)
39+
40+
41+
## Input
42+
- `auth_obj_path` - Path to the auth object file.
43+
- `auth_str` - Auth string.
44+
- `test_query` - Test query to run (overrides test_query_path).
45+
- `test_query_path` - Path to the test query file.
46+
- `expected_rows` - Expected number of rows in the result.
47+
- `expected_results_str` - expected result from executing test query, support object string (overrides expected_results_file_path)
48+
- `expected_results_file_path` - file that stores expected result, json is support

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ inputs:
1818
description: expected number of rows from executing test query
1919
required: false
2020
expected_results_str:
21-
description: expected result from executing test query, support object string, overrides expected_results_file_path
21+
description: expected result from executing test query, support json string, overrides expected_results_file_path
2222
required: false
2323
expected_results_file_path:
2424
description: file that stores expected result, json is support

action_scripts/execute.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@ if [ -z "$AUTH" ]; then
77
exit 1
88
fi
99

10-
if [ -z "$QUERY_FILE_PATH" ]; then
11-
stackql exec "$QUERY" --auth="${AUTH}" --output="${OUTPUT}"
10+
if [ -z "$QUERY" ] && [ -z "$QUERY_FILE_PATH" ]; then
11+
echo "ERROR: Either QUERY or QUERY_FILE_PATH must be set."
12+
exit 1
13+
fi
14+
15+
if [ -z "$QUERY" ]; then
16+
stackql exec -i "$QUERY_FILE_PATH" --auth="${AUTH}" --output="${OUTPUT}"
1217
else
13-
stackql exec -i "$QUERY_FILE_PATH" --auth="${AUTH}" --output="${OUTPUT}"
14-
fi
18+
stackql exec "$QUERY" --auth="${AUTH}" --output="${OUTPUT}"
19+
fi
20+

0 commit comments

Comments
 (0)