From bce47f650891638272e19250caa9f87c8701147e Mon Sep 17 00:00:00 2001 From: Jeffrey Aven Date: Tue, 5 Sep 2023 07:58:02 +1000 Subject: [PATCH 01/10] dryrun to show rendered query --- action.yml | 22 ++++++++++++++++++---- lib/utils.js | 42 +++++++++++++++++++++++++++++++++++++----- 2 files changed, 55 insertions(+), 9 deletions(-) diff --git a/action.yml b/action.yml index f316e48..64a991f 100644 --- a/action.yml +++ b/action.yml @@ -77,7 +77,24 @@ runs: DATA_FILE_PATH: ${{inputs.data_file_path}} VARS: ${{inputs.vars}} OUTPUT: 'json' - + + - name: dryrun stackql command + id: dryrun-query + shell: bash + run: | + ${{ env.STACKQL_DRYRUN_COMMAND }} + + - name: show rendered stackql query + uses: actions/github-script@v6 + with: + script: | + const path = require('path'); + const utilsPath = path.join(process.env.GITHUB_ACTION_PATH, 'lib', 'utils.js') + const {getStackqlCommand} = require(utilsPath) + showStackQLQuery(core) + env: + DRYRUN_RESULT: ${{steps.dryrun-query.outputs.stdout}} + - name: execute stackql command id: exec-query shell: bash @@ -97,9 +114,6 @@ runs: EXPECTED_RESULTS_STR: ${{ inputs.expected_results_str }} EXPECTED_RESULTS_FILE_PATH: ${{inputs.expected_results_file_path}} EXPECTED_ROWS: ${{inputs.expected_rows}} - - - branding: icon: 'terminal' diff --git a/lib/utils.js b/lib/utils.js index c9c6990..1ad8c12 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -28,6 +28,26 @@ function setupAuth(core) { core.exportVariable("AUTH", auth); } +async function showStackQLQuery(core) { + core = coreObj; + try { + let [ + dryRunResult, + ] = [ + process.env.DRYRUN_RESULT, + ]; + + if (!dryRunResult) { + core.setFailed("No Dryrun Output from stackql command"); + } + + core.info(`stackql query:\n${dryRunResult}`); + + } catch (e) { + core.setFailed(e); + } +} + async function getStackqlCommand(core) { const [query, queryFilePath, dataFilePath, vars, auth, output = "json"] = [ @@ -45,32 +65,43 @@ async function getStackqlCommand(core) { } let args = ["exec"]; + let dryRunArgs = ["exec", "-H"]; if (query) { args.push(`"${query}"`); + dryRunArgs.push(`"${query}"`); } else { - args.push("-i", queryFilePath); + args.push("-i", queryFilePath); + dryRunArgs.push("-i", queryFilePath); } - + if (checkEnvVarValid(dataFilePath)) { args.push(`--iqldata='${dataFilePath}'`); + dryRunArgs.push(`--iqldata='${dataFilePath}'`); } - + if (checkEnvVarValid(vars)) { args.push(`--var='${vars}'`); + dryRunArgs.push(`--var='${vars}'`); } if (checkEnvVarValid(auth)) { args.push(`--auth='${auth}'`); + dryRunArgs.push(`--auth='${auth}'`); } args.push(`--output='${output}'`); + dryRunArgs.push(`--output='text'`); try { - core.exportVariable('STACKQL_COMMAND', `stackql ${args.join(" ")}`) + const stackqlQuery = `stackql ${args.join(" ")}`; + const stackqlDryRunQuery = `stackql ${dryRunArgs.join(" ")}`; + core.exportVariable('STACKQL_COMMAND', stackqlQuery); + core.exportVariable('STACKQL_DRYRUN_COMMAND', stackqlDryRunQuery); + core.info(`stackql command:\n${stackqlQuery}`); } catch (error) { core.error(error); - core.setFailed("Error when executing stackql"); + core.setFailed("Error exporting stackql command"); } } @@ -88,4 +119,5 @@ const checkEnvVarValid = (variable) => { module.exports = { setupAuth, getStackqlCommand, + showStackQLQuery, }; From e74e599361edaedb2296ba73035959251df9ddaa Mon Sep 17 00:00:00 2001 From: Jeffrey Aven Date: Tue, 5 Sep 2023 08:00:05 +1000 Subject: [PATCH 02/10] dryrun to show rendered query --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 64a991f..522e69c 100644 --- a/action.yml +++ b/action.yml @@ -90,7 +90,7 @@ runs: script: | const path = require('path'); const utilsPath = path.join(process.env.GITHUB_ACTION_PATH, 'lib', 'utils.js') - const {getStackqlCommand} = require(utilsPath) + const {showStackQLQuery} = require(utilsPath) showStackQLQuery(core) env: DRYRUN_RESULT: ${{steps.dryrun-query.outputs.stdout}} From 609138a80e0a70c47b002538b013d7d08d2d7d55 Mon Sep 17 00:00:00 2001 From: Jeffrey Aven Date: Tue, 5 Sep 2023 08:01:41 +1000 Subject: [PATCH 03/10] dryrun to show rendered query --- lib/utils.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/utils.js b/lib/utils.js index 1ad8c12..4493c4f 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -29,7 +29,6 @@ function setupAuth(core) { } async function showStackQLQuery(core) { - core = coreObj; try { let [ dryRunResult, From 9aba197bd6924713fa1c69ba4689c6f36e1956ef Mon Sep 17 00:00:00 2001 From: Jeffrey Aven Date: Tue, 5 Sep 2023 08:07:22 +1000 Subject: [PATCH 04/10] dryrun to show rendered query --- action.yml | 1 - lib/utils.js | 5 ++++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 522e69c..f4e638b 100644 --- a/action.yml +++ b/action.yml @@ -42,7 +42,6 @@ runs: else echo "stackql_installed=false" >> $GITHUB_OUTPUT fi - - name: Setup StackQL uses: stackql/setup-stackql@v1.2.0 diff --git a/lib/utils.js b/lib/utils.js index 4493c4f..5210393 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -31,15 +31,18 @@ function setupAuth(core) { async function showStackQLQuery(core) { try { let [ + dryRunCommand, dryRunResult, ] = [ - process.env.DRYRUN_RESULT, + process.env.STACKQL_DRYRUN_COMMAND, + process.env.DRYRUN_RESULT, ]; if (!dryRunResult) { core.setFailed("No Dryrun Output from stackql command"); } + core.info(`stackql dryrun command:\n${dryRunCommand}`); core.info(`stackql query:\n${dryRunResult}`); } catch (e) { From f4c6dd85da508fa14269ca0cd2b128d8dc2ce76b Mon Sep 17 00:00:00 2001 From: Jeffrey Aven Date: Tue, 5 Sep 2023 08:19:04 +1000 Subject: [PATCH 05/10] dryrun to show rendered query --- lib/utils.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index 5210393..dde7630 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -42,8 +42,8 @@ async function showStackQLQuery(core) { core.setFailed("No Dryrun Output from stackql command"); } - core.info(`stackql dryrun command:\n${dryRunCommand}`); - core.info(`stackql query:\n${dryRunResult}`); + core.info(`šŸš€ stackql dryrun command:\n${dryRunCommand}`); + core.info(`šŸš€ stackql query:\n${dryRunResult}`); } catch (e) { core.setFailed(e); @@ -100,7 +100,7 @@ async function getStackqlCommand(core) { const stackqlDryRunQuery = `stackql ${dryRunArgs.join(" ")}`; core.exportVariable('STACKQL_COMMAND', stackqlQuery); core.exportVariable('STACKQL_DRYRUN_COMMAND', stackqlDryRunQuery); - core.info(`stackql command:\n${stackqlQuery}`); + core.info(`šŸš€ stackql command:\n${stackqlQuery}`); } catch (error) { core.error(error); core.setFailed("Error exporting stackql command"); From 3169e00c7ec08b26d9808b3641b8999cd72d7820 Mon Sep 17 00:00:00 2001 From: Jeffrey Aven Date: Tue, 5 Sep 2023 09:27:23 +1000 Subject: [PATCH 06/10] dryrun to show rendered query --- .github/workflows/stackql-assert.yml | 2 +- action.yml | 10 ++++++---- lib/assert.js | 17 ++++++++++------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/.github/workflows/stackql-assert.yml b/.github/workflows/stackql-assert.yml index e35cc98..0473d19 100644 --- a/.github/workflows/stackql-assert.yml +++ b/.github/workflows/stackql-assert.yml @@ -60,7 +60,7 @@ jobs: # # Example `test_query_file_path` with `expected_rows` supplying `vars` using `jsonnet` config provided using `data_file_path` # - - name: Use test query string and expected results file, with auth object + - name: Use test query file with a jsonnet data file sourcing external vars and an expected row count uses: ./ with: test_query_file_path: './.github/workflows/workflow_scripts/github-example.iql' diff --git a/action.yml b/action.yml index f4e638b..f7ef0f0 100644 --- a/action.yml +++ b/action.yml @@ -33,7 +33,7 @@ inputs: runs: using: "composite" steps: - - name: Check StackQL is installed and set output + - name: check if stackql is installed and set output id: check-stackql shell: bash run: | @@ -43,13 +43,14 @@ runs: echo "stackql_installed=false" >> $GITHUB_OUTPUT fi - - name: Setup StackQL + - name: setup stackql uses: stackql/setup-stackql@v1.2.0 if: ${{steps.check-stackql.outputs.stackql_installed == 'false'}} with: use_wrapper: true - - name: Setup auth + - name: setup auth + if: (inputs.auth_obj_path != '') || (inputs.auth_str != '') id: setup-auth uses: actions/github-script@v6 with: @@ -92,7 +93,8 @@ runs: const {showStackQLQuery} = require(utilsPath) showStackQLQuery(core) env: - DRYRUN_RESULT: ${{steps.dryrun-query.outputs.stdout}} + # DRYRUN_RESULT: ${{steps.dryrun-query.outputs.stdout}} + DRYRUN_RESULT: ${{steps}} - name: execute stackql command id: exec-query diff --git a/lib/assert.js b/lib/assert.js index d1d1825..f498458 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -10,7 +10,7 @@ const parseResult = (resultStr, varName) => { const jsonObj = JSON.parse(jsonStr); // parse the JSON string into an object return jsonObj; } catch (error) { - throw(`Failed to parse ${varName} JSON + throw(`āŒ Failed to parse ${varName} JSON \nvalue: ${resultStr} \nerror: ${error}`); } @@ -34,18 +34,21 @@ const checkResult = (expectedResult, expectedRows, actualResult) => { let equality; let message; expectedRows = parseInt(expectedRows); + const successMessage = `āœ… StackQL Assert Successful`; + const failureMessage = `āŒ StackQL Assert Failed`; + // if only passed expectedRows, check expectedRows // if only passed expected result, only check expected result // if both passed, check both if (expectedRows) { equality = actualResult.length === expectedRows; if(equality) { - message = `============ StackQL Assert Successful (row count) ============ \n + message = `============ ${successMessage} (row count) ============ \n Expected Number of Rows: ${expectedRows} \n Actual Number of Rows: ${actualResult.length} \n `; } else { - message = `============ StackQL Assert Failed (row count) ============ \n + message = `============ ${failureMessage} (row count) ============ \n Expected Number of Rows: ${expectedRows} \n Actual Number of Rows: ${actualResult.length} \n Execution Result: ${JSON.stringify(actualResult)} \n @@ -56,9 +59,9 @@ const checkResult = (expectedResult, expectedRows, actualResult) => { if (expectedResult) { equality = JSON.stringify(expectedResult) === JSON.stringify(actualResult); if(equality) { - message = `============ StackQL Assert Successful (expected results) ============`; + message = `============ ${successMessage} (expected results) ============`; } else { - message = `============ StackQL Assert Failed (expected results) ============ \n + message = `============ ${failureMessage} (expected results) ============ \n Expected: ${JSON.stringify(expectedResult)}\n Actual: ${JSON.stringify(actualResult)} `; @@ -80,7 +83,7 @@ function checkParameters(expectedResultStr, expectedResultFilePath, expectedRows .map(param => param.name) if (missingParams.length === 3) { - const errorMessage = "Cannot find expected result, file path or expected rows"; + const errorMessage = "āŒ Cannot find expected result, file path or expected rows"; throw errorMessage; } } @@ -111,7 +114,7 @@ const assertResult = (coreObj) =>{ const actualResult = parseResult(execResultStr); if (!actualResult) { - core.setFailed("No Output from executing query"); + core.setFailed(`āŒ No Output from executing query`); } const {equality, message} = checkResult(expectedResult, expectedRows, actualResult); From 21965a94e0f8f3056b572cd85d63363b89037328 Mon Sep 17 00:00:00 2001 From: Jeffrey Aven Date: Tue, 5 Sep 2023 09:29:39 +1000 Subject: [PATCH 07/10] dryrun to show rendered query --- lib/tests/assert.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tests/assert.test.js b/lib/tests/assert.test.js index d3d1956..b9841c9 100644 --- a/lib/tests/assert.test.js +++ b/lib/tests/assert.test.js @@ -133,7 +133,7 @@ describe('getExpectedResult', ()=>{ assertResult(coreObj) - expect(coreObj.setFailed).toHaveBeenCalledWith('Cannot find expected result, file path or expected rows') + expect(coreObj.setFailed).toHaveBeenCalledWith('āŒ Cannot find expected result, file path or expected rows') }); it('it should setFailed when actual result is not equal to expected result', () => { From d995c6b74d0642f8511a23c5ea84809c2e860f87 Mon Sep 17 00:00:00 2001 From: Jeffrey Aven Date: Tue, 5 Sep 2023 09:35:56 +1000 Subject: [PATCH 08/10] dryrun to show rendered query --- lib/utils.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/utils.js b/lib/utils.js index dde7630..adb4a03 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -94,6 +94,7 @@ async function getStackqlCommand(core) { args.push(`--output='${output}'`); dryRunArgs.push(`--output='text'`); + dryRunArgs.push(`--dryrun`); try { const stackqlQuery = `stackql ${args.join(" ")}`; From 25d669f8cde71e4f5ee91e57684b457a67d97b1d Mon Sep 17 00:00:00 2001 From: Jeffrey Aven Date: Tue, 5 Sep 2023 09:40:02 +1000 Subject: [PATCH 09/10] dryrun to show rendered query --- action.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/action.yml b/action.yml index f7ef0f0..f19148c 100644 --- a/action.yml +++ b/action.yml @@ -93,8 +93,7 @@ runs: const {showStackQLQuery} = require(utilsPath) showStackQLQuery(core) env: - # DRYRUN_RESULT: ${{steps.dryrun-query.outputs.stdout}} - DRYRUN_RESULT: ${{steps}} + DRYRUN_RESULT: ${{steps.dryrun-query.outputs.stdout}} - name: execute stackql command id: exec-query From eae10df74ba856f04677516e56347a4f9d340644 Mon Sep 17 00:00:00 2001 From: Jeffrey Aven Date: Tue, 5 Sep 2023 09:44:18 +1000 Subject: [PATCH 10/10] dryrun to show rendered query --- lib/utils.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index adb4a03..0a6f4b0 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -42,8 +42,7 @@ async function showStackQLQuery(core) { core.setFailed("No Dryrun Output from stackql command"); } - core.info(`šŸš€ stackql dryrun command:\n${dryRunCommand}`); - core.info(`šŸš€ stackql query:\n${dryRunResult}`); + core.info(`\nšŸš€ rendered stackql query:\n${dryRunResult}`); } catch (e) { core.setFailed(e); @@ -101,7 +100,6 @@ async function getStackqlCommand(core) { const stackqlDryRunQuery = `stackql ${dryRunArgs.join(" ")}`; core.exportVariable('STACKQL_COMMAND', stackqlQuery); core.exportVariable('STACKQL_DRYRUN_COMMAND', stackqlDryRunQuery); - core.info(`šŸš€ stackql command:\n${stackqlQuery}`); } catch (error) { core.error(error); core.setFailed("Error exporting stackql command");