Skip to content

Commit 64ed61c

Browse files
committed
fix: setup-jikkou.js
1 parent 1f598c6 commit 64ed61c

8 files changed

Lines changed: 131 additions & 46 deletions

File tree

.github/workflows/setup-jikkou.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
strategy:
1818
matrix:
1919
os: [ubuntu-latest, macos-latest]
20-
jikkou-versions: [0.27.0, latest]
20+
jikkou-versions: [0.27.0, 0.28.0, latest]
2121

2222
steps:
2323
- name: Checkout GitHub repository
@@ -29,11 +29,12 @@ jobs:
2929
uses: ./
3030
with:
3131
jikkou_version: ${{ matrix['jikkou-versions'] }}
32+
jikkou_config: ./config/jikkouconfig.json
3233

3334
- name: Validate Jikkou Version - ${{ matrix['jikkou-versions'] }}
3435
if: ${{ matrix['jikkou-versions'] != 'latest' }}
3536
run: jikkou -V | grep ${{ matrix['jikkou-versions']}}
3637

3738
- name: Validate Jikkou Version - ${{ matrix['jikkou-versions'] }}
3839
if: ${{ matrix['jikkou-versions'] == 'latest' }}
39-
run: jikkou -V | grep 'Jikkou version'
40+
run: jikkou -V | grep 'Jikkou version'

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/node_modules/
2+
/.idea/

README.md

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# setup-jikkou
22

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

68
* Downloading a specific version of **Jikkou CLI** and adding it to the `PATH`.
9+
* Configuring **JIKKOU CLI** with a custom configuration file.
710

811
After you've used the action, subsequent steps in the same job can run arbitrary Jikkou commands using the GitHub
912
Actions run syntax. This allows most Jikkou commands to work exactly like they do on your local command line.
@@ -12,18 +15,36 @@ Actions run syntax. This allows most Jikkou commands to work exactly like they d
1215

1316
```yaml
1417
steps:
15-
- uses: streamthoughts/setup-jikkou@v1
18+
- uses: streamthoughts/setup-jikkou@v1
1619
```
1720
1821
A specific version of Jikkou CLI can be installed:
1922
2023
```yaml
2124
steps:
22-
- uses: streamthoughts/setup-jikkou@v1
23-
with:
24-
jikkou_version: 0.28.0
25+
- uses: streamthoughts/setup-jikkou@v0.1.0
26+
with:
27+
jikkou_version: 0.28.0
2528
```
2629
30+
A custom configuration file can be specified:
31+
32+
```yaml
33+
steps:
34+
- uses: streamthoughts/setup-jikkou@v0.1.0
35+
with:
36+
jikkou_config: ./config/jikkouconfig.json
37+
```
38+
39+
## Inputs
40+
41+
This Action additionally supports the following inputs :
42+
43+
| Property | Default | Description |
44+
|------------------|----------|--------------------------------------------------------------------------------------------------------------------------------|
45+
| `jikkou_version` | `latest` | The version of Jikkou CLI to install. A value of `latest` will install the latest version of Jikkou CLI. |
46+
| `jikkou_config` | | The path to the Jikkou CLI config file. If set, Jikkou CLI will be configured through the `JIKKOUCONFIG` environment variable. |
47+
2748
## License
2849

2950
This code base is available under the Apache License, version 2.

action.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ inputs:
66
description: 'The version of Jikkou CLI to install. A value of `latest` will install the latest version of Jikkou CLI. Defaults to `latest`.'
77
default: 'latest'
88
required: false
9+
jikkou_config:
10+
description: 'The path to the Jikkou CLI config file. If set, Jikkou CLI will be configured through the `JIKKOUCONFIG` environment variable.'
11+
required: false
912
runs:
1013
using: 'node20'
1114
main: 'dist/index.js'

config/jikkouconfig.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"currentContext": "github-action",
3+
"github-action": {
4+
"configProps": {}
5+
}
6+
}

dist/index.js

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,20 @@
1010
*/
1111

1212
// Node.js core
13-
const fs = (__nccwpck_require__(7147).promises);
13+
const fs = __nccwpck_require__(7147);
1414
const os = __nccwpck_require__(2037);
1515
const path = __nccwpck_require__(1017);
1616

1717
// Github toolkit
1818
const core = __nccwpck_require__(2186);
1919
const github = __nccwpck_require__(5438);
2020
const tc = __nccwpck_require__(7784);
21-
2221
const http = __nccwpck_require__(6255);
2322

24-
const project = {
25-
owner: "streamthoughts",
26-
repo: "jikkou",
27-
};
23+
const project = { owner: "streamthoughts", repo: "jikkou" };
2824

