mirror of
https://github.com/google-github-actions/setup-gcloud.git
synced 2026-08-28 20:39:23 +00:00
Allow setting project ID
This commit is contained in:
parent
e51b9908a9
commit
94600200ac
5 changed files with 95 additions and 21 deletions
19
.github/workflows/setup-gcloud-it.yml
vendored
19
.github/workflows/setup-gcloud-it.yml
vendored
|
|
@ -69,3 +69,22 @@ jobs:
|
|||
- name: Verify Exported
|
||||
shell: bash
|
||||
run: test -f $GOOGLE_APPLICATION_CREDENTIALS
|
||||
|
||||
project_id:
|
||||
name: setup-gcloud with configured project
|
||||
runs-on: ${{ matrix.operating-system }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
operating-system: [ubuntu-latest, windows-latest, macos-latest]
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: setup-gcloud
|
||||
uses: ./setup-gcloud/
|
||||
with:
|
||||
project_id: ${{ secrets.SETUP_GCLOUD_IT_PROJECT_ID }}
|
||||
|
||||
- name: Verify project
|
||||
shell: bash
|
||||
run: gcloud config get-value project | grep ${{ secrets.SETUP_GCLOUD_IT_PROJECT_ID }}
|
||||
|
|
|
|||
|
|
@ -40,6 +40,14 @@ inputs:
|
|||
value can be raw or base64-encoded.
|
||||
required: true
|
||||
|
||||
project_id:
|
||||
description: |-
|
||||
ID of the Google Cloud project. If provided, this will configure gcloud to
|
||||
use this project ID by default for commands. Individual commands can still
|
||||
override the project using the --project flag which takes precedence.
|
||||
default: null
|
||||
required: false
|
||||
|
||||
export_default_credentials:
|
||||
description: |-
|
||||
Export the provided credentials as Google Default Application Credentials.
|
||||
|
|
|
|||
|
|
@ -40,6 +40,14 @@ inputs:
|
|||
value can be raw or base64-encoded.
|
||||
required: true
|
||||
|
||||
project_id:
|
||||
description: |-
|
||||
ID of the Google Cloud project. If provided, this will configure gcloud to
|
||||
use this project ID by default for commands. Individual commands can still
|
||||
override the project using the --project flag which takes precedence.
|
||||
default: null
|
||||
required: false
|
||||
|
||||
export_default_credentials:
|
||||
description: |-
|
||||
Export the provided credentials as Google Default Application Credentials.
|
||||
|
|
|
|||
38
setup-gcloud/dist/index.js
vendored
38
setup-gcloud/dist/index.js
vendored
|
|
@ -9972,12 +9972,31 @@ function run() {
|
|||
let toolPath = toolCache.find('gcloud', version);
|
||||
if (!toolPath) {
|
||||
toolPath = yield installGcloudSDK(version);
|
||||
core.info('Successfully installed gcloud Cloud SDK');
|
||||
}
|
||||
// A workaround for https://github.com/actions/toolkit/issues/229
|
||||
// Currently exec on windows runs as cmd shell.
|
||||
let toolCommand = 'gcloud';
|
||||
if (process.platform == 'win32') {
|
||||
toolCommand = 'gcloud.cmd';
|
||||
}
|
||||
// Set the project ID, if given.
|
||||
const projectId = core.getInput('project_id');
|
||||
if (projectId) {
|
||||
yield exec.exec(toolCommand, [
|
||||
'--quiet',
|
||||
'config',
|
||||
'set',
|
||||
'core/project',
|
||||
projectId,
|
||||
]);
|
||||
core.info('Successfully set default project');
|
||||
}
|
||||
const serviceAccountEmail = core.getInput('service_account_email') || '';
|
||||
const serviceAccountKey = core.getInput('service_account_key');
|
||||
// if a service account key isn't provided, log an un-authenticated notice
|
||||
if (!serviceAccountKey) {
|
||||
core.info('gcloud SDK installed without authentication.');
|
||||
core.info('No credentials provided, skipping authentication');
|
||||
return;
|
||||
}
|
||||
// Handle base64-encoded credentials
|
||||
|
|
@ -9998,14 +10017,15 @@ function run() {
|
|||
});
|
||||
});
|
||||
yield fs_1.promises.writeFile(tmpKeyFilePath, serviceAccountJSON);
|
||||
// A workaround for https://github.com/actions/toolkit/issues/229
|
||||
// Currently exec on windows runs as cmd shell.
|
||||
let toolCommand = 'gcloud';
|
||||
if (process.platform == 'win32') {
|
||||
toolCommand = 'gcloud.cmd';
|
||||
}
|
||||
// authenticate as the specified service account
|
||||
yield exec.exec(`${toolCommand} auth activate-service-account ${serviceAccountEmail} --key-file=${tmpKeyFilePath}`);
|
||||
// Authenticate as the specified service account.
|
||||
yield exec.exec(toolCommand, [
|
||||
'--quiet',
|
||||
'auth',
|
||||
'activate-service-account',
|
||||
serviceAccountEmail,
|
||||
'--key-file',
|
||||
tmpKeyFilePath,
|
||||
]);
|
||||
// Export credentials if requested - these credentials must be exported in
|
||||
// the shared workspace directory, since the filesystem must be shared among
|
||||
// all steps.
|
||||
|
|
|
|||
|
|
@ -56,6 +56,27 @@ async function run(): Promise<void> {
|
|||
let toolPath = toolCache.find('gcloud', version);
|
||||
if (!toolPath) {
|
||||
toolPath = await installGcloudSDK(version);
|
||||
core.info('Successfully installed gcloud Cloud SDK');
|
||||
}
|
||||
|
||||
// A workaround for https://github.com/actions/toolkit/issues/229
|
||||
// Currently exec on windows runs as cmd shell.
|
||||
let toolCommand = 'gcloud';
|
||||
if (process.platform == 'win32') {
|
||||
toolCommand = 'gcloud.cmd';
|
||||
}
|
||||
|
||||
// Set the project ID, if given.
|
||||
const projectId = core.getInput('project_id');
|
||||
if (projectId) {
|
||||
await exec.exec(toolCommand, [
|
||||
'--quiet',
|
||||
'config',
|
||||
'set',
|
||||
'core/project',
|
||||
projectId,
|
||||
]);
|
||||
core.info('Successfully set default project');
|
||||
}
|
||||
|
||||
const serviceAccountEmail = core.getInput('service_account_email') || '';
|
||||
|
|
@ -63,7 +84,7 @@ async function run(): Promise<void> {
|
|||
|
||||
// if a service account key isn't provided, log an un-authenticated notice
|
||||
if (!serviceAccountKey) {
|
||||
core.info('gcloud SDK installed without authentication.');
|
||||
core.info('No credentials provided, skipping authentication');
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -87,17 +108,15 @@ async function run(): Promise<void> {
|
|||
});
|
||||
await fs.writeFile(tmpKeyFilePath, serviceAccountJSON);
|
||||
|
||||
// A workaround for https://github.com/actions/toolkit/issues/229
|
||||
// Currently exec on windows runs as cmd shell.
|
||||
let toolCommand = 'gcloud';
|
||||
if (process.platform == 'win32') {
|
||||
toolCommand = 'gcloud.cmd';
|
||||
}
|
||||
|
||||
// authenticate as the specified service account
|
||||
await exec.exec(
|
||||
`${toolCommand} auth activate-service-account ${serviceAccountEmail} --key-file=${tmpKeyFilePath}`,
|
||||
);
|
||||
// Authenticate as the specified service account.
|
||||
await exec.exec(toolCommand, [
|
||||
'--quiet',
|
||||
'auth',
|
||||
'activate-service-account',
|
||||
serviceAccountEmail,
|
||||
'--key-file',
|
||||
tmpKeyFilePath,
|
||||
]);
|
||||
|
||||
// Export credentials if requested - these credentials must be exported in
|
||||
// the shared workspace directory, since the filesystem must be shared among
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue