Skip to content

Commit

Permalink
Merge pull request #15 from stackql/feature/add-support-for-data-files
Browse files Browse the repository at this point in the history
added support for data files
  • Loading branch information
jeffreyaven authored Sep 3, 2023
2 parents 9e711ee + 003b86c commit 9484f89
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 7 deletions.
23 changes: 21 additions & 2 deletions .github/workflows/stackql-exec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,34 @@ jobs:
GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}

#
# query_file_path with vars
# query_file_path with jsonnet code block using external vars
#
- name: exec google example with query file using vars
id: stackql-exec-file-with-vars
uses: ./
with:
query_file_path: './stackql_scripts/google-instances-by-status-with-vars.iql'
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 }}

#
# query_file_path with jsonnet data file using external vars
#
- name: exec google example with query file and data file using vars
id: stackql-exec-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-exec output
shell: bash
run: |
Expand All @@ -84,4 +99,8 @@ jobs:
if [ -z '${{ steps.stackql-exec-file-with-vars.outputs.exec-result }}' ]; then
echo "exec-stackql output does not contain expected result"
exit 1
fi
if [ -z '${{ steps.stackql-exec-file-with-data-file-and-vars.outputs.exec-result }}' ]; then
echo "exec-stackql output does not contain expected result"
exit 1
fi
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ GROUP BY status;
## Inputs
- `query` - stackql query to execute **(need to supply either `query` or `query_file_path`)**
- `query_file_path` - stackql query file to execute **(need to supply either `query` or `query_file_path`)**
- `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
- `data_file_path` - (optional) path to data file to pass to the stackql query preprocessor (`json` or `jsonnet`)
- `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
- `query_output` - (optional) output format of the stackql exec result, accepts `table`, `csv`, `json`, defaults to `json`
- `auth_obj_path` - (optional) the path of json file that stores stackql AUTH string **(only required when using non-standard environment variable names)**
- `auth_str` - (optional) stackql AUTH string **(only required when using non-standard environment variable names)**
Expand Down
6 changes: 5 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ inputs:
query_file_path:
description: stackql query file to be executed
required: false
data_file_path:
description: jsonnet or json data file to be passed to query preprocessor
required: false
vars:
description: comma delimited list of vars to be passed to query preprocessor (jsonnet)
description: comma delimited list of vars to be passed to query preprocessor (supported with jsonnet config blocks or jsonnet data files only)
required: false
query_output:
description: output format
Expand Down Expand Up @@ -77,6 +80,7 @@ runs:
env:
QUERY_FILE_PATH: ${{ inputs.query_file_path }}
QUERY: ${{inputs.query}}
DATA_FILE_PATH: ${{inputs.data_file_path}}
OUTPUT: ${{inputs.query_output}}
VARS: ${{inputs.vars}}

Expand Down
11 changes: 8 additions & 3 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ async function getStackqlCommand(core) {
// core.info("Cannot find AUTH environment variable when executing stackql. Proceeding using default provider environment variable names.");
// }

const [query, queryFilePath, auth, output = "json", vars] = [
const [query, queryFilePath, auth, output = "json", vars, dataFilePath] = [
process.env.QUERY,
process.env.QUERY_FILE_PATH,
process.env.AUTH,
process.env.OUTPUT,
process.env.VARS
process.env.VARS,
process.env.DATA_FILE_PATH,
];

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

if (checkEnvVarValid(auth)) {
args.push(`--auth="${auth}"`);
}
}

if (checkEnvVarValid(dataFilePath)) {
args.push(`--iqldata="${dataFilePath}"`);
}

try {
const stackQLCommand = `stackql ${args.join(" ")}`;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT status, count(*) as num_instances
FROM google.compute.instances
WHERE project = '{{ .project }}' and zone = '{{ .zone }}'
GROUP BY status;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
local project = std.extVar("GOOGLE_PROJECT");
local zone = std.extVar("GOOGLE_ZONE");
{
project: project,
zone: zone,
}

0 comments on commit 9484f89

Please sign in to comment.