Skip to content

Commit d8366c6

Browse files
Merge pull request #6 from stackql/feature/wrapper
Feature/wrapper
2 parents be8863c + 7c7ad36 commit d8366c6

File tree

13 files changed

+14292
-7
lines changed

13 files changed

+14292
-7
lines changed

.github/workflows/example-workflows.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ defaults:
1212
shell: bash
1313

1414
jobs:
15-
stackql-versions:
16-
name: 'Stackql Versions'
15+
stackql-tests:
16+
name: 'Stackql Examples'
1717
runs-on: ubuntu-latest
1818

1919
steps:
@@ -22,6 +22,8 @@ jobs:
2222

2323
- name: Setup stackql
2424
uses: ./
25+
with:
26+
use_wrapper: 'true'
2527

2628

2729
- name: Validate Stackql Version
@@ -35,9 +37,15 @@ jobs:
3537
AUTH: ${{ vars.AUTH }} ##'{ "github": { "type": "basic", "credentialsenvvar": "STACKQL_GITHUB_CREDS" } }'
3638
STACKQL_GITHUB_CREDS: ${{ secrets.STACKQL_GITHUB_CREDS }}
3739

38-
- name: use Google Provider
40+
- name: Use Google Provider
3941
run: | ## use the secret to create json file
4042
sudo echo ${{ secrets.GOOGLE_CREDS }} | base64 -d > sa-key.json
4143
stackql exec -i ./examples/google-example.iql --auth="${AUTH}"
4244
env:
4345
AUTH: ${{ vars.AUTH }} ## '{ "google": { "type": "service_account", "credentialsfilepath": "sa-key.json" }}'
46+
47+
##### uncomment the step to see error handling
48+
# - name: Handle error
49+
# run: | ## use the secret to create json file
50+
# stackql exec -i ./examples/github-example.iql --auth="${INVALID_AUTH}"
51+

.husky/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/sh
22
. "$(dirname "$0")/_/husky.sh"
33

4-
npm run build && git add dist/
4+
npm run build && git add dist/ && git add wrapper/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# setup-stackql
22

3-
The `stackql/setup-stackql` action is a JavaScript action that sets up Terraform CLI in your GitHub Actions workflow by:
3+
The `stackql/setup-stackql` action is a JavaScript action that sets up StackQL CLI in your GitHub Actions workflow by:
44

55
- Downloading a latest Stackql CLI and adding it to the `PATH`.
66
- Setup AUTH env var in the Github Action

action.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
name: 'StackQL Studio - Setup StackQL'
22
description: 'Sets up StackQL CLI in your GitHub Actions workflow.'
33
author: 'Yuncheng Yang, StackQL'
4-
4+
inputs:
5+
use_wrapper:
6+
description: 'Whether or not to install a wrapper to wrap subsequent calls of the `stackql` binary and expose its STDOUT, STDERR, and exit code as outputs named `stdout`, `stderr`, and `exitcode` respectively. Defaults to `true`.'
7+
default: 'true'
8+
required: false
59

610
runs:
711
using: 'node16'

dist/index.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6748,12 +6748,51 @@ async function addPermission(){
67486748
}
67496749
}
67506750

6751+
6752+
async function installWrapper (pathToCLI) {
6753+
let source, target;
6754+
6755+
// If we're on Windows, then the executable ends with .exe
6756+
const exeSuffix = os.platform().startsWith('win') ? '.exe' : '';
6757+
6758+
// Rename stackql(.exe) to stackql-bin(.exe)
6759+
try {
6760+
source = [pathToCLI, `stackql${exeSuffix}`].join(path.sep);
6761+
target = [pathToCLI, `stackql-bin${exeSuffix}`].join(path.sep);
6762+
core.debug(`Moving ${source} to ${target}.`);
6763+
await io.mv(source, target);
6764+
} catch (e) {
6765+
core.debug(`Unable to move ${source} to ${target}.`);
6766+
throw e;
6767+
}
6768+
6769+
// Install our wrapper as stackql by moving the wrapped executable to stackql
6770+
try {
6771+
source = path.resolve([__dirname, '..', 'wrapper', 'dist', 'index.js'].join(path.sep));
6772+
target = [pathToCLI, 'stackql'].join(path.sep);
6773+
core.debug(`Copying ${source} to ${target}.`);
6774+
await io.cp(source, target);
6775+
} catch (e) {
6776+
core.error(`Unable to copy ${source} to ${target}.`);
6777+
throw e;
6778+
}
6779+
6780+
// Export a new environment variable, so our wrapper can locate the binary
6781+
core.exportVariable('STACKQL_CLI_PATH', pathToCLI);
6782+
}
6783+
6784+
67516785
async function setup(){
67526786

67536787
const path = await downloadCLI()
67546788

67556789
core.addPath(path)
67566790
await addPermission()
6791+
const wrapper = core.getInput('use_wrapper') === 'true';
6792+
if(wrapper){
6793+
console.log('installing wrapper')
6794+
await installWrapper(path)
6795+
}
67576796
}
67586797

67596798
(async () => {

index.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,51 @@ async function addPermission(){
4646
}
4747
}
4848

49+
50+
async function installWrapper (pathToCLI) {
51+
let source, target;
52+
53+
// If we're on Windows, then the executable ends with .exe
54+
const exeSuffix = os.platform().startsWith('win') ? '.exe' : '';
55+
56+
// Rename stackql(.exe) to stackql-bin(.exe)
57+
try {
58+
source = [pathToCLI, `stackql${exeSuffix}`].join(path.sep);
59+
target = [pathToCLI, `stackql-bin${exeSuffix}`].join(path.sep);
60+
core.debug(`Moving ${source} to ${target}.`);
61+
await io.mv(source, target);
62+
} catch (e) {
63+
core.debug(`Unable to move ${source} to ${target}.`);
64+
throw e;
65+
}
66+
67+
// Install our wrapper as stackql by moving the wrapped executable to stackql
68+
try {
69+
source = path.resolve([__dirname, '..', 'wrapper', 'dist', 'index.js'].join(path.sep));
70+
target = [pathToCLI, 'stackql'].join(path.sep);
71+
core.debug(`Copying ${source} to ${target}.`);
72+
await io.cp(source, target);
73+
} catch (e) {
74+
core.error(`Unable to copy ${source} to ${target}.`);
75+
throw e;
76+
}
77+
78+
// Export a new environment variable, so our wrapper can locate the binary
79+
core.exportVariable('STACKQL_CLI_PATH', pathToCLI);
80+
}
81+
82+
4983
async function setup(){
5084

5185
const path = await downloadCLI()
5286

5387
core.addPath(path)
5488
await addPermission()
89+
const wrapper = core.getInput('use_wrapper') === 'true';
90+
if(wrapper){
91+
console.log('installing wrapper')
92+
await installWrapper(path)
93+
}
5594
}
5695

5796
(async () => {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "",
55
"main": "index.js",
66
"scripts": {
7-
"build": "ncc build index.js --out dist",
7+
"build": "cd wrapper && npm run build && cd .. && ncc build index.js --out dist",
88
"postinstall": "husky install"
99
},
1010
"repository": {

0 commit comments

Comments
 (0)