diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..82ee8b6 --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ + +MIT License + +Copyright (c) 2019 Mathrix Education SA + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 9276708..6c2fa9a 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,22 @@ # @mathrix-education/setup-gcloud -Small GitHub action to install the Google Cloud SDK on the virtual -environment. +Install the Google Cloud SDK in your GitHub Actions workflow. -Proudly maintained by [Mathieu Bour][1.1], Vice-CTO -[@mathrix-education][1.2]. +**This action is not supported by Google Cloud.** + +Proudly maintained by [Mathieu Bour][1.1], Vice-CTO [@mathrix-education][1.2]. [1.1]: https://github.com/mathieu-bour [1.2]: https://github.com/mathrix-education ## Motivations -Since the advent of GitHub Actions, Mathrix Education SA has chosen to -migrate from Google Cloud Build to this new compilation system. +Since the advent of GitHub Actions, Mathrix Education SA has chosen to migrate from Google Cloud Build to this new +compilation system. -If the official [@actions/gcloud][2.1] action works perfectly, the fact -that it is in two parts ([auth][2.2] and [cli][2.3]) and that it is -based on Docker makes it slow and not very suitable for launching -multiple commands. +If the official [@actions/gcloud][2.1] action works perfectly, the fact that it is in two parts ([auth][2.2] and +[cli][2.3]) and that it is based on Docker makes it slow and not very suitable for launching multiple commands. -So we chose to create a JavaScript action to fix this problem, also -adding additional features, such as Docker authentication with Google -Cloud Container Registry. +So we chose to create a JavaScript action to fix this problem, also adding additional features, such as Docker +authentication with Google Cloud Container Registry. [2.1]: https://github.com/actions/gcloud [2.2]: https://github.com/actions/gcloud/tree/master/auth @@ -43,17 +40,70 @@ The supported operating systems matrix is the following: [3.1]: https://img.shields.io/badge/status-supported-brightgreen [3.2]: https://img.shields.io/badge/status-unsupported-red +### Inputs +| Name | Type | Default value | +|-----------------------|--------------------------------|---------------| +| `version` | `'latest'` / `string` | `'latest'` | +| `service-account-key` | `string` (base64) | `''` | +| `project` | `'auto'` / `'none'` / `string` | `'auto'` | +| `components` | `string` | `''` | +| `configure-docker` | `true` / `false` | `false` | + +#### `version` +If you need a precise version of the Google Cloud SDK, you may provide this input. We strongly advise you to do so +since using the latest version may break your workflow if Google release a breaking version. + +#### `service-account-key` +To authenticate the SDK, you may provide a **base64-encoded** service account JSON key. In order to secure you workflow, +use GitHub Actions [secrets][3.3]. + +[3.3]: https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets + +#### `project` +By default, if you provide a `service-account-key`, the action will use it to determine which is the default project. + +- If you want to specify a different project (for example, in case of cross-project interaction), you may explicitly +specify your project ID here. +- If you want to disable the project configuration and provide your project ID later in your workflow, set this input +to `none`. + +#### `components` +If you want to install additional SDK components, you may provide them in this input. + +#### `configure-docker` +If you want to push an image to the Google Container Registry, you may authenticate the Docker agent by setting the +input to true. + -## In workflows +## Examples See [action.yml](action.yml) for details. -Simply add this step in your workflow `steps`. +### Minimum configuration ```yaml - uses: mathrix-education/setup-gcloud@master +``` +By default, the minimal example will install the latest Google Cloud SDK. Because no service account key was provided +you will have to authenticate the SDK yourself (for example, with [`gcloud auth activate-service-account`][4.1]). + +[4.1]: https://cloud.google.com/sdk/gcloud/reference/auth/activate-service-account + + +### Typical CI configuration +```yaml +- name: Setup Google Cloud SDK + uses: mathrix-education/setup-gcloud@0.1.3 with: - version: 245.0.0.0 # default: latest - project: my-project # the default Google Cloud project - service-account-key: # base64 encoded JSON service account key - components: beta # additional components to install - configure-docker: true # configure docker during install + service-account-key: ${{ secrets.GCLOUD_AUTH }} # base64-encoded service account JSON key + confgure-docker: true ``` +In this example, you provide a service account key. The action automatically download the latest version of the SDK and +authenticate using your key. + +Then using the field `"project_id"` of your key, we will set the default project using +`gcloud config set project {project}`, so you do not have to do it later. + +Finally, because you may want to build a Docker image and upload it to the [Google Container Registry][4.2], the action +will configure Docker to allow the upload of your image. Make sure that the service account has the correct rights to +write on the bucket linked to the registry. + +[4.2]: https://cloud.google.com/container-registry/ diff --git a/action.yml b/action.yml index cd0fe09..1a2d811 100644 --- a/action.yml +++ b/action.yml @@ -8,16 +8,17 @@ runs: using: 'node12' main: 'dist/index.js' inputs: + version: + description: Google Cloud SDK to use. If left null, will use the latest one. + required: false + default: latest service-account-key: description: The service account key to use, base64-encoded. required: false project: description: The default Google Cloud project. You can change it later. required: false - version: - description: Google Cloud SDK to use. If left null, will use the latest one. - required: false - default: latest + default: auto components: description: Install additional components (e.g. beta, gsutils, etc.) required: false diff --git a/dist/index.js b/dist/index.js index d4f5aaf..cd95547 100644 --- a/dist/index.js +++ b/dist/index.js @@ -34,8 +34,10 @@ module.exports = /******/ // the startup function /******/ function startup() { /******/ // Load entry module and return exports -/******/ return __webpack_require__(655); +/******/ return __webpack_require__(840); /******/ }; +/******/ // initialize runtime +/******/ runtime(__webpack_require__); /******/ /******/ // run startup /******/ return startup(); @@ -928,13 +930,6 @@ module.exports = require("tls"); /***/ }), -/***/ 34: -/***/ (function(module) { - -module.exports = require("https"); - -/***/ }), - /***/ 87: /***/ (function(module) { @@ -973,7 +968,7 @@ module.exports = function nodeRNG() { var net = __webpack_require__(631); var tls = __webpack_require__(16); var http = __webpack_require__(605); -var https = __webpack_require__(34); +var https = __webpack_require__(211); var events = __webpack_require__(614); var assert = __webpack_require__(357); var util = __webpack_require__(669); @@ -1217,103 +1212,12 @@ if (process.env.NODE_DEBUG && /\btunnel\b/.test(process.env.NODE_DEBUG)) { exports.debug = debug; // for test -/***/ }), - -/***/ 163: -/***/ (function(__unusedmodule, exports, __webpack_require__) { - -"use strict"; - -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; - result["default"] = mod; - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const core = __importStar(__webpack_require__(470)); -const exec = __importStar(__webpack_require__(986)); -const path_1 = __webpack_require__(622); -const constants_1 = __webpack_require__(211); -function isWindows() { - return process.platform === 'win32'; -} -exports.isWindows = isWindows; -function isMacOS() { - return process.platform === 'darwin'; -} -exports.isMacOS = isMacOS; -function isUbuntu() { - return process.platform === 'linux'; -} -exports.isUbuntu = isUbuntu; -function getCloudSDKFolder() { - if (isWindows()) { - return constants_1.WINDOWS_INSTALL_PATH; - } - else if (isUbuntu()) { - return constants_1.UBUNTU_INSTALL_PATH; - } - else { - const home = process.env.HOME ? process.env.HOME : process.cwd(); - return path_1.resolve(home, constants_1.INSTALL_DIRECTORY); - } -} -exports.getCloudSDKFolder = getCloudSDKFolder; -function getDownloadLink() { - const baseUrl = 'https://dl.google.com/dl/cloudsdk/channels/rapid'; - const version = core.getInput('version'); - if (version === 'latest') { - if (isWindows()) { - return `${baseUrl}/google-cloud-sdk.zip`; - } - else { - return `${baseUrl}/google-cloud-sdk.tar.gz`; - } - } - if (isWindows()) { - return `${baseUrl}/downloads/google-cloud-sdk-${version}-windows-x86_64.zip`; - } - else if (isMacOS()) { - return `${baseUrl}/downloads/google-cloud-sdk-${version}-darwin-x86_64.tar.gz`; - } - else { - return `${baseUrl}/downloads/google-cloud-sdk-${version}-linux-x86_64.tar.gz`; - } -} -exports.getDownloadLink = getDownloadLink; -function gcloud(args, options = undefined) { - return __awaiter(this, void 0, void 0, function* () { - const gcloudPath = path_1.resolve(getCloudSDKFolder(), 'bin', 'gcloud' + (isWindows() ? '.cmd' : '')); - args.unshift('--quiet'); - yield exec.exec(gcloudPath, args, options); - }); -} -exports.gcloud = gcloud; - - /***/ }), /***/ 211: -/***/ (function(__unusedmodule, exports) { - -"use strict"; - -Object.defineProperty(exports, "__esModule", { value: true }); -exports.INSTALL_DIRECTORY = 'google-cloud-sdk'; -exports.WINDOWS_INSTALL_PATH = `C:\\${exports.INSTALL_DIRECTORY}`; -exports.UBUNTU_INSTALL_PATH = `/home/runner/${exports.INSTALL_DIRECTORY}`; +/***/ (function(module) { +module.exports = require("https"); /***/ }), @@ -3215,69 +3119,6 @@ function getState(name) { exports.getState = getState; //# sourceMappingURL=core.js.map -/***/ }), - -/***/ 526: -/***/ (function(__unusedmodule, exports, __webpack_require__) { - -"use strict"; - -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; - result["default"] = mod; - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const core = __importStar(__webpack_require__(470)); -const exec = __importStar(__webpack_require__(986)); -const child_process_1 = __webpack_require__(129); -const path_1 = __webpack_require__(622); -const utils_1 = __webpack_require__(163); -/** - * Setup the Google Cloud SDK. - */ -function setup() { - return __awaiter(this, void 0, void 0, function* () { - const installScriptExtension = utils_1.isWindows() ? 'bat' : 'sh'; - const installScript = path_1.resolve(utils_1.getCloudSDKFolder(), `install.${installScriptExtension}`); - const args = [ - '--usage-reporting=false', - '--command-completion=false', - '--path-update=true', - '--usage-reporting=false', - '--quiet', - ]; - if (core.getInput('components')) { - args.push('--additional-components=' + core.getInput('components')); - } - if (utils_1.isWindows()) { - // @actions/exec does not exit on windows - child_process_1.execSync(`"${installScript}" ${args.join(' ')}`, { stdio: 'inherit' }); - } - else { - yield exec.exec(installScript, args); - } - if (core.getInput('project')) { - yield utils_1.gcloud(['config', 'set', 'project', core.getInput('project')]); - } - const binPath = path_1.resolve(utils_1.getCloudSDKFolder(), 'bin'); - core.addPath(binPath); - }); -} -exports.setup = setup; - - /***/ }), /***/ 533: @@ -3744,65 +3585,6 @@ module.exports = require("events"); module.exports = require("path"); -/***/ }), - -/***/ 629: -/***/ (function(__unusedmodule, exports, __webpack_require__) { - -"use strict"; - -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; - result["default"] = mod; - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const core = __importStar(__webpack_require__(470)); -const fs_1 = __webpack_require__(747); -const path_1 = __webpack_require__(622); -const utils_1 = __webpack_require__(163); -/** - * Authenticate the Google Cloud SDK. - */ -function authenticate() { - return __awaiter(this, void 0, void 0, function* () { - // If service account key is not provided, skip the authentication - if (!core.getInput('service-account-key')) { - return; - } - // Write the service account key - const serviceAccountKeyBase64 = core.getInput('service-account-key'); - const serviceAccountKeyJson = Buffer.from(serviceAccountKeyBase64, 'base64'); - const serviceAccountKeyPath = path_1.resolve(process.cwd(), 'gcloud.json'); - fs_1.writeFileSync(serviceAccountKeyPath, serviceAccountKeyJson); - // Activate the service account - yield utils_1.gcloud([ - 'auth', - 'activate-service-account', - `--key-file=${serviceAccountKeyPath}`, - ]); - // Configure Docker if necessary - if (core.getInput('configure-docker')) { - yield utils_1.gcloud(['--quiet', 'auth', 'configure-docker']); - } - // Remove the service account key - fs_1.unlinkSync(serviceAccountKeyPath); - }); -} -exports.authenticate = authenticate; - - /***/ }), /***/ 631: @@ -3810,64 +3592,6 @@ exports.authenticate = authenticate; module.exports = require("net"); -/***/ }), - -/***/ 655: -/***/ (function(__unusedmodule, exports, __webpack_require__) { - -"use strict"; - -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; - result["default"] = mod; - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const core = __importStar(__webpack_require__(470)); -const authenticate_1 = __webpack_require__(629); -const download_1 = __webpack_require__(725); -const setup_1 = __webpack_require__(526); -const utils_1 = __webpack_require__(163); -/** - * Install the Google Cloud SDK. - */ -function install() { - return __awaiter(this, void 0, void 0, function* () { - try { - // Currently, Windows is disabled because the installer does not work properly - if (utils_1.isWindows()) { - core.error('This action does not support Windows for now. PR are welcome!'); - } - yield download_1.download(); - yield setup_1.setup(); - yield authenticate_1.authenticate(); - } - catch (e) { - core.setFailed(e.message); - } - }); -} -exports.install = install; -install() - .then(() => { - core.info('Installation succeeded'); -}) - .catch(() => { - core.error('Installation failed'); -}); - - /***/ }), /***/ 669: @@ -4108,54 +3832,6 @@ function bytesToUuid(buf, offset) { module.exports = bytesToUuid; -/***/ }), - -/***/ 725: -/***/ (function(__unusedmodule, exports, __webpack_require__) { - -"use strict"; - -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; - result["default"] = mod; - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const tc = __importStar(__webpack_require__(533)); -const utils_1 = __webpack_require__(163); -const fs_1 = __webpack_require__(747); -const path_1 = __webpack_require__(622); -/** - * Download the Google Cloud SDK archive. - */ -function download() { - return __awaiter(this, void 0, void 0, function* () { - const downloadLink = utils_1.getDownloadLink(); - const downloadPath = yield tc.downloadTool(downloadLink); - const extractionPath = path_1.resolve(utils_1.getCloudSDKFolder(), '..'); - fs_1.mkdirSync(utils_1.getCloudSDKFolder()); - if (downloadLink.endsWith('.zip')) { - yield tc.extractZip(downloadPath, extractionPath); - } - else if (downloadLink.endsWith('.tar.gz')) { - yield tc.extractTar(downloadPath, extractionPath); - } - }); -} -exports.download = download; - - /***/ }), /***/ 747: @@ -4206,6 +3882,227 @@ module.exports = v4; module.exports = require("url"); +/***/ }), + +/***/ 840: +/***/ (function(__unusedmodule, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); + +// EXTERNAL MODULE: ./node_modules/@actions/core/lib/core.js +var core = __webpack_require__(470); + +// EXTERNAL MODULE: external "fs" +var external_fs_ = __webpack_require__(747); + +// EXTERNAL MODULE: external "path" +var external_path_ = __webpack_require__(622); + +// EXTERNAL MODULE: ./node_modules/@actions/exec/lib/exec.js +var exec = __webpack_require__(986); + +// CONCATENATED MODULE: ./src/constants.ts +const INSTALL_DIRECTORY = 'google-cloud-sdk'; +const WINDOWS_INSTALL_PATH = `C:\\${INSTALL_DIRECTORY}`; +const UBUNTU_INSTALL_PATH = `/home/runner/${INSTALL_DIRECTORY}`; + +// CONCATENATED MODULE: ./src/utils.ts + + + + +function isWindows() { + return process.platform === 'win32'; +} +function isMacOS() { + return process.platform === 'darwin'; +} +function isUbuntu() { + return process.platform === 'linux'; +} +function getCloudSDKFolder() { + if (isWindows()) { + return WINDOWS_INSTALL_PATH; + } + else if (isUbuntu()) { + return UBUNTU_INSTALL_PATH; + } + else { + const home = process.env.HOME ? process.env.HOME : process.cwd(); + return Object(external_path_.resolve)(home, INSTALL_DIRECTORY); + } +} +function getDownloadLink() { + const baseUrl = 'https://dl.google.com/dl/cloudsdk/channels/rapid'; + const version = Object(core.getInput)('version'); + if (version === 'latest') { + if (isWindows()) { + return `${baseUrl}/google-cloud-sdk.zip`; + } + else { + return `${baseUrl}/google-cloud-sdk.tar.gz`; + } + } + if (isWindows()) { + return `${baseUrl}/downloads/google-cloud-sdk-${version}-windows-x86_64.zip`; + } + else if (isMacOS()) { + return `${baseUrl}/downloads/google-cloud-sdk-${version}-darwin-x86_64.tar.gz`; + } + else { + return `${baseUrl}/downloads/google-cloud-sdk-${version}-linux-x86_64.tar.gz`; + } +} +async function gcloud(args, options = undefined) { + const gcloudPath = Object(external_path_.resolve)(getCloudSDKFolder(), 'bin', 'gcloud' + (isWindows() ? '.cmd' : '')); + args.unshift('--quiet'); + await Object(exec.exec)(gcloudPath, args, options); +} + +// CONCATENATED MODULE: ./src/authenticate.ts + + + + +/** + * Authenticate the Google Cloud SDK. + */ +async function authenticate() { + // If service account key is not provided, skip the authentication + if (!Object(core.getInput)('service-account-key')) { + Object(core.warning)('No service-account-key input was passed.' + + 'If it is intentional, you can safely ignore this warning.'); + return; + } + // Write the service account key + const serviceAccountKeyBase64 = Object(core.getInput)('service-account-key'); + const serviceAccountKeyJson = Buffer.from(serviceAccountKeyBase64, 'base64'); + const serviceAccountKeyPath = Object(external_path_.resolve)(process.cwd(), 'gcloud.json'); + Object(external_fs_.writeFileSync)(serviceAccountKeyPath, serviceAccountKeyJson); + // Activate the service account + await gcloud([ + 'auth', + 'activate-service-account', + `--key-file=${serviceAccountKeyPath}`, + ]); + // Configure Docker if necessary + if (Object(core.getInput)('configure-docker')) { + await gcloud(['--quiet', 'auth', 'configure-docker']); + } + // Remove the service account key + Object(external_fs_.unlinkSync)(serviceAccountKeyPath); +} + +// EXTERNAL MODULE: ./node_modules/@actions/tool-cache/lib/tool-cache.js +var tool_cache = __webpack_require__(533); + +// EXTERNAL MODULE: ./node_modules/@actions/io/lib/io.js +var io = __webpack_require__(1); + +// CONCATENATED MODULE: ./src/download.ts + + + + +/** + * Download the Google Cloud SDK archive. + */ +async function download() { + const downloadLink = getDownloadLink(); + const downloadPath = await Object(tool_cache.downloadTool)(downloadLink); + const extractionPath = Object(external_path_.resolve)(getCloudSDKFolder(), '..'); + await Object(io.mkdirP)(getCloudSDKFolder()); + if (downloadLink.endsWith('.zip')) { + await Object(tool_cache.extractZip)(downloadPath, extractionPath); + } + else if (downloadLink.endsWith('.tar.gz')) { + await Object(tool_cache.extractTar)(downloadPath, extractionPath); + } +} + +// EXTERNAL MODULE: external "child_process" +var external_child_process_ = __webpack_require__(129); + +// CONCATENATED MODULE: ./src/setup.ts + + + + + +/** + * Setup the Google Cloud SDK. + */ +async function setup() { + const installScriptExtension = isWindows() ? 'bat' : 'sh'; + const installScript = Object(external_path_.resolve)(getCloudSDKFolder(), `install.${installScriptExtension}`); + const args = [ + '--usage-reporting=false', + '--command-completion=false', + '--path-update=false', + '--usage-reporting=false', + '--quiet', + ]; + if (Object(core.getInput)('components')) { + args.push('--additional-components=' + Object(core.getInput)('components')); + } + if (isWindows()) { + // @actions/exec does not exit on windows + Object(external_child_process_.execSync)(`"${installScript}" ${args.join(' ')}`, { stdio: 'inherit' }); + } + else { + await Object(exec.exec)(installScript, args); + } + if (Object(core.getInput)('project') === 'auto' && + Object(core.getInput)('service-account-key')) { + // Project will be read from the service account key + const buffer = new Buffer(Object(core.getInput)('service-account-key'), 'base64'); + const serviceAccountKey = JSON.parse(buffer.toString()); + if (serviceAccountKey.hasOwnProperty('project_id')) { + await gcloud(['config', 'set', 'project', serviceAccountKey.project_id]); + } + } + else if (Object(core.getInput)('project') !== 'none') { + // Project was passed as input + await gcloud(['config', 'set', 'project', Object(core.getInput)('project')]); + } + const binPath = Object(external_path_.resolve)(getCloudSDKFolder(), 'bin'); + Object(core.addPath)(binPath); +} + +// CONCATENATED MODULE: ./src/install.ts +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "install", function() { return install; }); + + + + + +/** + * Install the Google Cloud SDK. + */ +async function install() { + try { + // Currently, Windows is disabled because the installer does not work properly + if (isWindows()) { + Object(core.error)('This action does not support Windows for now. PR are welcome!'); + } + await download(); + await setup(); + await authenticate(); + } + catch (e) { + Object(core.setFailed)(e.message); + } +} +install() + .then(() => { + Object(core.info)('Installation succeeded'); +}) + .catch(() => { + Object(core.error)('Installation failed'); +}); + + /***/ }), /***/ 874: @@ -4226,7 +4123,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge Object.defineProperty(exports, "__esModule", { value: true }); const url = __webpack_require__(835); const http = __webpack_require__(605); -const https = __webpack_require__(34); +const https = __webpack_require__(211); let fs; let tunnel; var HttpCodes; @@ -4715,4 +4612,62 @@ exports.exec = exec; /***/ }) -/******/ }); \ No newline at end of file +/******/ }, +/******/ function(__webpack_require__) { // webpackRuntimeModules +/******/ "use strict"; +/******/ +/******/ /* webpack/runtime/make namespace object */ +/******/ !function() { +/******/ // define __esModule on exports +/******/ __webpack_require__.r = function(exports) { +/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { +/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); +/******/ } +/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ }; +/******/ }(); +/******/ +/******/ /* webpack/runtime/define property getter */ +/******/ !function() { +/******/ // define getter function for harmony exports +/******/ var hasOwnProperty = Object.prototype.hasOwnProperty; +/******/ __webpack_require__.d = function(exports, name, getter) { +/******/ if(!hasOwnProperty.call(exports, name)) { +/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); +/******/ } +/******/ }; +/******/ }(); +/******/ +/******/ /* webpack/runtime/create fake namespace object */ +/******/ !function() { +/******/ // create a fake namespace object +/******/ // mode & 1: value is a module id, require it +/******/ // mode & 2: merge all properties of value into the ns +/******/ // mode & 4: return value when already ns object +/******/ // mode & 8|1: behave like require +/******/ __webpack_require__.t = function(value, mode) { +/******/ if(mode & 1) value = this(value); +/******/ if(mode & 8) return value; +/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; +/******/ var ns = Object.create(null); +/******/ __webpack_require__.r(ns); +/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); +/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); +/******/ return ns; +/******/ }; +/******/ }(); +/******/ +/******/ /* webpack/runtime/compat get default export */ +/******/ !function() { +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __webpack_require__.n = function(module) { +/******/ var getter = module && module.__esModule ? +/******/ function getDefault() { return module['default']; } : +/******/ function getModuleExports() { return module; }; +/******/ __webpack_require__.d(getter, 'a', getter); +/******/ return getter; +/******/ }; +/******/ }(); +/******/ +/******/ } +); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index ebe153c..cdfc3ed 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@mathrix-education/setup-gcloud", - "version": "0.1.1", + "version": "0.1.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 47a2f8d..aec4022 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@mathrix-education/setup-gcloud", - "version": "0.1.2", - "description": "Small GitHub action to install the Google Cloud SDK on the virtual environment.", + "version": "0.1.3", + "description": "Install the Google Cloud SDK in your GitHub Actions workflow.", "keywords": [ "github-actions", "actions", diff --git a/src/authenticate.ts b/src/authenticate.ts index e51fb2c..3ec3ed0 100644 --- a/src/authenticate.ts +++ b/src/authenticate.ts @@ -9,6 +9,10 @@ import { gcloud } from './utils'; export async function authenticate(): Promise { // If service account key is not provided, skip the authentication if (!core.getInput('service-account-key')) { + core.warning( + 'No service-account-key input was passed.' + + 'If it is intentional, you can safely ignore this warning.', + ); return; } diff --git a/src/download.ts b/src/download.ts index fde5822..0983331 100644 --- a/src/download.ts +++ b/src/download.ts @@ -1,7 +1,7 @@ import * as tc from '@actions/tool-cache'; import { getCloudSDKFolder, getDownloadLink } from './utils'; -import { mkdirSync } from 'fs'; import { resolve } from 'path'; +import * as io from '@actions/io'; /** * Download the Google Cloud SDK archive. @@ -11,7 +11,7 @@ export async function download(): Promise { const downloadPath = await tc.downloadTool(downloadLink); const extractionPath = resolve(getCloudSDKFolder(), '..'); - mkdirSync(getCloudSDKFolder()); + await io.mkdirP(getCloudSDKFolder()); if (downloadLink.endsWith('.zip')) { await tc.extractZip(downloadPath, extractionPath); diff --git a/src/setup.ts b/src/setup.ts index 2e4b723..58249b9 100644 --- a/src/setup.ts +++ b/src/setup.ts @@ -17,7 +17,7 @@ export async function setup(): Promise { const args = [ '--usage-reporting=false', '--command-completion=false', - '--path-update=true', + '--path-update=false', '--usage-reporting=false', '--quiet', ]; @@ -33,7 +33,21 @@ export async function setup(): Promise { await exec.exec(installScript, args); } - if (core.getInput('project')) { + if ( + core.getInput('project') === 'auto' && + core.getInput('service-account-key') + ) { + // Project will be read from the service account key + const buffer = new Buffer(core.getInput('service-account-key'), 'base64'); + const serviceAccountKey: { project_id: string } = JSON.parse( + buffer.toString(), + ); + + if (serviceAccountKey.hasOwnProperty('project_id')) { + await gcloud(['config', 'set', 'project', serviceAccountKey.project_id]); + } + } else if (core.getInput('project') !== 'none') { + // Project was passed as input await gcloud(['config', 'set', 'project', core.getInput('project')]); } diff --git a/tsconfig.json b/tsconfig.json index f1111e5..831c063 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,8 +1,11 @@ { "compilerOptions": { - "module": "commonjs", - "target": "es6", + "target": "es2018", + "moduleResolution": "node", "strict": true, + "lib": [ + "es6" + ], "outDir": "./dist", "rootDir": "./src", "esModuleInterop": true,