Skip to content

Commit 7800739

Browse files
authored
chore: update deps, switch to parseFlags in actions-utils (#4)
1 parent c8e3d57 commit 7800739

File tree

7 files changed

+253
-272
lines changed

7 files changed

+253
-272
lines changed

.github/workflows/unit.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ on:
2020
- 'main'
2121
pull_request:
2222
branches:
23-
- 'main'
23+
- 'main'
2424
workflow_dispatch:
2525

2626
concurrency:
@@ -55,4 +55,4 @@ jobs:
5555
run: 'npm run lint'
5656

5757
- name: 'npm test'
58-
run: npm run test
58+
run: npm run test

dist/main/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/post/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 216 additions & 167 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,27 @@
3131
"@actions/core": "^1.6.0",
3232
"@actions/exec": "^1.1.1",
3333
"@actions/tool-cache": "^1.7.2",
34-
"@google-github-actions/actions-utils": "^0.1.6",
34+
"@google-github-actions/actions-utils": "^0.2.0",
3535
"@google-github-actions/setup-cloud-sdk": "^0.5.0",
3636
"sshpk": "^1.17.0"
3737
},
3838
"devDependencies": {
39-
"@types/chai": "^4.3.0",
39+
"@types/chai": "^4.3.1",
4040
"@types/mocha": "^9.1.0",
4141
"@types/sinon": "^10.0.11",
42-
"@types/node": "^17.0.21",
42+
"@types/node": "^17.0.24",
4343
"@types/sshpk": "^1.17.0",
44-
"@typescript-eslint/eslint-plugin": "^5.15.0",
45-
"@typescript-eslint/parser": "^5.15.0",
46-
"@vercel/ncc": "^0.33.3",
47-
"eslint": "^8.11.0",
44+
"@typescript-eslint/eslint-plugin": "^5.19.0",
45+
"@typescript-eslint/parser": "^5.19.0",
46+
"@vercel/ncc": "^0.33.4",
47+
"eslint": "^8.13.0",
4848
"eslint-config-prettier": "^8.5.0",
4949
"eslint-plugin-prettier": "^4.0.0",
50-
"prettier": "^2.6.0",
50+
"prettier": "^2.6.2",
5151
"ts-node": "^10.7.0",
52-
"typescript": "^4.6.2",
52+
"typescript": "^4.6.3",
5353
"mocha": "^9.2.2",
54-
"sinon": "^13.0.1",
54+
"sinon": "^13.0.2",
5555
"chai": "^4.3.6"
5656
}
5757
}

src/main.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ import * as exec from '@actions/exec';
2424
import * as toolCache from '@actions/tool-cache';
2525
import * as setupGcloud from '@google-github-actions/setup-cloud-sdk';
2626
import {
27+
errorMessage,
2728
exactlyOneOf,
2829
isPinnedToHead,
30+
parseFlags,
2931
pinnedToHeadWarning,
30-
errorMessage,
31-
randomFilepath,
3232
presence,
33+
randomFilepath,
3334
} from '@google-github-actions/actions-utils';
3435

