Skip to content

Commit c2599db

Browse files
authored
Update and drop unnecessary deps (#662)
1 parent 7c7fdb0 commit c2599db

File tree

10 files changed

+386
-1052
lines changed

10 files changed

+386
-1052
lines changed

.eslintrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,8 @@ module.exports = {
2424
'plugin:@typescript-eslint/recommended',
2525
'plugin:prettier/recommended',
2626
],
27+
28+
rules: {
29+
'@typescript-eslint/no-explicit-any': 'off',
30+
},
2731
};

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ branding:
5353

5454
runs:
5555
using: 'node20'
56-
main: 'dist/main/index.js'
56+
main: 'dist/index.js'

dist/index.js

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

dist/main/index.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

package-lock.json

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

package.json

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
"description": "Setup gcloud GitHub action",
55
"main": "dist/main/index.js",
66
"scripts": {
7-
"build": "ncc build -m src/main.ts -o dist/main",
7+
"build": "ncc build -m src/main.ts",
88
"format": "prettier --write **/*.ts",
9-
"integration": "mocha -r ts-node/register -t 180s 'tests/integration/*.test.ts'",
9+
"integration": "node --require ts-node/register --test-reporter spec --test tests/integration.test.ts",
1010
"lint": "eslint . --ext .ts,.tsx",
11-
"test": "mocha -r ts-node/register -t 180s 'tests/*.test.ts'"
11+
"test": "node --require ts-node/register --test-reporter spec --test tests/setup-gcloud.test.ts"
1212
},
1313
"repository": {
1414
"type": "git",
@@ -27,25 +27,19 @@
2727
"dependencies": {
2828
"@actions/core": "^1.10.1",
2929
"@actions/tool-cache": "^2.0.1",
30-
"@google-github-actions/actions-utils": "^0.4.9",
30+
"@google-github-actions/actions-utils": "^0.4.10",
3131
"@google-github-actions/setup-cloud-sdk": "^1.1.3"
3232
},
3333
"devDependencies": {
34-
"@types/chai": "^4.3.10",
35-
"@types/mocha": "^10.0.4",
36-
"@types/node": "^20.9.0",
37-
"@types/sinon": "^17.0.1",
38-
"@typescript-eslint/eslint-plugin": "^6.10.0",
39-
"@typescript-eslint/parser": "^6.10.0",
34+
"@types/node": "^20.10.4",
35+
"@typescript-eslint/eslint-plugin": "^6.13.2",
36+
"@typescript-eslint/parser": "^6.13.2",
4037
"@vercel/ncc": "^0.38.1",
41-
"chai": "^4.3.10",
42-
"eslint": "^8.53.0",
43-
"eslint-config-prettier": "^9.0.0",
38+
"eslint-config-prettier": "^9.1.0",
4439
"eslint-plugin-prettier": "^5.0.1",
45-
"mocha": "^10.2.0",
46-
"prettier": "^3.0.3",
47-
"sinon": "^17.0.1",
48-
"ts-node": "^10.9.1",
49-
"typescript": "^5.2.2"
40+
"eslint": "^8.55.0",
41+
"prettier": "^3.1.0",
42+
"ts-node": "^10.9.2",
43+
"typescript": "^5.3.3"
5044
}
5145
}

tests/integration.test.ts

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { describe, it } from 'node:test';
18+
import assert from 'node:assert';
19+
20+
import { getExecOutput, ExecOptions } from '@actions/exec';
21+
22+
const skipIfMissingEnvs = (...keys: string[]): { skip: string } | undefined => {
23+
const missingKeys: string[] = [];
24+
25+
for (const key of keys) {
26+
if (!(key in process.env)) {
27+
missingKeys.push(key);
28+
}
29+
}
30+
31+
if (missingKeys.length > 0) {
32+
return { skip: `missing $${missingKeys.join(', $')}` };
33+
}
34+
return undefined;
35+
};
36+
37+
describe(
38+
'#run',
39+
skipIfMissingEnvs('TEST_ACCOUNT', 'TEST_PROJECT_ID', 'TEST_COMPONENTS'),
40+
async () => {
41+
const testAccount = process.env.TEST_ACCOUNT!;
42+
const testProjectID = process.env.TEST_PROJECT_ID!;
43+
const testComponents = process.env.TEST_COMPONENTS!;
44+
45+
it('has the correct account', async () => {
46+
const raw = await gcloudRun([
47+
'--quiet',
48+
'auth',
49+
'list',
50+
'--filter',
51+
'status:ACTIVE',
52+
'--format',
53+
'json',
54+
]);
55+
const result = JSON.parse(raw)[0]?.['account'] || '(unset)';
56+
assert.deepStrictEqual(result, testAccount);
57+
});
58+
59+
it('has the correct project_id', async () => {
60+
const raw = await gcloudRun([
61+
'--quiet',
62+
'config',
63+
'list',
64+
'core/project',
65+
'--format',
66+
'json',
67+
]);
68+
const result = JSON.parse(raw)['core']?.['project'] || '(unset)';
69+
assert.deepStrictEqual(result, testProjectID);
70+
});
71+
72+
it('includes the given components', async () => {
73+
const raw = await gcloudRun([
74+
'--quiet',
75+
'components',
76+
'list',
77+
'--only-local-state',
78+
'--format',
79+
'json',
80+
]);
81+
const result = JSON.parse(raw).map((entry: Record<string, any>) => entry['id']);
82+
const members = testComponents.split(',').map((component) => component.trim());
83+
84+
const intersection = members.filter((v) => result.includes(v));
85+
assert.deepStrictEqual(intersection, members);
86+
});
87+
},
88+
);
89+
90+
async function gcloudRun(cmd: string[], options?: ExecOptions): Promise<string> {
91+
// A workaround for https://github.com/actions/toolkit/issues/229
92+
let toolCommand = 'gcloud';
93+
if (process.platform == 'win32') {
94+
toolCommand = 'gcloud.cmd';
95+
}
96+
97+
const opts = Object.assign({}, { silent: true, ignoreReturnCode: true }, options);
98+
const commandString = `${toolCommand} ${cmd.join(' ')}`;
99+
100+
const result = await getExecOutput(toolCommand, cmd, opts);
101+
if (result.exitCode !== 0) {
102+
const errMsg = result.stderr || `command exited ${result.exitCode}, but stderr had no output`;
103+
throw new Error(`failed to execute command \`${commandString}\`: ${errMsg}`);
104+
}
105+
return result.stdout;
106+
}

tests/integration/integration.test.ts

Lines changed: 0 additions & 84 deletions
This file was deleted.

0 commit comments

Comments
 (0)