mirror of
https://github.com/google-github-actions/setup-gcloud.git
synced 2026-08-20 02:09:26 +00:00
Update deps (#677)
This commit is contained in:
parent
5a5f7b85fc
commit
1eec0df8cf
5 changed files with 326 additions and 732 deletions
10
dist/index.js
vendored
10
dist/index.js
vendored
File diff suppressed because one or more lines are too long
751
package-lock.json
generated
751
package-lock.json
generated
File diff suppressed because it is too large
Load diff
16
package.json
16
package.json
|
|
@ -27,18 +27,18 @@
|
|||
"dependencies": {
|
||||
"@actions/core": "^1.10.1",
|
||||
"@actions/tool-cache": "^2.0.1",
|
||||
"@google-github-actions/actions-utils": "^0.4.10",
|
||||
"@google-github-actions/setup-cloud-sdk": "^1.1.3"
|
||||
"@google-github-actions/actions-utils": "^0.7.0",
|
||||
"@google-github-actions/setup-cloud-sdk": "^1.1.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.10.4",
|
||||
"@typescript-eslint/eslint-plugin": "^6.13.2",
|
||||
"@typescript-eslint/parser": "^6.13.2",
|
||||
"@types/node": "^20.11.5",
|
||||
"@typescript-eslint/eslint-plugin": "^6.19.1",
|
||||
"@typescript-eslint/parser": "^6.19.1",
|
||||
"@vercel/ncc": "^0.38.1",
|
||||
"eslint-config-prettier": "^9.1.0",
|
||||
"eslint-plugin-prettier": "^5.0.1",
|
||||
"eslint": "^8.55.0",
|
||||
"prettier": "^3.1.0",
|
||||
"eslint-plugin-prettier": "^5.1.3",
|
||||
"eslint": "^8.56.0",
|
||||
"prettier": "^3.2.4",
|
||||
"ts-node": "^10.9.2",
|
||||
"typescript": "^5.3.3"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,71 +14,38 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { describe, it } from 'node:test';
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert';
|
||||
|
||||
import { getExecOutput, ExecOptions } from '@actions/exec';
|
||||
import { gcloudRunJSON } from '@google-github-actions/setup-cloud-sdk';
|
||||
import { skipIfMissingEnv } from '@google-github-actions/actions-utils';
|
||||
|
||||
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(
|
||||
test(
|
||||
'#run',
|
||||
skipIfMissingEnvs('TEST_ACCOUNT', 'TEST_PROJECT_ID', 'TEST_COMPONENTS'),
|
||||
async () => {
|
||||
{
|
||||
concurrency: true,
|
||||
skip: skipIfMissingEnv('TEST_ACCOUNT', 'TEST_PROJECT_ID', 'TEST_COMPONENTS'),
|
||||
},
|
||||
async (suite) => {
|
||||
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)';
|
||||
await suite.test('has the correct account', async () => {
|
||||
const raw = await gcloudRunJSON(['--quiet', 'auth', 'list', '--filter', 'status:ACTIVE']);
|
||||
const result = raw?.at(0)?.acccount || '(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)';
|
||||
await suite.test('has the correct project_id', async () => {
|
||||
const raw = await gcloudRunJSON(['--quiet', 'config', 'list', 'core/project']);
|
||||
const result = 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']);
|
||||
await suite.test('includes the given components', async () => {
|
||||
const raw = await gcloudRunJSON(['--quiet', 'components', 'list', '--only-local-state']);
|
||||
const result = raw.map((entry: Record<string, any>) => entry.id);
|
||||
const members = testComponents.split(',').map((component) => component.trim());
|
||||
|
||||
const intersection = members.filter((v) => result.includes(v));
|
||||
|
|
@ -86,21 +53,3 @@ describe(
|
|||
});
|
||||
},
|
||||
);
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { afterEach, beforeEach, describe, mock, it } from 'node:test';
|
||||
import { mock, test } from 'node:test';
|
||||
import assert from 'node:assert';
|
||||
|
||||
import { promises as fs } from 'fs';
|
||||
|
|
@ -22,7 +22,6 @@ import * as setupGcloud from '@google-github-actions/setup-cloud-sdk';
|
|||
import { TestToolCache } from '@google-github-actions/setup-cloud-sdk';
|
||||
import * as core from '@actions/core';
|
||||
import * as toolCache from '@actions/tool-cache';
|
||||
import { clearEnv } from '@google-github-actions/actions-utils';
|
||||
|
||||
import { run } from '../src/main';
|
||||
|
||||
|
|
@ -81,58 +80,57 @@ const defaultMocks = (
|
|||
};
|
||||
};
|
||||
|
||||
describe('#run', async () => {
|
||||
beforeEach(async () => {
|
||||
test('#run', { concurrency: true }, async (suite) => {
|
||||
const originalEnv = Object.assign({}, process.env);
|
||||
|
||||
suite.beforeEach(async () => {
|
||||
await TestToolCache.start();
|
||||
// process.env.GITHUB_PATH = '/';
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
clearEnv((key: string) => key.startsWith(`GITHUB_`));
|
||||
suite.afterEach(async () => {
|
||||
process.env = originalEnv;
|
||||
await TestToolCache.stop();
|
||||
});
|
||||
|
||||
describe('download', async () => {
|
||||
it('downloads when no version is provided', async (t) => {
|
||||
const mocks = defaultMocks(t.mock, {
|
||||
version: '',
|
||||
});
|
||||
await run();
|
||||
|
||||
assert.match(mocks.installGcloudSDK.mock.calls?.at(0)?.arguments?.at(0), /\d+\.\d+\.\d+/);
|
||||
await suite.test('downloads when no version is provided', async (t) => {
|
||||
const mocks = defaultMocks(t.mock, {
|
||||
version: '',
|
||||
});
|
||||
await run();
|
||||
|
||||
it('downloads when version is "latest"', async (t) => {
|
||||
const mocks = defaultMocks(t.mock, {
|
||||
version: '',
|
||||
});
|
||||
await run();
|
||||
assert.match(mocks.installGcloudSDK.mock.calls?.at(0)?.arguments?.at(0), /\d+\.\d+\.\d+/);
|
||||
});
|
||||
|
||||
assert.match(mocks.installGcloudSDK.mock.calls?.at(0)?.arguments?.at(0), /\d+\.\d+\.\d+/);
|
||||
await suite.test('downloads when version is "latest"', async (t) => {
|
||||
const mocks = defaultMocks(t.mock, {
|
||||
version: '',
|
||||
});
|
||||
await run();
|
||||
|
||||
it('downloads when version is not installed', async (t) => {
|
||||
const mocks = defaultMocks(t.mock, {
|
||||
version: '5.6.7',
|
||||
});
|
||||
await run();
|
||||
assert.match(mocks.installGcloudSDK.mock.calls?.at(0)?.arguments?.at(0), /\d+\.\d+\.\d+/);
|
||||
});
|
||||
|
||||
assert.deepStrictEqual(mocks.installGcloudSDK.mock.calls?.at(0)?.arguments?.at(0), '5.6.7');
|
||||
await suite.test('downloads when version is not installed', async (t) => {
|
||||
const mocks = defaultMocks(t.mock, {
|
||||
version: '5.6.7',
|
||||
});
|
||||
await run();
|
||||
|
||||
it('downloads when version constraint is not satisfied', async (t) => {
|
||||
const mocks = defaultMocks(t.mock, {
|
||||
version: '>= 10.0.0',
|
||||
});
|
||||
await run();
|
||||
assert.deepStrictEqual(mocks.installGcloudSDK.mock.calls?.at(0)?.arguments?.at(0), '5.6.7');
|
||||
});
|
||||
|
||||
assert.deepStrictEqual(
|
||||
mocks.installGcloudSDK.mock.calls?.at(0)?.arguments?.at(0),
|
||||
'>= 10.0.0',
|
||||
);
|
||||
await suite.test('downloads when version constraint is not satisfied', async (t) => {
|
||||
const mocks = defaultMocks(t.mock, {
|
||||
version: '>= 10.0.0',
|
||||
});
|
||||
await run();
|
||||
|
||||
it('downloads when a version is installed but the version constraint is not satisfied', async (t) => {
|
||||
assert.deepStrictEqual(mocks.installGcloudSDK.mock.calls?.at(0)?.arguments?.at(0), '>= 10.0.0');
|
||||
});
|
||||
|
||||
await suite.test(
|
||||
'downloads when a version is installed but the version constraint is not satisfied',
|
||||
async (t) => {
|
||||
const mocks = defaultMocks(t.mock, {
|
||||
version: '>= 10.0.0',
|
||||
});
|
||||
|
|
@ -143,90 +141,78 @@ describe('#run', async () => {
|
|||
mocks.installGcloudSDK.mock.calls?.at(0)?.arguments?.at(0),
|
||||
'>= 10.0.0',
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
await suite.test('does not download when version is installed', async (t) => {
|
||||
const mocks = defaultMocks(t.mock, {
|
||||
version: '1.2.3',
|
||||
});
|
||||
await installFakeGcloud('1.2.3');
|
||||
await run();
|
||||
|
||||
it('does not download when version is installed', async (t) => {
|
||||
const mocks = defaultMocks(t.mock, {
|
||||
version: '1.2.3',
|
||||
});
|
||||
await installFakeGcloud('1.2.3');
|
||||
await run();
|
||||
|
||||
assert.deepStrictEqual(mocks.installGcloudSDK.mock.callCount(), 0);
|
||||
});
|
||||
|
||||
it('does not download when a version constraint is satisfied', async (t) => {
|
||||
const mocks = defaultMocks(t.mock, {
|
||||
version: '>= 1.0.0',
|
||||
});
|
||||
await installFakeGcloud('1.2.3');
|
||||
await run();
|
||||
|
||||
assert.deepStrictEqual(mocks.installGcloudSDK.mock.callCount(), 0);
|
||||
});
|
||||
assert.deepStrictEqual(mocks.installGcloudSDK.mock.callCount(), 0);
|
||||
});
|
||||
|
||||
describe('component installation', async () => {
|
||||
it('installs 1 additional component', async (t) => {
|
||||
const mocks = defaultMocks(t.mock, {
|
||||
install_components: 'beta',
|
||||
});
|
||||
await run();
|
||||
|
||||
assert.deepStrictEqual(mocks.installComponent.mock.calls?.at(0)?.arguments?.at(0), ['beta']);
|
||||
await suite.test('does not download when a version constraint is satisfied', async (t) => {
|
||||
const mocks = defaultMocks(t.mock, {
|
||||
version: '>= 1.0.0',
|
||||
});
|
||||
await installFakeGcloud('1.2.3');
|
||||
await run();
|
||||
|
||||
it('installs additional components', async (t) => {
|
||||
const mocks = defaultMocks(t.mock, {
|
||||
install_components: 'alpha, beta',
|
||||
});
|
||||
await run();
|
||||
|
||||
assert.deepStrictEqual(mocks.installComponent.mock.calls?.at(0)?.arguments?.at(0), [
|
||||
'alpha',
|
||||
'beta',
|
||||
]);
|
||||
});
|
||||
assert.deepStrictEqual(mocks.installGcloudSDK.mock.callCount(), 0);
|
||||
});
|
||||
|
||||
describe('authentication', async () => {
|
||||
const originalEnv = Object.assign({}, process.env);
|
||||
|
||||
afterEach(async () => {
|
||||
process.env = originalEnv;
|
||||
await suite.test('installs 1 additional component', async (t) => {
|
||||
const mocks = defaultMocks(t.mock, {
|
||||
install_components: 'beta',
|
||||
});
|
||||
await run();
|
||||
|
||||
it('authenticates if GOOGLE_GHA_CREDS is set', async (t) => {
|
||||
const mocks = defaultMocks(t.mock, {
|
||||
install_components: 'alpha, beta',
|
||||
});
|
||||
|
||||
process.env.GOOGLE_GHA_CREDS_PATH = '/foo/bar/path.json';
|
||||
|
||||
await run();
|
||||
|
||||
assert.deepStrictEqual(mocks.authenticateGcloudSDK.mock.callCount(), 1);
|
||||
});
|
||||
assert.deepStrictEqual(mocks.installComponent.mock.calls?.at(0)?.arguments?.at(0), ['beta']);
|
||||
});
|
||||
|
||||
describe('configuration', async () => {
|
||||
it('sets the project ID if provided', async (t) => {
|
||||
const mocks = defaultMocks(t.mock, {
|
||||
project_id: 'test',
|
||||
});
|
||||
await run();
|
||||
await suite.test('installs additional components', async (t) => {
|
||||
const mocks = defaultMocks(t.mock, {
|
||||
install_components: 'alpha, beta',
|
||||
});
|
||||
await run();
|
||||
|
||||
assert.deepStrictEqual(mocks.setProject.mock.calls?.at(0)?.arguments?.at(0), 'test');
|
||||
assert.deepStrictEqual(mocks.installComponent.mock.calls?.at(0)?.arguments?.at(0), [
|
||||
'alpha',
|
||||
'beta',
|
||||
]);
|
||||
});
|
||||
|
||||
await suite.test('authenticates if GOOGLE_GHA_CREDS is set', async (t) => {
|
||||
const mocks = defaultMocks(t.mock, {
|
||||
install_components: 'alpha, beta',
|
||||
});
|
||||
|
||||
it('does not set the project ID if not provided', async (t) => {
|
||||
const mocks = defaultMocks(t.mock, {
|
||||
project_id: '',
|
||||
});
|
||||
await run();
|
||||
process.env.GOOGLE_GHA_CREDS_PATH = '/foo/bar/path.json';
|
||||
|
||||
assert.deepStrictEqual(mocks.setProject.mock.callCount(), 0);
|
||||
await run();
|
||||
|
||||
assert.deepStrictEqual(mocks.authenticateGcloudSDK.mock.callCount(), 1);
|
||||
});
|
||||
|
||||
await suite.test('sets the project ID if provided', async (t) => {
|
||||
const mocks = defaultMocks(t.mock, {
|
||||
project_id: 'test',
|
||||
});
|
||||
await run();
|
||||
|
||||
assert.deepStrictEqual(mocks.setProject.mock.calls?.at(0)?.arguments?.at(0), 'test');
|
||||
});
|
||||
|
||||
await suite.test('does not set the project ID if not provided', async (t) => {
|
||||
const mocks = defaultMocks(t.mock, {
|
||||
project_id: '',
|
||||
});
|
||||
await run();
|
||||
|
||||
assert.deepStrictEqual(mocks.setProject.mock.callCount(), 0);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue