Skip to content

Commit

Permalink
feat: add binary wrapper to capture stdout,stderr,exitcode
Browse files Browse the repository at this point in the history
  • Loading branch information
fhussonnois committed Sep 30, 2023
1 parent 64ed61c commit 5a0ed1d
Show file tree
Hide file tree
Showing 14 changed files with 4,571 additions and 22 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: 'build'

on:
push:
branches:
- main
pull_request:

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: 'Checkout GitHub repository'
uses: actions/checkout@v4
with:
clean: true

- name: 'Setup Node'
uses: actions/setup-node@v3
with:
node-version: '20.x'

- name: 'Run npm'
run:
npm install && npm run all
47 changes: 47 additions & 0 deletions .github/workflows/setup-jikkou-wrapper.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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: [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

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

- name: 'Output stdout'
run: echo "${{ steps.version.outputs.stdout }}"

- name: 'Output stderr'
run: echo "${{ steps.version.outputs.stderr }}"

- name: 'Output exitcode'
run: echo "${{ steps.version.outputs.exitcode }}"

5 changes: 3 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-no-wrapper:
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 All @@ -30,6 +30,7 @@ jobs:
with:
jikkou_version: ${{ matrix['jikkou-versions'] }}
jikkou_config: ./config/jikkouconfig.json
jikkou_wrapper: false

- name: Validate Jikkou Version - ${{ matrix['jikkou-versions'] }}
if: ${{ matrix['jikkou-versions'] != 'latest' }}
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
49 changes: 41 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
# setup-jikkou

**Jikkou (jikkō / 実行)** is an open-source tool designed to provide an efficient and easy way to manage, automate, and
provision resource configurations for Kafka, Schema Registry, etc.

The `streamthoughts/setup-jikkou` action is a JavaScript action that sets
up [Jikkou CLI](https://github.com/streamthoughts/jikkou) in your **GitHub Actions**
workflow
by:
workflow by:

* Downloading a specific version of **Jikkou CLI** and adding it to the `PATH`.
* Configuring **JIKKOU CLI** with a custom configuration file.
* Configuring **JIKKOU CLI** with a custom configuration file and automatically setting up the `JIKKOUCONFIG`
environment variable.
* Installing a **wrapper script** to wrap calls of the Jikkou CLI binary to expose its `STDOUT`, `STDERR`,
and exit code as outputs named `stdout`, `stderr`, and `exitcode` respectively.

After you've used the action, subsequent steps in the same job can run arbitrary Jikkou commands using the GitHub
Actions run syntax. This allows most Jikkou commands to work exactly like they do on your local command line.

## Usage
## Usages

```yaml
steps:
Expand Down Expand Up @@ -40,10 +45,38 @@ steps:

This Action additionally supports the following inputs :

| Property | Default | Description |
|------------------|----------|--------------------------------------------------------------------------------------------------------------------------------|
| `jikkou_version` | `latest` | The version of Jikkou CLI to install. A value of `latest` will install the latest version of Jikkou CLI. |
| `jikkou_config` | | The path to the Jikkou CLI config file. If set, Jikkou CLI will be configured through the `JIKKOUCONFIG` environment variable. |
| Property | Default | Description |
|------------------|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `jikkou_version` | `latest` | The version of Jikkou CLI to install. A value of `latest` will install the latest version of Jikkou CLI. |
| `jikkou_config` | | The path to the Jikkou CLI config file. If set, Jikkou CLI will be configured through the `JIKKOUCONFIG` environment variable. |
| `jikkou_wrapper` | `true` | If `true`, wrap calls of the Jikkou CLI binary to expose its `STDOUT`, `STDERR`, and exit code as outputs named `stdout`, `stderr`, and `exitcode` respectively. |

## Outputs

Only available when input `jikkou-wrapper` is `true`.

| Property | Description |
|------------|---------------------------------------------|
| `stdout` | STDOUT of the Jikkou CLI execution call. |
| `stderr` | STDERR of the Jikkou CLI execution call. |
| `exitcode` | Exit code of the Jikkou CLI execution call. |


## Documentation
Check the official [documentation](https://streamthoughts.github.io/jikkou/) for further usage about Jikkou CLI.


## 💡 Contributions

Any feedback, bug reports and PRs are greatly appreciated!

- **Source Code**: https://github.com/streamthoughts/setup-jikkou
- **Issue Tracker**: https://github.com/streamthoughts/jikkou/setup-jikkou

## 🙏 Show your support

You think this project can help you or your team to manage your Apache Kafka Cluster ?
Please ⭐ this repository to support us!

## License

Expand Down
11 changes: 11 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ 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 calls of the `jikkou` binary to expose its STDOUT, STDERR, and exit code as outputs named `stdout`, `stderr`, and `exitcode` respectively. Defaults to `true`.'
default: 'true'
required: false
outputs:
stdout:
description: 'STDOUT of the Jikkou CLI execution call (only available if `jikkou-wrapper` is `true`).'
stderr:
description: 'STDERR of the Jikkou CLI execution call (only available if `jikkou-wrapper` is `true`).'
exitcode:
description: 'Exit code of the Jikkou CLI execution call (only available if `jikkou-wrapper` is `true`).'
runs:
using: 'node20'
main: 'dist/index.js'
Expand Down
44 changes: 42 additions & 2 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 @@ -142,15 +176,21 @@ async function run() {
path.sep,
),
);
core.info(`Jikkou CLI path is ${pathToCLI}`);
core.addPath(pathToCLI);

if (inputConfig) {
const pathToConfigFile = path.resolve(inputConfig);
core.info(`Set environment variable JIKKOUCONFIG=${pathToConfigFile}`);
core.exportVariable("JIKKOUCONFIG", pathToConfigFile);
}

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

core.info(`Jikkou CLI path is ${pathToCLI}`);
core.addPath(pathToCLI);

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

0 comments on commit 5a0ed1d

Please sign in to comment.