2925
async function downloadCLI(url) {
30-
core.debug(`Downloading Jikkou CLI from ${url}`);
26+
core.info(`Downloading Jikkou CLI from ${url}`);
3127
const pathToCLIZip = await tc.downloadTool(url);
3228

3329
let pathToCLI = "";
@@ -43,27 +39,27 @@ async function downloadCLI(url) {
4339
pathToCLI = await tc.extractZip(pathToCLIZip);
4440
}
4541

46-
core.debug(`Jikkou CLI path is ${pathToCLI}.`);
47-
4842
if (!pathToCLIZip || !pathToCLI) {
4943
throw new Error(`Unable to download Jikkou from ${url}`);
5044
}
51-
5245
return pathToCLI;
5346
}
5447

55-
// arch in [arm, x32, x64...] (https://nodejs.org/api/os.html#os_os_arch)
48+
// arch in [arm, x32, x64...]
49+
// (https://nodejs.org/api/os.html#os_os_platform)
5650
function mapArch(arch) {
5751
const mappings = {
5852
x64: "x86_64",
5953
};
6054
return mappings[arch] || arch;
6155
}
6256

63-
// os in [darwin, linux, win32...] (https://nodejs.org/api/os.html#os_os_platform)
57+
// os in [darwin, linux, win32...]
58+
// (https://nodejs.org/api/os.html#os_os_platform)
6459
function mapOS(os) {
6560
const mappings = {
6661
win32: "windows",
62+
darwin: "osx",
6763
};
6864
return mappings[os] || os;
6965
}
@@ -76,8 +72,9 @@ async function getReleaseVersion(version) {
7672
},
7773
});
7874

79-
const url = `https://api.github.com/repos/${project.owner}/${project.repo}/releases/${version}`;
80-
const res = await _http.get(url);
75+
const res = await _http.get(
76+
`https://api.github.com/repos/${project.owner}/${project.repo}/releases/${version}`,
77+
);
8178
const body = await res.readBody();
8279
const response = JSON.parse(body);
8380
return response;
@@ -90,24 +87,34 @@ async function findLatestReleaseVersion() {
9087

9188
async function getBuild(version, platform, arch) {
9289
const response = await getReleaseVersion(`tags/v${version}`);
90+
if (!response || !response.assets) return null;
91+
9392
const asset = response.assets.find((asset) =>
9493
asset.name.includes(`jikkou-${version}-${platform}-${arch}.zip`),
9594
);
96-
return !asset ? null : { url: `${asset.browser_download_url}` };
95+
return !asset
96+
? null
97+
: {
98+
name: `${asset.name}`,
99+
url: `${asset.browser_download_url}`,
100+
created_at: `${asset.created_at}`,
101+
size: `${asset.size}`,
102+
};
97103
}
98104

99105
async function run() {
100106
try {
101107
// Gather GitHub Actions inputs
102108
const inputVersion = core.getInput("jikkou_version") || "latest";
109+
const inputConfig = core.getInput("jikkou_config");
103110

104111
// Gather OS details
105112
const osPlatform = os.platform();
106113
const osArch = os.arch();
107114
core.debug(`OS: {platform:"${osPlatform}", arch: "${osArch}"}`);
108115

109116
// Gather Release
110-
core.debug(`Finding releases for Jikkou version "${inputVersion}"`);
117+
core.info(`Finding releases for Jikkou version "${inputVersion}"`);
111118
const platform = mapOS(osPlatform);
112119
const arch = mapArch(osArch);
113120

@@ -116,22 +123,42 @@ async function run() {
116123
version = await findLatestReleaseVersion();
117124
}
118125

119-
core.debug(
126+
core.info(
120127
`Getting build for Jikkou version ${version}: ${platform} ${arch}`,
121128
);
129+
122130
const build = await getBuild(version, platform, arch);
123131
if (!build) {
124132
throw new Error(
125133
`Jikkou version ${version} not available for ${platform} and ${arch}`,
126134
);
127135
}
128-
core.debug(build);
129-
130136
// Download requested version
131-
const pathToCLI = await downloadCLI(build.url);
137+
const pathToCLIDirectory = await downloadCLI(build.url);
132138

133139
// Add to path
140+
const pathToCLI = path.resolve(
141+
[pathToCLIDirectory, build.name.replace(".zip", ""), "bin"].join(
142+
path.sep,
143+
),
144+
);
145+
core.info(`Jikkou CLI path is ${pathToCLI}`);
134146
core.addPath(pathToCLI);
147+
148+
if (inputConfig) {
149+
const pathToConfigFile = path.resolve(inputConfig);
150+
core.info(`Set environment variable JIKKOUCONFIG=${pathToConfigFile}`);
151+
core.exportVariable("JIKKOUCONFIG", pathToConfigFile);
152+
}
153+
154+
const release = {
155+
version: version,
156+
name: build.name,
157+
url: build.url,
158+
created_at: build.created_at,
159+
size: build.size,
160+
};
161+
135162
return release;
136163
} catch (error) {
137164
core.error(error);

0 commit comments

Comments
 (0)