Skip to content

Commit 9484f89

Browse files
authored
Merge pull request #15 from stackql/feature/add-support-for-data-files
added support for data files
2 parents 9e711ee + 003b86c commit 9484f89

7 files changed

+46
-7
lines changed

.github/workflows/stackql-exec.yml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,34 @@ jobs:
5353
GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}
5454

5555
#
56-
# query_file_path with vars
56+
# query_file_path with jsonnet code block using external vars
5757
#
5858
- name: exec google example with query file using vars
5959
id: stackql-exec-file-with-vars
6060
uses: ./
6161
with:
62-
query_file_path: './stackql_scripts/google-instances-by-status-with-vars.iql'
62+
query_file_path: './stackql_scripts/google-instances-by-status-with-inline-jsonnet-block.iql'
6363
vars: GOOGLE_PROJECT=${{ env.GOOGLE_PROJECT }},GOOGLE_ZONE=${{ env.GOOGLE_ZONE }}
6464
env:
6565
GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}
6666
GOOGLE_PROJECT: ${{ vars.GOOGLE_PROJECT }}
6767
GOOGLE_ZONE: ${{ vars.GOOGLE_ZONE }}
6868

69+
#
70+
# query_file_path with jsonnet data file using external vars
71+
#
72+
- name: exec google example with query file and data file using vars
73+
id: stackql-exec-file-with-data-file-and-vars
74+
uses: ./
75+
with:
76+
query_file_path: './stackql_scripts/google-instances-by-status-with-external-data-file.iql'
77+
data_file_path: './stackql_scripts/google-instances-by-status-with-external-data-file.jsonnet'
78+
vars: GOOGLE_PROJECT=${{ env.GOOGLE_PROJECT }},GOOGLE_ZONE=${{ env.GOOGLE_ZONE }}
79+
env:
80+
GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}
81+
GOOGLE_PROJECT: ${{ vars.GOOGLE_PROJECT }}
82+
GOOGLE_ZONE: ${{ vars.GOOGLE_ZONE }}
83+
6984
- name: validate stackql-exec output
7085
shell: bash
7186
run: |
@@ -84,4 +99,8 @@ jobs:
8499
if [ -z '${{ steps.stackql-exec-file-with-vars.outputs.exec-result }}' ]; then
85100
echo "exec-stackql output does not contain expected result"
86101
exit 1
102+
fi
103+
if [ -z '${{ steps.stackql-exec-file-with-data-file-and-vars.outputs.exec-result }}' ]; then
104+
echo "exec-stackql output does not contain expected result"
105+
exit 1
87106
fi

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ GROUP BY status;
5656
## Inputs
5757
- `query` - stackql query to execute **(need to supply either `query` or `query_file_path`)**
5858
- `query_file_path` - stackql query file to execute **(need to supply either `query` or `query_file_path`)**
59-
- `vars` - (optional) comma delimited list of variables to pass to the stackql query preprocessor (jsonnet), accepts `var1=val1 var2=val2`, can be used to source environment variables into stackql queries
59+
- `data_file_path` - (optional) path to data file to pass to the stackql query preprocessor (`json` or `jsonnet`)
60+
- `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
6061
- `query_output` - (optional) output format of the stackql exec result, accepts `table`, `csv`, `json`, defaults to `json`
6162
- `auth_obj_path` - (optional) the path of json file that stores stackql AUTH string **(only required when using non-standard environment variable names)**
6263
- `auth_str` - (optional) stackql AUTH string **(only required when using non-standard environment variable names)**

action.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ inputs:
88
query_file_path:
99
description: stackql query file to be executed
1010
required: false
11+
data_file_path:
12+
description: jsonnet or json data file to be passed to query preprocessor
13+
required: false
1114
vars:
12-
description: comma delimited list of vars to be passed to query preprocessor (jsonnet)
15+
description: comma delimited list of vars to be passed to query preprocessor (supported with jsonnet config blocks or jsonnet data files only)
1316
required: false
1417
query_output:
1518
description: output format
@@ -77,6 +80,7 @@ runs:
7780
env:
7881
QUERY_FILE_PATH: ${{ inputs.query_file_path }}
7982
QUERY: ${{inputs.query}}
83+
DATA_FILE_PATH: ${{inputs.data_file_path}}
8084
OUTPUT: ${{inputs.query_output}}
8185
VARS: ${{inputs.vars}}
8286

lib/utils.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ async function getStackqlCommand(core) {
3939
// core.info("Cannot find AUTH environment variable when executing stackql. Proceeding using default provider environment variable names.");
4040
// }
4141

42-
const [query, queryFilePath, auth, output = "json", vars] = [
42+
const [query, queryFilePath, auth, output = "json", vars, dataFilePath] = [
4343
process.env.QUERY,
4444
process.env.QUERY_FILE_PATH,
4545
process.env.AUTH,
4646
process.env.OUTPUT,
47-
process.env.VARS
47+
process.env.VARS,
48+
process.env.DATA_FILE_PATH,
4849
];
4950

5051
if (!checkEnvVarValid(query) && !checkEnvVarValid(queryFilePath)) {
@@ -77,7 +78,11 @@ async function getStackqlCommand(core) {
7778

7879
if (checkEnvVarValid(auth)) {
7980
args.push(`--auth="${auth}"`);
80-
}
81+
}
82+
83+
if (checkEnvVarValid(dataFilePath)) {
84+
args.push(`--iqldata="${dataFilePath}"`);
85+
}
8186

8287
try {
8388
const stackQLCommand = `stackql ${args.join(" ")}`;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SELECT status, count(*) as num_instances
2+
FROM google.compute.instances
3+
WHERE project = '{{ .project }}' and zone = '{{ .zone }}'
4+
GROUP BY status;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
local project = std.extVar("GOOGLE_PROJECT");
2+
local zone = std.extVar("GOOGLE_ZONE");
3+
{
4+
project: project,
5+
zone: zone,
6+
}

0 commit comments

Comments
 (0)