diff --git a/.github/workflows/setup-stackql.yml b/.github/workflows/setup-stackql.yml index b33c003..351a32f 100644 --- a/.github/workflows/setup-stackql.yml +++ b/.github/workflows/setup-stackql.yml @@ -13,11 +13,12 @@ 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 @@ -25,6 +26,8 @@ jobs: - name: Setup Stackql uses: ./ + with: + use_wrapper: ${{matrix.use_wrapper}} - name: Validate Stackql Version run: | @@ -37,6 +40,7 @@ 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)) @@ -44,12 +48,18 @@ jobs: 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}" diff --git a/action.yml b/action.yml index 62b25e3..6aebb24 100644 --- a/action.yml +++ b/action.yml @@ -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' diff --git a/dist/index.js b/dist/index.js index c02053e..c99de09 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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', @@ -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 { @@ -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) { diff --git a/index.js b/index.js index 59b7b3b..012a20b 100644 --- a/index.js +++ b/index.js @@ -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', @@ -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 { @@ -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) {