3536
import sshpk from 'sshpk';
@@ -43,10 +44,6 @@ import {
4344
export const GCLOUD_METRICS_ENV_VAR = 'CLOUDSDK_METRICS_ENVIRONMENT';
4445
export const GCLOUD_METRICS_LABEL = 'github-actions-ssh-compute';
4546

46-
export function parseFlags(flags: string): RegExpMatchArray {
47-
return flags.match(/(".*?"|[^"\s=]+)+(?=\s*|\s*$)/g)!; // Split on space or "=" if not in quotes
48-
}
49-
5047
export async function run(): Promise<void> {
5148
try {
5249
core.exportVariable(GCLOUD_METRICS_ENV_VAR, GCLOUD_METRICS_LABEL);

tests/unit/ssh-compute.test.ts

Lines changed: 20 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import * as core from '@actions/core';
44
import * as exec from '@actions/exec';
55
import * as setupGcloud from '@google-github-actions/setup-cloud-sdk';
66
import { expect } from 'chai';
7-
import { run, parseFlags } from '../../src/main';
8-
import {run as postRun} from '../../src/post';
9-
import {EOL} from 'os';
7+
import { run } from '../../src/main';
8+
import { run as postRun } from '../../src/post';
9+
import { EOL } from 'os';
1010

1111
import { promises as fs } from 'fs';
1212

@@ -36,7 +36,7 @@ const fakeInputs: { [key: string]: string } = {
3636
};
3737

3838
function getInputMock(name: string): string {
39-
return fakeInputs[name];
39+
return fakeInputs[name];
4040
}
4141

4242
describe('#ssh-compute', function () {
@@ -95,8 +95,9 @@ describe('#ssh-compute', function () {
9595
this.stubs.getInput.withArgs('gcloud_component').returns('wrong_value');
9696
await run();
9797
expect(
98-
this.stubs.setFailed.withArgs(`${ERROR_PREFIX} invalid input received for gcloud_component: wrong_value`)
99-
.callCount,
98+
this.stubs.setFailed.withArgs(
99+
`${ERROR_PREFIX} invalid input received for gcloud_component: wrong_value`,
100+
).callCount,
100101
).to.be.at.least(1);
101102
});
102103

@@ -117,17 +118,19 @@ describe('#ssh-compute', function () {
117118
this.stubs.getInput.withArgs('command').returns('test command');
118119
await run();
119120
expect(
120-
this.stubs.setFailed.withArgs(`${ERROR_PREFIX} either \`command\` or \`script\` should be set`)
121-
.callCount,
121+
this.stubs.setFailed.withArgs(
122+
`${ERROR_PREFIX} either \`command\` or \`script\` should be set`,
123+
).callCount,
122124
).to.be.at.least(1);
123125
});
124126

125127
it('throws an error if neither script nor command is set', async function () {
126128
this.stubs.getInput.withArgs('command').returns(undefined);
127129
await run();
128130
expect(
129-
this.stubs.setFailed.withArgs(`${ERROR_PREFIX} either \`command\` or \`script\` should be set`)
130-
.callCount,
131+
this.stubs.setFailed.withArgs(
132+
`${ERROR_PREFIX} either \`command\` or \`script\` should be set`,
133+
).callCount,
131134
).to.be.at.least(1);
132135
});
133136

@@ -173,13 +176,17 @@ describe('#ssh-compute', function () {
173176
it('writes private key to the folder', async function () {
174177
this.stubs.getInput.withArgs('ssh_keys_dir').returns('temp-dir');
175178
await run();
176-
expect(this.stubs.writeFile.withArgs('temp-dir/google_compute_engine.pub').callCount).to.eq(1);
179+
expect(this.stubs.writeFile.withArgs('temp-dir/google_compute_engine.pub').callCount).to.eq(
180+
1,
181+
);
177182
});
178183

179184
it('writes public key to the folder', async function () {
180185
this.stubs.getInput.withArgs('ssh_keys_dir').returns('temp-dir');
181186
await run();
182-
expect(this.stubs.writeFile.withArgs('temp-dir/google_compute_engine.pub').callCount).to.eq(1);
187+
expect(this.stubs.writeFile.withArgs('temp-dir/google_compute_engine.pub').callCount).to.eq(
188+
1,
189+
);
183190
});
184191

185192
it('sets the correct command if script is provided', async function () {
@@ -227,76 +234,4 @@ describe('#ssh-compute', function () {
227234
expect(this.stubs.rm.callCount).to.eq(1);
228235
});
229236
});
230-
231-
describe('#parseFlags', () => {
232-
const cases = [
233-
{
234-
name: `with equals`,
235-
input: `--concurrency=2 --memory=2Gi`,
236-
exp: [`--concurrency`, `2`, `--memory`, `2Gi`],
237-
},
238-
{
239-
name: `with spaces`,
240-
input: `--concurrency 2 --memory 2Gi`,
241-
exp: [`--concurrency`, `2`, `--memory`, `2Gi`],
242-
},
243-
{
244-
name: `with equals and spaces`,
245-
input: `--concurrency 2 --memory=2Gi`,
246-
exp: [`--concurrency`, `2`, `--memory`, `2Gi`],
247-
},
248-
{
249-
name: `with equals and double quotes`,
250-
input: `--memory="2Gi"`,
251-
exp: [`--memory`, `"2Gi"`],
252-
},
253-
{
254-
name: `with space and double quotes`,
255-
input: `--memory "2Gi"`,
256-
exp: [`--memory`, `"2Gi"`],
257-
},
258-
{
259-
name: `with equals and space and double quotes`,
260-
input: `--memory="2Gi" --concurrency "2"`,
261-
exp: [`--memory`, `"2Gi"`, `--concurrency`, `"2"`],
262-
},
263-
{
264-
name: `with equals and space and some double quotes`,
265-
input: `--memory="2Gi" --concurrency 2`,
266-
exp: [`--memory`, `"2Gi"`, `--concurrency`, `2`],
267-
},
268-
{
269-
name: `with equals and single quotes`,
270-
input: `--memory='2Gi'`,
271-
exp: [`--memory`, `'2Gi'`],
272-
},
273-
{
274-
name: `with space and single quotes`,
275-
input: `--memory '2Gi'`,
276-
exp: [`--memory`, `'2Gi'`],
277-
},
278-
{
279-
name: `with equals and space and single quotes`,
280-
input: `--memory='2Gi' --concurrency '2'`,
281-
exp: [`--memory`, `'2Gi'`, `--concurrency`, `'2'`],
282-
},
283-
{
284-
name: `with equals and space and some single quotes`,
285-
input: `--memory='2Gi' --concurrency 2`,
286-
exp: [`--memory`, `'2Gi'`, `--concurrency`, `2`],
287-
},
288-
{
289-
name: `with double and single quotes`,
290-
input: `--memory='2Gi' --concurrency="2"`,
291-
exp: [`--memory`, `'2Gi'`, `--concurrency`, `"2"`],
292-
},
293-
];
294-
295-
cases.forEach((tc) => {
296-
it(tc.name, () => {
297-
const result = parseFlags(tc.input);
298-
expect(result).to.eql(tc.exp);
299-
});
300-
});
301-
});
302-
});
237+
});

0 commit comments

Comments
 (0)