Skip to content
Merged
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
4 changes: 4 additions & 0 deletions .github/workflows/setup-gcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ jobs:
- name: Lint
working-directory: ./setup-gcloud
run: npm run lint

- name: Test
working-directory: ./setup-gcloud
run: npm test
3 changes: 3 additions & 0 deletions setup-gcloud/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ steps:
project_id: ${{ secrets.GCP_PROJECT_ID }}
service_account_key: ${{ secrets.GCP_SA_KEY }}
export_default_credentials: true
credentials_file_path: '/tmp/gcloud-credentials'
- run: gcloud info
```

Expand All @@ -76,6 +77,8 @@ steps:

* `export_default_credentials`: (Optional) Export the provided credentials as [Google Default Application Credentials][dac]. This will make the credentials available to later steps. Future steps that consume Default Application Credentials will automatically detect and use these credentials.

* `credentials_file_path`: (Optional) Only valid when `export_default_credentials` is `true`. Sets the path at which the credentials should be written. If not provided, `GITHUB_WORKSPACE` is used.

* `project_id`: (Optional) 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.

[dac]: https://cloud.google.com/docs/authentication/production
Expand Down
8 changes: 8 additions & 0 deletions setup-gcloud/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ inputs:
these credentials.
default: false
required: false
credentials_file_path:
description: |-
The path and name of the file to which to write the shared default
credentials. This option is only valid when
export_default_credentials=true. By default, the credentials will be
written to a new file in the root of GITHUB_WORKSPACE.
default: null
required: false

runs:
using: node12
Expand Down
27 changes: 21 additions & 6 deletions setup-gcloud/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports =
/******/ // the startup function
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove the dist

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is built and added in a pre-commit hook (via Husky). Do you want me to delete this file, or just revert my changes? And should I remove the git hook too?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pre-commit hook has been removed. Please revert the changes to the dist/index.js. We will be generating this file as a part of our release process.

/******/ function startup() {
/******/ // Load entry module and return exports
/******/ return __webpack_require__(738);
/******/ return __webpack_require__(325);
/******/ };
/******/
/******/ // run startup
Expand Down Expand Up @@ -1363,6 +1363,18 @@ exports.debug = debug; // for test

module.exports = require("https");

/***/ }),

/***/ 325:
/***/ (function(__unusedmodule, exports, __webpack_require__) {

"use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const setup_gcloud_1 = __webpack_require__(738);
setup_gcloud_1.run();


/***/ }),

/***/ 357:
Expand Down Expand Up @@ -16436,11 +16448,14 @@ function run() {
// all steps.
const exportCreds = core.getInput('export_default_credentials');
if (String(exportCreds).toLowerCase() === 'true') {
const workspace = process.env.GITHUB_WORKSPACE;
if (!workspace) {
throw new Error('Missing GITHUB_WORKSPACE!');
let credsPath = core.getInput('credentials_file_path');
if (!credsPath) {
const credsDir = process.env.GITHUB_WORKSPACE;
if (!credsDir) {
throw new Error('No path for credentials. Set credentials_file_path or process.env.GITHUB_WORKSPACE');
}
credsPath = path_1.default.join(credsDir, uuid_1.v4());
}
const credsPath = path_1.default.join(workspace, uuid_1.v4());
const serviceAccountKeyObj = setupGcloud.parseServiceAccountKey(serviceAccountKey);
yield fs_1.promises.writeFile(credsPath, JSON.stringify(serviceAccountKeyObj, null, 2));
core.exportVariable('GCLOUD_PROJECT', projectId ? projectId : serviceAccountKeyObj.project_id); // If projectId is set export it, else export projectId from SA
Expand All @@ -16453,7 +16468,7 @@ function run() {
}
});
}
run();
exports.run = run;


/***/ }),
Expand Down
129 changes: 129 additions & 0 deletions setup-gcloud/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions setup-gcloud/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
"description": "Setup gcloud GitHub action",
"main": "dist/index.js",
"scripts": {
"build": "ncc build src/setup-gcloud.ts",
"build": "ncc build src/index.ts",
"lint": "eslint . --ext .ts,.tsx",
"test": "mocha -r ts-node/register -t 120s 'tests/*.test.ts'",
"format": "prettier --write **/*.ts"
},
"husky": {
Expand Down Expand Up @@ -43,18 +44,20 @@
"@types/mocha": "^7.0.1",
"@types/node": "^13.7.4",
"@types/semver": "^7.1.0",
"@types/sinon": "^7.5.2",
"@types/tmp": "^0.1.0",
"@types/uuid": "^3.4.7",
"@typescript-eslint/eslint-plugin": "^2.20.0",
"@typescript-eslint/parser": "^2.20.0",
"@zeit/ncc": "^0.21.0",
"chai": "^4.2.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-prettier": "^3.1.2",
"eslint": "^6.8.0",
"husky": "^4.2.3",
"mocha": "^7.0.1",
"prettier": "^1.19.1",
"sinon": "^9.0.2",
"ts-node": "^8.6.2",
"typescript": "^3.8.2"
}
Expand Down
3 changes: 3 additions & 0 deletions setup-gcloud/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { run } from './setup-gcloud';

run();
20 changes: 13 additions & 7 deletions setup-gcloud/src/setup-gcloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { promises as fs } from 'fs';
import path from 'path';
import { v4 as uuidv4 } from 'uuid';

async function run(): Promise<void> {
export async function run(): Promise<void> {
try {
let version = core.getInput('version');
if (!version || version == 'latest') {
Expand Down Expand Up @@ -56,15 +56,23 @@ async function run(): Promise<void> {
// all steps.
const exportCreds = core.getInput('export_default_credentials');
if (String(exportCreds).toLowerCase() === 'true') {
const workspace = process.env.GITHUB_WORKSPACE;
if (!workspace) {
throw new Error('Missing GITHUB_WORKSPACE!');
let credsPath = core.getInput('credentials_file_path');

if (!credsPath) {
const credsDir = process.env.GITHUB_WORKSPACE;
if (!credsDir) {
throw new Error(
'No path for credentials. Set credentials_file_path or process.env.GITHUB_WORKSPACE',
);
}

credsPath = path.join(credsDir, uuidv4());
}

const credsPath = path.join(workspace, uuidv4());
const serviceAccountKeyObj = setupGcloud.parseServiceAccountKey(
serviceAccountKey,
);

await fs.writeFile(
credsPath,
JSON.stringify(serviceAccountKeyObj, null, 2), // Print to file as string w/ indents
Expand All @@ -80,5 +88,3 @@ async function run(): Promise<void> {
core.setFailed(error.message);
}
}

run();
Loading