Skip to content

Commit

Permalink
Merge pull request #16 from stackql/feature/reinstate-wrapper
Browse files Browse the repository at this point in the history
recovered the install wrapper code, added condition step of prep goog…
  • Loading branch information
yunchengyang515 authored Feb 3, 2023
2 parents 7faf95e + f27d0c1 commit d54b7a2
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 10 deletions.
20 changes: 15 additions & 5 deletions .github/workflows/setup-stackql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,21 @@ defaults:

jobs:
stackql-test-matrix:
name: Stackql Local Run ${{ matrix.os }}
name: Stackql local run on ${{ matrix.os }} ${{ matrix.use_wrapper && 'with' || 'without' }} wrapper
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
use_wrapper: [true, false]

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Stackql
uses: ./
with:
use_wrapper: ${{matrix.use_wrapper}}

- name: Validate Stackql Version
run: |
Expand All @@ -37,19 +40,26 @@ jobs:
STACKQL_GITHUB_CREDS: ${{ secrets.STACKQL_GITHUB_CREDS }}

- name: Prep Google Creds (Windows)
if: ${{ matrix.os == 'windows-latest'}}
run: | ## use the secret to create json file
$GoogleCreds = [System.Environment]::GetEnvironmentVariable("GOOGLE_CREDS_ENV")
$GoogleCredsDecoded = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($GoogleCreds))
Write-Output $GoogleCredsDecoded | Set-Content sa-key.json
shell: pwsh
env:
GOOGLE_CREDS_ENV: ${{ secrets.GOOGLE_CREDS }}

- name: Prep Google Creds (bash)
if: ${{ matrix.os != 'windows-latest' }}
run: | ## use the secret to create json file
sudo echo ${{ secrets.GOOGLE_CREDS }} | base64 -d > sa-key.json
- name: Use Google Provider
run: |
stackql exec -i ./examples/google-example.iql --auth='{ "google": { "type": "service_account", "credentialsfilepath": "sa-key.json" }}'
##### uncomment the step to see error handling
# - name: Handle error
# run: | ## use the secret to create json file
# stackql exec -i ./examples/github-example.iql --auth="${INVALID_AUTH}"
- name: Handle error
if: ${{ matrix.use_wrapper}}
continue-on-error: true
run: | ## use the secret to create json file
stackql exec -i ./examples/github-example.iql --auth="${INVALID_AUTH}"
10 changes: 5 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: 'StackQL Studio - Setup StackQL'
description: 'Sets up the StackQL CLI in your GitHub Actions workflow.'
author: 'Yuncheng Yang, StackQL Studios'
inputs: {}
# use_wrapper:
# 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`.'
# default: 'true'
# required: false
inputs:
use_wrapper:
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`.'
default: 'false'
required: false

runs:
using: 'node16'
Expand Down
41 changes: 41 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6706,6 +6706,7 @@ const os = __nccwpck_require__(2037);
const { execSync } = __nccwpck_require__(2081);
const core = __nccwpck_require__(4695);
const tc = __nccwpck_require__(3203);
const io = __nccwpck_require__(9631);

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


async function installWrapper (pathToCLI) {
let source, target;

// If we're on Windows, then the executable ends with .exe
const exeSuffix = os.platform().startsWith('win') ? '.exe' : '';

// Rename stackql(.exe) to stackql-bin(.exe)
try {
source = [pathToCLI, `stackql${exeSuffix}`].join(path.sep);
target = [pathToCLI, `stackql-bin${exeSuffix}`].join(path.sep);
core.debug(`Moving ${source} to ${target}.`);
await io.mv(source, target);
} catch (e) {
core.debug(`Unable to move ${source} to ${target}.`);
throw e;
}

// Install our wrapper as stackql by moving the wrapped executable to stackql
try {
source = path.resolve([__dirname, '..', 'wrapper', 'dist', 'index.js'].join(path.sep));
target = [pathToCLI, 'stackql'].join(path.sep);
core.debug(`Copying ${source} to ${target}.`);
await io.cp(source, target);
} catch (e) {
core.error(`Unable to copy ${source} to ${target}.`);
throw e;
}

// Export a new environment variable, so our wrapper can locate the binary
core.exportVariable('STACKQL_CLI_PATH', pathToCLI);
}


async function setup() {
try {

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

await makeExecutable(cliPath, osPlatform)

const wrapper = core.getInput('use_wrapper') === 'true';

if(wrapper){
core.info('installing wrapper')
await installWrapper(cliPath)
}
core.info(`successfully setup stackql at ${cliPath}`);

} catch (e) {
Expand Down
41 changes: 41 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const os = require('os');
const { execSync } = require("child_process");
const core = require('@actions/core');
const tc = require('@actions/tool-cache');
const io = require('@actions/io');

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


async function installWrapper (pathToCLI) {
let source, target;

// If we're on Windows, then the executable ends with .exe
const exeSuffix = os.platform().startsWith('win') ? '.exe' : '';

// Rename stackql(.exe) to stackql-bin(.exe)
try {
source = [pathToCLI, `stackql${exeSuffix}`].join(path.sep);
target = [pathToCLI, `stackql-bin${exeSuffix}`].join(path.sep);
core.debug(`Moving ${source} to ${target}.`);
await io.mv(source, target);
} catch (e) {
core.debug(`Unable to move ${source} to ${target}.`);
throw e;
}

// Install our wrapper as stackql by moving the wrapped executable to stackql
try {
source = path.resolve([__dirname, '..', 'wrapper', 'dist', 'index.js'].join(path.sep));
target = [pathToCLI, 'stackql'].join(path.sep);
core.debug(`Copying ${source} to ${target}.`);
await io.cp(source, target);
} catch (e) {
core.error(`Unable to copy ${source} to ${target}.`);
throw e;
}

// Export a new environment variable, so our wrapper can locate the binary
core.exportVariable('STACKQL_CLI_PATH', pathToCLI);
}


async function setup() {
try {

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

await makeExecutable(cliPath, osPlatform)

const wrapper = core.getInput('use_wrapper') === 'true';

if(wrapper){
core.info('installing wrapper')
await installWrapper(cliPath)
}
core.info(`successfully setup stackql at ${cliPath}`);

} catch (e) {
Expand Down

0 comments on commit d54b7a2

Please sign in to comment.