Skip to content

Commit

Permalink
Update and drop unnecessary deps (#662)
Browse files Browse the repository at this point in the history
  • Loading branch information
sethvargo committed Dec 8, 2023
1 parent 7c7fdb0 commit c2599db
Show file tree
Hide file tree
Showing 10 changed files with 386 additions and 1,052 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.js
Expand Up @@ -24,4 +24,8 @@ module.exports = {
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],

rules: {
'@typescript-eslint/no-explicit-any': 'off',
},
};
2 changes: 1 addition & 1 deletion action.yml
Expand Up @@ -53,4 +53,4 @@ branding:

runs:
using: 'node20'
main: 'dist/main/index.js'
main: 'dist/index.js'
5 changes: 5 additions & 0 deletions dist/index.js

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions dist/main/index.js

This file was deleted.

972 changes: 115 additions & 857 deletions package-lock.json

Large diffs are not rendered by default.

30 changes: 12 additions & 18 deletions package.json
Expand Up @@ -4,11 +4,11 @@
"description": "Setup gcloud GitHub action",
"main": "dist/main/index.js",
"scripts": {
"build": "ncc build -m src/main.ts -o dist/main",
"build": "ncc build -m src/main.ts",
"format": "prettier --write **/*.ts",
"integration": "mocha -r ts-node/register -t 180s 'tests/integration/*.test.ts'",
"integration": "node --require ts-node/register --test-reporter spec --test tests/integration.test.ts",
"lint": "eslint . --ext .ts,.tsx",
"test": "mocha -r ts-node/register -t 180s 'tests/*.test.ts'"
"test": "node --require ts-node/register --test-reporter spec --test tests/setup-gcloud.test.ts"
},
"repository": {
"type": "git",
Expand All @@ -27,25 +27,19 @@
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/tool-cache": "^2.0.1",
"@google-github-actions/actions-utils": "^0.4.9",
"@google-github-actions/actions-utils": "^0.4.10",
"@google-github-actions/setup-cloud-sdk": "^1.1.3"
},
"devDependencies": {
"@types/chai": "^4.3.10",
"@types/mocha": "^10.0.4",
"@types/node": "^20.9.0",
"@types/sinon": "^17.0.1",
"@typescript-eslint/eslint-plugin": "^6.10.0",
"@typescript-eslint/parser": "^6.10.0",
"@types/node": "^20.10.4",
"@typescript-eslint/eslint-plugin": "^6.13.2",
"@typescript-eslint/parser": "^6.13.2",
"@vercel/ncc": "^0.38.1",
"chai": "^4.3.10",
"eslint": "^8.53.0",
"eslint-config-prettier": "^9.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.0.1",
"mocha": "^10.2.0",
"prettier": "^3.0.3",
"sinon": "^17.0.1",
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
"eslint": "^8.55.0",
"prettier": "^3.1.0",
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
}
}
106 changes: 106 additions & 0 deletions tests/integration.test.ts
@@ -0,0 +1,106 @@
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { describe, it } from 'node:test';
import assert from 'node:assert';

import { getExecOutput, ExecOptions } from '@actions/exec';

const skipIfMissingEnvs = (...keys: string[]): { skip: string } | undefined => {
const missingKeys: string[] = [];

for (const key of keys) {
if (!(key in process.env)) {
missingKeys.push(key);
}
}

if (missingKeys.length > 0) {
return { skip: `missing $${missingKeys.join(', $')}` };
}
return undefined;
};

describe(
'#run',
skipIfMissingEnvs('TEST_ACCOUNT', 'TEST_PROJECT_ID', 'TEST_COMPONENTS'),
async () => {
const testAccount = process.env.TEST_ACCOUNT!;
const testProjectID = process.env.TEST_PROJECT_ID!;
const testComponents = process.env.TEST_COMPONENTS!;

it('has the correct account', async () => {
const raw = await gcloudRun([
'--quiet',
'auth',
'list',
'--filter',
'status:ACTIVE',
'--format',
'json',
]);
const result = JSON.parse(raw)[0]?.['account'] || '(unset)';
assert.deepStrictEqual(result, testAccount);
});

it('has the correct project_id', async () => {
const raw = await gcloudRun([
'--quiet',
'config',
'list',
'core/project',
'--format',
'json',
]);
const result = JSON.parse(raw)['core']?.['project'] || '(unset)';
assert.deepStrictEqual(result, testProjectID);
});

it('includes the given components', async () => {
const raw = await gcloudRun([
'--quiet',
'components',
'list',
'--only-local-state',
'--format',
'json',
]);
const result = JSON.parse(raw).map((entry: Record<string, any>) => entry['id']);
const members = testComponents.split(',').map((component) => component.trim());

const intersection = members.filter((v) => result.includes(v));
assert.deepStrictEqual(intersection, members);
});
},
);

async function gcloudRun(cmd: string[], options?: ExecOptions): Promise<string> {
// A workaround for https://github.com/actions/toolkit/issues/229
let toolCommand = 'gcloud';
if (process.platform == 'win32') {
toolCommand = 'gcloud.cmd';
}

const opts = Object.assign({}, { silent: true, ignoreReturnCode: true }, options);
const commandString = `${toolCommand} ${cmd.join(' ')}`;

const result = await getExecOutput(toolCommand, cmd, opts);
if (result.exitCode !== 0) {
const errMsg = result.stderr || `command exited ${result.exitCode}, but stderr had no output`;
throw new Error(`failed to execute command \`${commandString}\`: ${errMsg}`);
}
return result.stdout;
}
84 changes: 0 additions & 84 deletions tests/integration/integration.test.ts

This file was deleted.

0 comments on commit c2599db

Please sign in to comment.