mirror of
https://github.com/google-github-actions/setup-gcloud.git
synced 2026-08-21 03:49:27 +00:00
Force authentication if GOOGLE_GHA_CREDS_PATH is set (#587)
* Force authentication if GOOGLE_GHA_CREDS_PATH is set * Upgrade to latest setup-cloud-sdk package
This commit is contained in:
parent
5c6749ce82
commit
1e0945d60c
6 changed files with 54 additions and 29 deletions
8
.github/workflows/setup-gcloud-it.yml
vendored
8
.github/workflows/setup-gcloud-it.yml
vendored
|
|
@ -372,8 +372,8 @@ jobs:
|
|||
|
||||
- uses: google-github-actions/auth@main
|
||||
with:
|
||||
workload_identity_provider: ${{ secrets.WIF_PROVIDER_NAME }}
|
||||
service_account: ${{ secrets.OIDC_AUTH_SA_EMAIL }}
|
||||
workload_identity_provider: '${{ secrets.WIF_PROVIDER_NAME }}'
|
||||
service_account: '${{ secrets.OIDC_AUTH_SA_EMAIL }}'
|
||||
|
||||
- name: 'setup-gcloud'
|
||||
uses: './'
|
||||
|
|
@ -385,6 +385,10 @@ jobs:
|
|||
CURRENT_SA=$(gcloud auth list --format="value(account)" --filter="(status=ACTIVE)")
|
||||
if [ ${{ secrets.OIDC_AUTH_SA_EMAIL }} != $CURRENT_SA ]; then exit 1; fi
|
||||
|
||||
- uses: google-github-actions/auth@main
|
||||
with:
|
||||
credentials_json: '${{ secrets.SETUP_GCLOUD_IT_KEY }}'
|
||||
|
||||
- name: setup-gcloud
|
||||
uses: ./
|
||||
with:
|
||||
|
|
|
|||
2
dist/main/index.js
vendored
2
dist/main/index.js
vendored
File diff suppressed because one or more lines are too long
50
package-lock.json
generated
50
package-lock.json
generated
|
|
@ -12,7 +12,7 @@
|
|||
"@actions/core": "^1.10.0",
|
||||
"@actions/tool-cache": "^2.0.1",
|
||||
"@google-github-actions/actions-utils": "^0.4.3",
|
||||
"@google-github-actions/setup-cloud-sdk": "^0.5.2"
|
||||
"@google-github-actions/setup-cloud-sdk": "^1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/chai": "^4.3.4",
|
||||
|
|
@ -129,9 +129,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@google-github-actions/setup-cloud-sdk": {
|
||||
"version": "0.5.2",
|
||||
"resolved": "https://registry.npmjs.org/@google-github-actions/setup-cloud-sdk/-/setup-cloud-sdk-0.5.2.tgz",
|
||||
"integrity": "sha512-6QjuF5IaKm1wP+ps4OuOOoxLiH2+ZCktRZRqmQww2kEjyi2vJQE5bbxD785YnHVHh6p+7zVxyltj0y5A1vMYIA==",
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@google-github-actions/setup-cloud-sdk/-/setup-cloud-sdk-1.0.0.tgz",
|
||||
"integrity": "sha512-5cfdQbEQ9hisMxeF+RBlScFP1dmQn8SCaezG0YyztIRMF4IXkE/b/3osy0boR8lYRV1/TvFVdjsUui8uai5Dmg==",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.0",
|
||||
"@actions/exec": "^1.1.1",
|
||||
|
|
@ -588,9 +588,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/acorn": {
|
||||
"version": "8.8.0",
|
||||
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.0.tgz",
|
||||
"integrity": "sha512-QOxyigPVrpZ2GXT+PFyZTl6TtOFc5egxHIP9IlQ+RbupQuX4RkT/Bee4/kQuC02Xkzg84JcT7oLYtDIQxp+v7w==",
|
||||
"version": "8.8.1",
|
||||
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.1.tgz",
|
||||
"integrity": "sha512-7zFpHzhnqYKrkYdUjF1HI1bzd0VygEGX8lFk4k5zVMqHEoES+P+7TKI+EvLO9WVMJ8eekdO0aDEK044xTXwPPA==",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
"acorn": "bin/acorn"
|
||||
|
|
@ -1178,9 +1178,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/espree": {
|
||||
"version": "9.4.0",
|
||||
"resolved": "https://registry.npmjs.org/espree/-/espree-9.4.0.tgz",
|
||||
"integrity": "sha512-DQmnRpLj7f6TgN/NYb0MTzJXL+vJF9h3pHy4JhCIs3zwcgez8xmGg3sXHcEO97BrmO2OSvCwMdfdlyl+E9KjOw==",
|
||||
"version": "9.4.1",
|
||||
"resolved": "https://registry.npmjs.org/espree/-/espree-9.4.1.tgz",
|
||||
"integrity": "sha512-XwctdmTO6SIvCzd9810yyNzIrOrqNYV9Koizx4C/mRhf9uq0o4yHoCEU/670pOxOL/MSraektvSAji79kX90Vg==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"acorn": "^8.8.0",
|
||||
|
|
@ -1748,9 +1748,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/loupe": {
|
||||
"version": "2.3.4",
|
||||
"resolved": "https://registry.npmjs.org/loupe/-/loupe-2.3.4.tgz",
|
||||
"integrity": "sha512-OvKfgCC2Ndby6aSTREl5aCCPTNIzlDfQZvZxNUrBrihDhL3xcrYegTblhmEiCrg2kKQz4XsFIaemE5BF4ybSaQ==",
|
||||
"version": "2.3.6",
|
||||
"resolved": "https://registry.npmjs.org/loupe/-/loupe-2.3.6.tgz",
|
||||
"integrity": "sha512-RaPMZKiMy8/JruncMU5Bt6na1eftNoo++R4Y+N2FrxkDVTrGvcyzFTsaGif4QTeKESheMGegbhw6iUAq+5A8zA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"get-func-name": "^2.0.0"
|
||||
|
|
@ -2787,9 +2787,9 @@
|
|||
}
|
||||
},
|
||||
"@google-github-actions/setup-cloud-sdk": {
|
||||
"version": "0.5.2",
|
||||
"resolved": "https://registry.npmjs.org/@google-github-actions/setup-cloud-sdk/-/setup-cloud-sdk-0.5.2.tgz",
|
||||
"integrity": "sha512-6QjuF5IaKm1wP+ps4OuOOoxLiH2+ZCktRZRqmQww2kEjyi2vJQE5bbxD785YnHVHh6p+7zVxyltj0y5A1vMYIA==",
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@google-github-actions/setup-cloud-sdk/-/setup-cloud-sdk-1.0.0.tgz",
|
||||
"integrity": "sha512-5cfdQbEQ9hisMxeF+RBlScFP1dmQn8SCaezG0YyztIRMF4IXkE/b/3osy0boR8lYRV1/TvFVdjsUui8uai5Dmg==",
|
||||
"requires": {
|
||||
"@actions/core": "^1.10.0",
|
||||
"@actions/exec": "^1.1.1",
|
||||
|
|
@ -3122,9 +3122,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"acorn": {
|
||||
"version": "8.8.0",
|
||||
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.0.tgz",
|
||||
"integrity": "sha512-QOxyigPVrpZ2GXT+PFyZTl6TtOFc5egxHIP9IlQ+RbupQuX4RkT/Bee4/kQuC02Xkzg84JcT7oLYtDIQxp+v7w==",
|
||||
"version": "8.8.1",
|
||||
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.1.tgz",
|
||||
"integrity": "sha512-7zFpHzhnqYKrkYdUjF1HI1bzd0VygEGX8lFk4k5zVMqHEoES+P+7TKI+EvLO9WVMJ8eekdO0aDEK044xTXwPPA==",
|
||||
"dev": true
|
||||
},
|
||||
"acorn-jsx": {
|
||||
|
|
@ -3550,9 +3550,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"espree": {
|
||||
"version": "9.4.0",
|
||||
"resolved": "https://registry.npmjs.org/espree/-/espree-9.4.0.tgz",
|
||||
"integrity": "sha512-DQmnRpLj7f6TgN/NYb0MTzJXL+vJF9h3pHy4JhCIs3zwcgez8xmGg3sXHcEO97BrmO2OSvCwMdfdlyl+E9KjOw==",
|
||||
"version": "9.4.1",
|
||||
"resolved": "https://registry.npmjs.org/espree/-/espree-9.4.1.tgz",
|
||||
"integrity": "sha512-XwctdmTO6SIvCzd9810yyNzIrOrqNYV9Koizx4C/mRhf9uq0o4yHoCEU/670pOxOL/MSraektvSAji79kX90Vg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"acorn": "^8.8.0",
|
||||
|
|
@ -3981,9 +3981,9 @@
|
|||
}
|
||||
},
|
||||
"loupe": {
|
||||
"version": "2.3.4",
|
||||
"resolved": "https://registry.npmjs.org/loupe/-/loupe-2.3.4.tgz",
|
||||
"integrity": "sha512-OvKfgCC2Ndby6aSTREl5aCCPTNIzlDfQZvZxNUrBrihDhL3xcrYegTblhmEiCrg2kKQz4XsFIaemE5BF4ybSaQ==",
|
||||
"version": "2.3.6",
|
||||
"resolved": "https://registry.npmjs.org/loupe/-/loupe-2.3.6.tgz",
|
||||
"integrity": "sha512-RaPMZKiMy8/JruncMU5Bt6na1eftNoo++R4Y+N2FrxkDVTrGvcyzFTsaGif4QTeKESheMGegbhw6iUAq+5A8zA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"get-func-name": "^2.0.0"
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
"@actions/core": "^1.10.0",
|
||||
"@actions/tool-cache": "^2.0.1",
|
||||
"@google-github-actions/actions-utils": "^0.4.3",
|
||||
"@google-github-actions/setup-cloud-sdk": "^0.5.2"
|
||||
"@google-github-actions/setup-cloud-sdk": "^1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/chai": "^4.3.4",
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
import * as core from '@actions/core';
|
||||
import * as toolCache from '@actions/tool-cache';
|
||||
import {
|
||||
authenticateGcloudSDK,
|
||||
getLatestGcloudSDKVersion,
|
||||
installComponent,
|
||||
installGcloudSDK,
|
||||
|
|
@ -60,6 +61,17 @@ export async function run(): Promise<void> {
|
|||
await installComponent(components.split(',').map((comp) => comp.trim()));
|
||||
}
|
||||
|
||||
// Authenticate - this comes from google-github-actions/auth
|
||||
const credFile = process.env.GOOGLE_GHA_CREDS_PATH;
|
||||
if (credFile) {
|
||||
await authenticateGcloudSDK(credFile);
|
||||
core.info('Successfully authenticated');
|
||||
} else {
|
||||
core.warning(
|
||||
'No authentication found for gcloud, authenticate with `google-github-actions/auth`.',
|
||||
);
|
||||
}
|
||||
|
||||
// Set the project ID, if given.
|
||||
const projectId = core.getInput('project_id');
|
||||
if (projectId) {
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ describe('#run', function () {
|
|||
exportVariable: sinon.stub(core, 'exportVariable'),
|
||||
setFailed: sinon.stub(core, 'setFailed'),
|
||||
warning: sinon.stub(core, 'warning'),
|
||||
authenticateGcloudSDK: sinon.stub(setupGcloud, 'authenticateGcloudSDK'),
|
||||
installGcloudSDK: sinon.stub(setupGcloud, 'installGcloudSDK'),
|
||||
isInstalled: sinon.stub(setupGcloud, 'isInstalled').returns(false),
|
||||
setProject: sinon.stub(setupGcloud, 'setProject'),
|
||||
|
|
@ -114,6 +115,14 @@ describe('#run', function () {
|
|||
expect(this.stubs.installComponent.callCount).to.eq(1);
|
||||
});
|
||||
|
||||
it('authenticates if GOOGLE_GHA_CREDS is set', async function () {
|
||||
this.stubs.env
|
||||
.value({ GOOGLE_GHA_CREDS_PATH: 'foo/bar/path.json' })
|
||||
.returns('{}');
|
||||
await run();
|
||||
expect(this.stubs.authenticateGcloudSDK.callCount).to.eq(1);
|
||||
});
|
||||
|
||||
it('sets the project ID if provided', async function () {
|
||||
this.stubs.getInput.withArgs('project_id').returns('test');
|
||||
await run();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue