From 072bbe9fbcc41afa8d1d1c3efd83aebcb1fa8343 Mon Sep 17 00:00:00 2001 From: rootkiller6788 Date: Mon, 21 Sep 2026 20:41:09 +0800 Subject: [PATCH 1/2] add a skip_auth_check input Jobs that only need the gcloud CLI, e.g. to drive the Firestore or Spanner emulator, never authenticate, so they get the "not authenticated" warning on every run. Add an opt-out: with skip_auth_check we don't probe gcloud at all and we don't warn. Credentials from google-github-actions/auth are still loaded, the flag only skips the check. --- action.yml | 12 ++++++++++++ src/main.ts | 3 +++ 2 files changed, 15 insertions(+) diff --git a/action.yml b/action.yml index ca5694c81..632ebaf66 100644 --- a/action.yml +++ b/action.yml @@ -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: |- diff --git a/src/main.ts b/src/main.ts index 0e72e12b4..c80cae1dc 100644 --- a/src/main.ts +++ b/src/main.ts @@ -56,6 +56,7 @@ export async function run(): Promise { 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) { @@ -105,6 +106,8 @@ export async function run(): Promise { 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 { From 04fe509ea0eaa26123574f68e941b368adc0fe2c Mon Sep 17 00:00:00 2001 From: rootkiller6788 Date: Mon, 21 Sep 2026 20:41:20 +0800 Subject: [PATCH 2/2] cover skip_auth_check in the unit tests Also pins the existing behaviour: without a credential file and with nothing authenticated, the warning is emitted. --- tests/setup-gcloud.test.ts | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/setup-gcloud.test.ts b/tests/setup-gcloud.test.ts index f1a3c6431..a11f1cf6a 100644 --- a/tests/setup-gcloud.test.ts +++ b/tests/setup-gcloud.test.ts @@ -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); + }); }); /**