Skip to content

Commit d54b7a2

Browse files
Merge pull request #16 from stackql/feature/reinstate-wrapper
recovered the install wrapper code, added condition step of prep goog…
2 parents 7faf95e + f27d0c1 commit d54b7a2

File tree

4 files changed

+102
-10
lines changed

4 files changed

+102
-10
lines changed

.github/workflows/setup-stackql.yml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,21 @@ defaults:
1313

1414
jobs:
1515
stackql-test-matrix:
16-
name: Stackql Local Run ${{ matrix.os }}
16+
name: Stackql local run on ${{ matrix.os }} ${{ matrix.use_wrapper && 'with' || 'without' }} wrapper
1717
runs-on: ${{ matrix.os }}
1818
strategy:
1919
matrix:
2020
os: [ubuntu-latest, windows-latest, macos-latest]
21+
use_wrapper: [true, false]
2122

2223
steps:
2324
- name: Checkout
2425
uses: actions/checkout@v3
2526

2627
- name: Setup Stackql
2728
uses: ./
29+
with:
30+
use_wrapper: ${{matrix.use_wrapper}}
2831

2932
- name: Validate Stackql Version
3033
run: |
@@ -37,19 +40,26 @@ jobs:
3740
STACKQL_GITHUB_CREDS: ${{ secrets.STACKQL_GITHUB_CREDS }}
3841

3942
- name: Prep Google Creds (Windows)
43+
if: ${{ matrix.os == 'windows-latest'}}
4044
run: | ## use the secret to create json file
4145
$GoogleCreds = [System.Environment]::GetEnvironmentVariable("GOOGLE_CREDS_ENV")
4246
$GoogleCredsDecoded = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($GoogleCreds))
4347
Write-Output $GoogleCredsDecoded | Set-Content sa-key.json
4448
shell: pwsh
4549
env:
4650
GOOGLE_CREDS_ENV: ${{ secrets.GOOGLE_CREDS }}
51+
52+
- name: Prep Google Creds (bash)
53+
if: ${{ matrix.os != 'windows-latest' }}
54+
run: | ## use the secret to create json file
55+
sudo echo ${{ secrets.GOOGLE_CREDS }} | base64 -d > sa-key.json
4756
4857
- name: Use Google Provider
4958
run: |
5059
stackql exec -i ./examples/google-example.iql --auth='{ "google": { "type": "service_account", "credentialsfilepath": "sa-key.json" }}'
5160
52-
##### uncomment the step to see error handling
53-
# - name: Handle error
54-
# run: | ## use the secret to create json file
55-
# stackql exec -i ./examples/github-example.iql --auth="${INVALID_AUTH}"
61+
- name: Handle error
62+
if: ${{ matrix.use_wrapper}}
63+
continue-on-error: true
64+
run: | ## use the secret to create json file
65+
stackql exec -i ./examples/github-example.iql --auth="${INVALID_AUTH}"

action.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
name: 'StackQL Studio - Setup StackQL'
22
description: 'Sets up the StackQL CLI in your GitHub Actions workflow.'
33
author: 'Yuncheng Yang, StackQL Studios'
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
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: 'false'
8+
required: false
99

1010
runs:
1111
using: 'node16'

dist/index.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6706,6 +6706,7 @@ const os = __nccwpck_require__(2037);
67066706
const { execSync } = __nccwpck_require__(2081);
67076707
const core = __nccwpck_require__(4695);
67086708
const tc = __nccwpck_require__(3203);
6709+
const io = __nccwpck_require__(9631);
67096710

67106711
const urls = {
67116712
'linux': 'https://releases.stackql.io/stackql/latest/stackql_linux_amd64.zip',
@@ -6755,6 +6756,40 @@ async function makeExecutable(cliPath, osPlatform){
67556756
}
67566757
}
67576758

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

@@ -6778,6 +6813,12 @@ async function setup() {
67786813

67796814
await makeExecutable(cliPath, osPlatform)
67806815

6816+
const wrapper = core.getInput('use_wrapper') === 'true';
6817+
6818+
if(wrapper){
6819+
core.info('installing wrapper')
6820+
await installWrapper(cliPath)
6821+
}
67816822
core.info(`successfully setup stackql at ${cliPath}`);
67826823

67836824
} catch (e) {

index.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const os = require('os');
44
const { execSync } = require("child_process");
55
const core = require('@actions/core');
66
const tc = require('@actions/tool-cache');
7+
const io = require('@actions/io');
78

89
const urls = {
910
'linux': 'https://releases.stackql.io/stackql/latest/stackql_linux_amd64.zip',
@@ -53,6 +54,40 @@ async function makeExecutable(cliPath, osPlatform){
5354
}
5455
}
5556

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

@@ -76,6 +111,12 @@ async function setup() {
76111

77112
await makeExecutable(cliPath, osPlatform)
78113

114+
const wrapper = core.getInput('use_wrapper') === 'true';
115+
116+
if(wrapper){
117+
core.info('installing wrapper')
118+
await installWrapper(cliPath)
119+
}
79120
core.info(`successfully setup stackql at ${cliPath}`);
80121

81122
} catch (e) {

0 commit comments

Comments
 (0)