Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ inputs:
default: false
required: false

skip_auth_check:
description: |-
Skip the check for an authenticated `gcloud` and suppress the warning
emitted when none is found. This is useful when the action is only used
to install components or to put `gcloud` on the PATH (for example, to
drive a local emulator) and no Google Cloud credentials are needed.

⚠️ If you enable this, the action will not tell you when `gcloud` is
unauthenticated, even if a later step needs credentials.
default: false
required: false

outputs:
version:
description: |-
Expand Down
3 changes: 3 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export async function run(): Promise<void> {
let version = presence(core.getInput('version'));
const components = core.getInput('install_components');
const projectId = core.getInput('project_id');
const skipAuthCheck = parseBoolean(core.getInput('skip_auth_check'));
const cache = parseBoolean(core.getInput('cache'));

if (skipInstall) {
Expand Down Expand Up @@ -105,6 +106,8 @@ export async function run(): Promise<void> {
if (credFile) {
await authenticateGcloudSDK(credFile);
core.info('Successfully authenticated');
} else if (skipAuthCheck) {
core.debug(`Skipping the authentication check ("skip_auth_check" was true)`);
} else {
let authed;
try {
Expand Down
35 changes: 35 additions & 0 deletions tests/setup-gcloud.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,41 @@ test('#run', { concurrency: true }, async (suite) => {

assert.deepStrictEqual(mocks.setProject.mock.callCount(), 0);
});

await suite.test('warns when there is no authentication', async (t) => {
const mocks = defaultMocks(t.mock, {});

// The suite restores process.env by assigning a copy back, which does not
// remove variables set by previous tests.
delete process.env.GOOGLE_GHA_CREDS_PATH;

await run();

assert.deepStrictEqual(mocks.isAuthenticated.mock.callCount(), 1);
assert.match(mocks.logWarning.mock.calls?.at(0)?.arguments?.at(0), /not authenticated/);
});

await suite.test('skips the authentication check when skip_auth_check is true', async (t) => {
const mocks = defaultMocks(t.mock, {
skip_auth_check: 'true',
});
await run();

assert.deepStrictEqual(mocks.isAuthenticated.mock.callCount(), 0);
assert.deepStrictEqual(mocks.logWarning.mock.callCount(), 0);
});

await suite.test('authenticates even when skip_auth_check is true', async (t) => {
const mocks = defaultMocks(t.mock, {
skip_auth_check: 'true',
});

process.env.GOOGLE_GHA_CREDS_PATH = '/foo/bar/path.json';

await run();

assert.deepStrictEqual(mocks.authenticateGcloudSDK.mock.callCount(), 1);
});
});

/**
Expand Down
Loading