1010 */
1111
1212// Node.js core
13- const fs = ( __nccwpck_require__(7147).promises );
13+ const fs = __nccwpck_require__(7147);
1414const os = __nccwpck_require__(2037);
1515const path = __nccwpck_require__(1017);
1616
1717// Github toolkit
1818const core = __nccwpck_require__(2186);
1919const github = __nccwpck_require__(5438);
2020const tc = __nccwpck_require__(7784);
21-
2221const http = __nccwpck_require__(6255);
2322
24- const project = {
25- owner: "streamthoughts",
26- repo: "jikkou",
27- };
23+ const project = { owner: "streamthoughts", repo: "jikkou" };
2824
2925async 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)
5650function 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)
6459function 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
9188async 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
99105async 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