Skip to content

Commit 07b10a5

Browse files
authored
improvements
1 parent a591a6f commit 07b10a5

4 files changed

Lines changed: 70 additions & 32 deletions

File tree

.github/workflows/check-dist.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ jobs:
3939

4040
- name: Install Dependencies
4141
id: install
42-
run: npm ci
42+
run: pnpm install
4343

4444
- name: Build dist/ Directory
4545
id: build
46-
run: npm run bundle
46+
run: pnpm run bundle
4747

4848
# This will fail the workflow if the `dist/` directory is different than
4949
# expected.

.github/workflows/ci.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,20 @@ jobs:
2929
cache: npm
3030

3131
- name: Install Dependencies
32-
id: npm-ci
33-
run: npm ci
32+
id: pnpm-install
33+
run: pnpm install
3434

3535
- name: Check Format
36-
id: npm-format-check
37-
run: npm run format:check
36+
id: pnpm-format-check
37+
run: pnpm run format:check
3838

3939
- name: Lint
40-
id: npm-lint
41-
run: npm run lint
40+
id: pnpm-lint
41+
run: pnpm run lint
4242

4343
- name: Test
44-
id: npm-ci-test
45-
run: npm run ci-test
44+
id: pnpm-ci-test
45+
run: pnpm run ci-test
4646

4747
test-action:
4848
name: GitHub Actions Test

.github/workflows/linter.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434

3535
- name: Install Dependencies
3636
id: install
37-
run: npm ci
37+
run: pnpm install
3838

3939
- name: Lint Codebase
4040
id: super-linter

src/main.ts

Lines changed: 59 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,95 @@
11
import * as core from '@actions/core'
2+
import * as github from '@actions/github'
23
import { arch } from 'os'
34
import { platform } from 'process'
45
import fs from 'fs';
56
import { mkdir } from 'fs/promises';
67
import { Readable } from 'stream';
78
import { finished } from 'stream/promises';
89
import path from 'path';
10+
import { createReadStream } from 'fs';
11+
import { createWriteStream } from 'fs';
12+
import { pipeline } from 'stream';
13+
import { promisify } from 'util';
14+
import unzipper from 'unzipper';
15+
import execa from 'execa';
916

1017
export async function run(): Promise<void> {
1118
try {
12-
// const ms: string = core.getInput('milliseconds')
19+
const action = core.getInput('action');
20+
const project = core.getInput('project');
21+
let pipelabVersion = core.getInput('pipelab-version');
1322

14-
// // Debug logs are only output if the `ACTIONS_STEP_DEBUG` secret is true
15-
// core.debug(`Waiting ${ms} milliseconds ...`)
23+
console.log(`Action: ${action}`);
24+
console.log(`Project: ${project}`);
25+
console.log(`Pipelab Version: ${pipelabVersion}`);
1626

17-
// // Log the current timestamp, wait, then log the new timestamp
18-
// core.debug(new Date().toTimeString())
19-
// await wait(parseInt(ms, 10))
20-
// core.debug(new Date().toTimeString())
21-
22-
// // Set outputs for other workflow steps to use
23-
// core.setOutput('time', new Date().toTimeString())
27+
if (!pipelabVersion) {
28+
console.log('No Pipelab version specified, fetching the latest version...');
29+
const res = await fetch('https://api.github.com/repos/CynToolkit/pipelab/releases/latest');
30+
const latestRelease = await res.json();
31+
pipelabVersion = latestRelease.tag_name.replace('v', '');
32+
console.log(`Latest Pipelab Version: ${pipelabVersion}`);
33+
}
2434

25-
const currentArch = arch()
26-
const currentPlatform = platform
35+
const currentArch = arch();
36+
const currentPlatform = platform;
2737

28-
console.log(`Current Arch: ${currentArch}`)
29-
console.log(`Current Platform: ${currentPlatform}`)
38+
console.log(`Current Arch: ${currentArch}`);
39+
console.log(`Current Platform: ${currentPlatform}`);
3040

3141
const downloadFile = (async (url: string, fileName: string) => {
42+
console.log(`Downloading file from ${url} to ${fileName}`);
3243
const res = await fetch(url);
3344
if (!res.body) {
3445
throw new Error('Response body is undefined');
3546
}
36-
if (!fs.existsSync("downloads")) await mkdir("downloads"); //Optional if you already have downloads directory
47+
if (!fs.existsSync("downloads")) {
48+
console.log('Creating downloads directory...');
49+
await mkdir("downloads");
50+
}
3751
const destination = path.resolve("./downloads", fileName);
3852
const fileStream = fs.createWriteStream(destination, { flags: 'wx' });
3953
await finished(Readable.fromWeb(res.body).pipe(fileStream));
54+
console.log(`Downloaded file to ${destination}`);
4055
});
4156

57+
const extractZip = async (filePath: string, extractTo: string) => {
58+
console.log(`Extracting zip file from ${filePath} to ${extractTo}`);
59+
await pipeline(
60+
createReadStream(filePath),
61+
unzipper.Extract({ path: extractTo })
62+
);
63+
console.log(`Extracted zip file to ${extractTo}`);
64+
};
4265

4366
if (currentArch === 'x64' && currentPlatform === 'win32') {
44-
core.setFailed('You are using a 64-bit Windows machine')
67+
core.setFailed('You are using a 64-bit Windows machine');
4568
}
4669
else if (currentArch === 'x64' && currentPlatform === 'linux') {
47-
console.log('You are using a 64-bit Linux machine')
48-
await downloadFile("https://github.com/CynToolkit/pipelab/releases/download/v1.4.8/Pipelab-linux-x64-1.4.8.zip", "pipelab.zip")
70+
console.log('You are using a 64-bit Linux machine');
71+
await downloadFile(`https://github.com/CynToolkit/pipelab/releases/download/v${pipelabVersion}/Pipelab-linux-x64-${pipelabVersion}.zip`, "pipelab.zip");
72+
await extractZip("./downloads/pipelab.zip", "./downloads");
73+
74+
const workspace = process.env.GITHUB_WORKSPACE || '';
75+
const jsonProject = path.resolve(workspace, project);
76+
const tmpLogFile = path.resolve('./downloads', 'log.txt');
77+
const args = ['--', '--project', jsonProject, '--action', action, '--output', tmpLogFile];
78+
79+
console.log(`Running Pipelab with args: ${args.join(' ')}`);
80+
try {
81+
const { stdout } = await execa('./downloads/pipelab', args);
82+
console.log(stdout);
83+
} catch (error) {
84+
console.error(error.stderr);
85+
core.setFailed(error.stderr);
86+
}
4987
}
5088
else {
51-
core.setFailed('You are using an unsupported platform')
89+
core.setFailed('You are using an unsupported platform');
5290
}
5391
} catch (error) {
54-
// Fail the workflow run if an error occurs
55-
if (error instanceof Error) core.setFailed(error.message)
92+
console.error(error);
93+
if (error instanceof Error) core.setFailed(error.message);
5694
}
5795
}

0 commit comments

Comments
 (0)