Skip to content

Commit

Permalink
feat: add jikkou wrapper to capture stdout, stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
fhussonnois committed Sep 30, 2023
1 parent 64ed61c commit 90e5824
Show file tree
Hide file tree
Showing 12 changed files with 4,505 additions and 7 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/setup-jikkou-wrapper.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: 'Setup Jikkou Wrapper'

on:
push:
branches:
- main
pull_request:

defaults:
run:
shell: bash

jobs:
jikkou-wrapper:
name: 'Jikkou Versions'
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
jikkou-versions: [0.29.0, latest]

steps:
- name: Checkout GitHub repository
uses: actions/checkout@v4
with:
clean: true

- name: Setup Jikkou - ${{ matrix['jikkou-versions'] }}
uses: ./
with:
jikkou_version: ${{ matrix['jikkou-versions'] }}
jikkou_config: ./config/jikkouconfig.json
jikkou_wrapper: true

# jikkou-versions != latest
- name: Validate Jikkou Version - ${{ matrix['jikkou-versions'] }}
id: version-latest
if: ${{ matrix['jikkou-versions'] != 'latest' }}
run: jikkou -V | grep ${{ matrix['jikkou-versions']}}

# jikkou-versions == latest
- name: Validate Jikkou Version - ${{ matrix['jikkou-versions'] }}
id: version
if: ${{ matrix['jikkou-versions'] == 'latest' }}
run: jikkou -V | grep 'Jikkou version'

- name: Output stdout
if: ${{ matrix['jikkou-versions'] == 'latest' }}
run: echo ${{ steps.version.outputs.stdout }}

- name: Output stderr
if: ${{ matrix['jikkou-versions'] == 'latest' }}
run: echo ${{ steps.version.outputs.stderr }}

- name: Output stderr
if: ${{ matrix['jikkou-versions'] == 'latest' }}
run: echo ${{ steps.version.outputs.exitcode }}

4 changes: 2 additions & 2 deletions .github/workflows/setup-jikkou.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ defaults:
shell: bash

jobs:
jikkou-versions:
jikkou:
name: 'Jikkou Versions'
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
jikkou-versions: [0.27.0, 0.28.0, latest]
jikkou-versions: [0.29.0, latest]

steps:
- name: Checkout GitHub repository
Expand Down
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
/node_modules/
/.idea/

# ./wrapper/dist gets included in top-level ./dist
wrapper/dist

# Jetbrains IDEs
.idea/
.iml

# dotenv environment variables file
.env
4 changes: 4 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ inputs:
jikkou_config:
description: 'The path to the Jikkou CLI config file. If set, Jikkou CLI will be configured through the `JIKKOUCONFIG` environment variable.'
required: false
jikkou_wrapper:
description: 'Whether or not to install a wrapper to wrap subsequent calls of the `jikkou` binary and expose its STDOUT, STDERR, and exit code as outputs named `stdout`, `stderr`, and `exitcode` respectively. Defaults to `false`.'
default: 'false'
required: false
runs:
using: 'node20'
main: 'dist/index.js'
Expand Down
39 changes: 39 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const core = __nccwpck_require__(2186);
const github = __nccwpck_require__(5438);
const tc = __nccwpck_require__(7784);
const http = __nccwpck_require__(6255);
const io = __nccwpck_require__(7436);

const project = { owner: "streamthoughts", repo: "jikkou" };

Expand Down Expand Up @@ -102,11 +103,44 @@ async function getBuild(version, platform, arch) {
};
}

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 jikkou(.exe) to jikkou-bin(.exe)
try {
source = [pathToCLI, `jikkou${exeSuffix}`].join(path.sep);
target = [pathToCLI, `jikkou-bin${exeSuffix}`].join(path.sep);
core.debug(`Moving binary from ${source} to ${target}.`);
await io.mv(source, target);
} catch (e) {
core.error(`Unable to move binary from ${source} to ${target}.`);
throw e;
}

// Install our wrapper as jikkou
try {
source = __nccwpck_require__.ab + "index1.js";
target = [pathToCLI, "jikkou"].join(path.sep);
core.debug(`Copying ${source} to ${target}.`);
await io.cp(__nccwpck_require__.ab + "index1.js", 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("JIKKOU_CLI_PATH", pathToCLI);
}

async function run() {
try {
// Gather GitHub Actions inputs
const inputVersion = core.getInput("jikkou_version") || "latest";
const inputConfig = core.getInput("jikkou_config");
const inputWrapper = core.getInput("jikkou_wrapper") === "true";

// Gather OS details
const osPlatform = os.platform();
Expand Down Expand Up @@ -151,6 +185,11 @@ async function run() {
core.exportVariable("JIKKOUCONFIG", pathToConfigFile);
}

// Install Wrapper
if (inputWrapper) {
await installWrapper(pathToCLI);
}

const release = {
version: version,
name: build.name,
Expand Down
Loading

0 comments on commit 90e5824

Please sign in to comment.