From f23ec91f805d0714641dce97e3f45c97df97baa5 Mon Sep 17 00:00:00 2001 From: Mathieu Bour Date: Mon, 27 Jan 2020 00:09:53 +0100 Subject: [PATCH 01/19] fix: project auto input, default input values Also change the default install directory on Ubuntu, to override the default installation. --- .github/workflows/tests.yaml | 11 ++++-- action.yml | 8 ++-- dist/index.js | 76 ++++++++++++++++++++++++------------ package-lock.json | 2 +- src/authenticate.ts | 41 +++++++++++++++---- src/constants.ts | 2 +- src/download.ts | 20 ++++++++-- src/setup.ts | 30 ++++++-------- 8 files changed, 127 insertions(+), 63 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index e203563..4ddca80 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -4,13 +4,15 @@ jobs: test: strategy: matrix: - os: [ubuntu-latest, macos-latest] - version: [latest, 245.0.0] + #os: [ubuntu-latest, macos-latest] + #version: [latest, 245.0.0] + os: [ubuntu-latest] + version: [latest] fail-fast: false runs-on: ${{ matrix.os }} steps: - name: Checkout repository - uses: actions/checkout@v1 + uses: actions/checkout@v2 - name: Setup Node.js 12 uses: actions/setup-node@v1.2.0 with: @@ -19,7 +21,8 @@ jobs: run: node dist/index.js env: INPUT_VERSION: ${{ matrix.version }} - INPUT_PROJECT: ${{ secrets.GCLOUD_PROJECT }} + INPUT_PROJECT: auto + # INPUT_PROJECT: ${{ secrets.GCLOUD_PROJECT }} INPUT_COMPONENTS: beta INPUT_SERVICE-ACCOUNT-KEY: ${{ secrets.GCLOUD_AUTH }} - name: Test Google Cloud SDK CLI diff --git a/action.yml b/action.yml index 1a2d811..c445a65 100644 --- a/action.yml +++ b/action.yml @@ -11,18 +11,18 @@ inputs: version: description: Google Cloud SDK to use. If left null, will use the latest one. required: false - default: latest + 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 - default: auto + default: 'auto' components: - description: Install additional components (e.g. beta, gsutils, etc.) + description: Install additional components (e.g. beta, gsutil, etc.) required: false configure-docker: description: Configure Docker to interact with Google Cloud Container Registry. required: false - default: false + default: 'false' diff --git a/dist/index.js b/dist/index.js index cd95547..f2ac906 100644 --- a/dist/index.js +++ b/dist/index.js @@ -3905,7 +3905,7 @@ 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}`; +const UBUNTU_INSTALL_PATH = `/usr/lib/${INSTALL_DIRECTORY}`; // CONCATENATED MODULE: ./src/utils.ts @@ -3971,13 +3971,12 @@ async function gcloud(args, options = undefined) { 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.'); + 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 serviceAccountKeyJson = Buffer.from(serviceAccountKeyBase64, 'base64').toString(); const serviceAccountKeyPath = Object(external_path_.resolve)(process.cwd(), 'gcloud.json'); Object(external_fs_.writeFileSync)(serviceAccountKeyPath, serviceAccountKeyJson); // Activate the service account @@ -3986,25 +3985,45 @@ async function authenticate() { 'activate-service-account', `--key-file=${serviceAccountKeyPath}`, ]); + // Remove the service account key + Object(external_fs_.unlinkSync)(serviceAccountKeyPath); + // Configure the default project + if (Object(core.getInput)('project') === 'auto' && + Object(core.getInput)('service-account-key') !== '') { + // Project will be read from the service account key + const serviceAccountKey = JSON.parse(serviceAccountKeyJson.toString()); + if (serviceAccountKey.hasOwnProperty('project_id')) { + // If key has a project_id field, use it to set the default project + await gcloud(['config', 'set', 'project', serviceAccountKey.project_id]); + } + else { + Object(core.warning)('You gave a service account key, but it does not have the "project_id" key. Thus, the default project ' + + 'cannot be configured. Your service account key might malformed.'); + } + } + else if (Object(core.getInput)('project') !== 'none') { + // Project was passed as input + await gcloud(['config', 'set', 'project', Object(core.getInput)('project')]); + } // Configure Docker if necessary - if (Object(core.getInput)('configure-docker')) { + if (Object(core.getInput)('configure-docker') === 'true') { 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); +// EXTERNAL MODULE: ./node_modules/@actions/tool-cache/lib/tool-cache.js +var tool_cache = __webpack_require__(533); + // CONCATENATED MODULE: ./src/download.ts + + /** * Download the Google Cloud SDK archive. */ @@ -4017,7 +4036,19 @@ async function download() { await Object(tool_cache.extractZip)(downloadPath, extractionPath); } else if (downloadLink.endsWith('.tar.gz')) { - await Object(tool_cache.extractTar)(downloadPath, extractionPath); + // Remove the existing installation of Google Cloud SDK on Ubuntu Runners + if (isUbuntu()) { + const cleanupScript = [ + `sudo rm -rf ${UBUNTU_INSTALL_PATH}`, + `sudo tar -xf ${downloadPath} -C ${Object(external_path_.resolve)(UBUNTU_INSTALL_PATH, '..')}`, + ]; + for (const line of cleanupScript) { + await Object(exec.exec)(line); + } + } + else { + await Object(tool_cache.extractTar)(downloadPath, extractionPath); + } } } @@ -4050,22 +4081,19 @@ async function setup() { // @actions/exec does not exit on windows Object(external_child_process_.execSync)(`"${installScript}" ${args.join(' ')}`, { stdio: 'inherit' }); } + else if (isUbuntu()) { + /* + * Since we extracted the SDK to a procted directory, we have also to run the installer as root, which has + * side-effects on the user $HOME folder. + */ + await Object(exec.exec)(`sudo ${installScript}`, args); + const user = process.env.USER || ''; + const home = process.env.HOME || ''; + await Object(exec.exec)(`sudo chown -R ${user} ${home}`); + } 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); } diff --git a/package-lock.json b/package-lock.json index cdfc3ed..f1aecb4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@mathrix-education/setup-gcloud", - "version": "0.1.2", + "version": "0.1.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/authenticate.ts b/src/authenticate.ts index 3ec3ed0..3642ca5 100644 --- a/src/authenticate.ts +++ b/src/authenticate.ts @@ -1,4 +1,5 @@ import * as core from '@actions/core'; +import * as exec from '@actions/exec'; import { unlinkSync, writeFileSync } from 'fs'; import { resolve } from 'path'; import { gcloud } from './utils'; @@ -10,15 +11,17 @@ 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.', + '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 = core.getInput('service-account-key'); - const serviceAccountKeyJson = Buffer.from(serviceAccountKeyBase64, 'base64'); + const serviceAccountKeyJson = Buffer.from( + serviceAccountKeyBase64, + 'base64', + ).toString(); const serviceAccountKeyPath = resolve(process.cwd(), 'gcloud.json'); writeFileSync(serviceAccountKeyPath, serviceAccountKeyJson); @@ -29,11 +32,35 @@ export async function authenticate(): Promise { `--key-file=${serviceAccountKeyPath}`, ]); + // Remove the service account key + unlinkSync(serviceAccountKeyPath); + + // Configure the default project + if ( + core.getInput('project') === 'auto' && + core.getInput('service-account-key') !== '' + ) { + // Project will be read from the service account key + const serviceAccountKey: { project_id: string } = JSON.parse( + serviceAccountKeyJson.toString(), + ); + + if (serviceAccountKey.hasOwnProperty('project_id')) { + // If key has a project_id field, use it to set the default project + await gcloud(['config', 'set', 'project', serviceAccountKey.project_id]); + } else { + core.warning( + 'You gave a service account key, but it does not have the "project_id" key. Thus, the default project ' + + 'cannot be configured. Your service account key might malformed.', + ); + } + } else if (core.getInput('project') !== 'none') { + // Project was passed as input + await gcloud(['config', 'set', 'project', core.getInput('project')]); + } + // Configure Docker if necessary - if (core.getInput('configure-docker')) { + if (core.getInput('configure-docker') === 'true') { await gcloud(['--quiet', 'auth', 'configure-docker']); } - - // Remove the service account key - unlinkSync(serviceAccountKeyPath); } diff --git a/src/constants.ts b/src/constants.ts index 36cfe64..27566b9 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,3 +1,3 @@ export const INSTALL_DIRECTORY = 'google-cloud-sdk'; export const WINDOWS_INSTALL_PATH = `C:\\${INSTALL_DIRECTORY}`; -export const UBUNTU_INSTALL_PATH = `/home/runner/${INSTALL_DIRECTORY}`; +export const UBUNTU_INSTALL_PATH = `/usr/lib/${INSTALL_DIRECTORY}`; diff --git a/src/download.ts b/src/download.ts index 0983331..4b7e44a 100644 --- a/src/download.ts +++ b/src/download.ts @@ -1,7 +1,9 @@ +import * as exec from '@actions/exec'; +import * as io from '@actions/io'; import * as tc from '@actions/tool-cache'; -import { getCloudSDKFolder, getDownloadLink } from './utils'; import { resolve } from 'path'; -import * as io from '@actions/io'; +import { UBUNTU_INSTALL_PATH } from './constants'; +import { getCloudSDKFolder, getDownloadLink, isUbuntu } from './utils'; /** * Download the Google Cloud SDK archive. @@ -16,6 +18,18 @@ export async function download(): Promise { if (downloadLink.endsWith('.zip')) { await tc.extractZip(downloadPath, extractionPath); } else if (downloadLink.endsWith('.tar.gz')) { - await tc.extractTar(downloadPath, extractionPath); + // Remove the existing installation of Google Cloud SDK on Ubuntu Runners + if (isUbuntu()) { + const cleanupScript = [ + `sudo rm -rf ${UBUNTU_INSTALL_PATH}`, + `sudo tar -xf ${downloadPath} -C ${resolve(UBUNTU_INSTALL_PATH, '..')}`, + ]; + + for (const line of cleanupScript) { + await exec.exec(line); + } + } else { + await tc.extractTar(downloadPath, extractionPath); + } } } diff --git a/src/setup.ts b/src/setup.ts index 58249b9..9d2646e 100644 --- a/src/setup.ts +++ b/src/setup.ts @@ -2,7 +2,7 @@ import * as core from '@actions/core'; import * as exec from '@actions/exec'; import { execSync } from 'child_process'; import { resolve } from 'path'; -import { gcloud, getCloudSDKFolder, isWindows } from './utils'; +import { getCloudSDKFolder, isUbuntu, isWindows } from './utils'; /** * Setup the Google Cloud SDK. @@ -29,28 +29,20 @@ export async function setup(): Promise { if (isWindows()) { // @actions/exec does not exit on windows execSync(`"${installScript}" ${args.join(' ')}`, { stdio: 'inherit' }); + } else if (isUbuntu()) { + /* + * Since we extracted the SDK to a procted directory, we have also to run the installer as root, which has + * side-effects on the user $HOME folder. + */ + await exec.exec(`sudo ${installScript}`, args); + + const user = process.env.USER || ''; + const home = process.env.HOME || ''; + await exec.exec(`sudo chown -R ${user} ${home}`); } else { await exec.exec(installScript, args); } - 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')]); - } - const binPath = resolve(getCloudSDKFolder(), 'bin'); core.addPath(binPath); } From 341fc78f70b01fd264d00e6deb7fd2ccae4fd96d Mon Sep 17 00:00:00 2001 From: Mathieu Bour Date: Mon, 27 Jan 2020 02:03:17 +0100 Subject: [PATCH 02/19] ci: re-add mac-os --- .github/workflows/tests.yaml | 20 ++++++++++++++------ CHANGELOG.md | 6 ++++++ 2 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 CHANGELOG.md diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 4ddca80..c77b1aa 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -4,10 +4,19 @@ jobs: test: strategy: matrix: - #os: [ubuntu-latest, macos-latest] - #version: [latest, 245.0.0] - os: [ubuntu-latest] - version: [latest] + os: [ubuntu-latest, macos-latest] + version: [latest, 245.0.0] + project: [auto, 'matrix-education'] + exclude: + - os: macos-latest + version: latest + project: 'matrix-education' + - os: macos-latest + version: 245.0.0 + project: auto + - os: macos-latest + version: 245.0.0 + project: 'matrix-education' fail-fast: false runs-on: ${{ matrix.os }} steps: @@ -21,8 +30,7 @@ jobs: run: node dist/index.js env: INPUT_VERSION: ${{ matrix.version }} - INPUT_PROJECT: auto - # INPUT_PROJECT: ${{ secrets.GCLOUD_PROJECT }} + INPUT_PROJECT: ${{ matrix.project }} INPUT_COMPONENTS: beta INPUT_SERVICE-ACCOUNT-KEY: ${{ secrets.GCLOUD_AUTH }} - name: Test Google Cloud SDK CLI diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..65f0d72 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,6 @@ +# Changelog + +## Version 1.0.0 - Stable release +- fixed: inputs are now compared to strings +- fixed: project guess using the `service-account-key` input +- changed: install directory on Ubuntu runners (overrides the already installed one) From 42a1794af3af2b81412b7ebb87327441d459484b Mon Sep 17 00:00:00 2001 From: Mathieu Bour Date: Mon, 27 Jan 2020 02:20:29 +0100 Subject: [PATCH 03/19] chore(docs): update README and CHANGELOG --- CHANGELOG.md | 9 ++++++--- README.md | 6 ++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65f0d72..086053c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog ## Version 1.0.0 - Stable release -- fixed: inputs are now compared to strings -- fixed: project guess using the `service-account-key` input -- changed: install directory on Ubuntu runners (overrides the already installed one) +- **fixed**: inputs are now compared to strings +- **fixed**: project guess using the `service-account-key` input +- **changed**: install directory on Ubuntu runners (overrides the already installed one) + +## Version 0.1.x - Pre-releases +The versions are now deprecated and should not be used. diff --git a/README.md b/README.md index 6c2fa9a..1f295a0 100644 --- a/README.md +++ b/README.md @@ -18,9 +18,15 @@ If the official [@actions/gcloud][2.1] action works perfectly, the fact that it 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. +Update [2019/01/27]: The [GoogleCloudPlatform official GitHub organization][2.4] has released an official +[setup-gcloud][2.5] action. Compared to Mathrix's one, we provide some additional automation tasks, such as project +guessing and automatic Docker Configuration. + [2.1]: https://github.com/actions/gcloud [2.2]: https://github.com/actions/gcloud/tree/master/auth [2.3]: https://github.com/actions/gcloud/tree/master/cli +[2.4]: https://github.com/GoogleCloudPlatform +[2.5]: https://github.com/GoogleCloudPlatform/github-actions/tree/master/setup-gcloud ## Usage From 9491762954d4149595ee415cfc85e83118dff2ae Mon Sep 17 00:00:00 2001 From: Mathieu Bour Date: Mon, 27 Jan 2020 02:24:13 +0100 Subject: [PATCH 04/19] ci(actions): drop ubuntu-latest, 245.0.0, matrix-education from matrix --- .github/workflows/tests.yaml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index c77b1aa..5c0625e 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -6,17 +6,20 @@ jobs: matrix: os: [ubuntu-latest, macos-latest] version: [latest, 245.0.0] - project: [auto, 'matrix-education'] + project: [auto, matrix-education] exclude: + - os: ubuntu-latest + version: 245.0.0 + project: matrix-education - os: macos-latest version: latest - project: 'matrix-education' + project: matrix-education - os: macos-latest version: 245.0.0 project: auto - os: macos-latest version: 245.0.0 - project: 'matrix-education' + project: matrix-education fail-fast: false runs-on: ${{ matrix.os }} steps: From 4f1d2d7e4b95323776ffcc083a8265372b8805e6 Mon Sep 17 00:00:00 2001 From: Mathieu Bour Date: Mon, 27 Jan 2020 02:26:43 +0100 Subject: [PATCH 05/19] ci(actions): test on windows-latest --- .github/workflows/tests.yaml | 39 ++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 5c0625e..e73dd7e 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -1,25 +1,30 @@ name: Tests -on: push +on: + push: + branches: ['**'] jobs: test: strategy: matrix: - os: [ubuntu-latest, macos-latest] - version: [latest, 245.0.0] - project: [auto, matrix-education] - exclude: - - os: ubuntu-latest - version: 245.0.0 - project: matrix-education - - os: macos-latest - version: latest - project: matrix-education - - os: macos-latest - version: 245.0.0 - project: auto - - os: macos-latest - version: 245.0.0 - project: matrix-education + os: [windows-latest] + version: [latest] + project: [auto] +# os: [ubuntu-latest, macos-latest] +# version: [latest, 245.0.0] +# project: [auto, matrix-education] +# exclude: +# - os: ubuntu-latest +# version: 245.0.0 +# project: matrix-education +# - os: macos-latest +# version: latest +# project: matrix-education +# - os: macos-latest +# version: 245.0.0 +# project: auto +# - os: macos-latest +# version: 245.0.0 +# project: matrix-education fail-fast: false runs-on: ${{ matrix.os }} steps: From b262fa0416217c83d0f36c8a8e6e7eb517048ce8 Mon Sep 17 00:00:00 2001 From: Mathieu Bour Date: Mon, 27 Jan 2020 02:38:59 +0100 Subject: [PATCH 06/19] feat(windows): update windows install dir --- dist/index.js | 25 +++++++++++-------------- src/constants.ts | 3 ++- src/download.ts | 16 ++++++++-------- src/install.ts | 7 ------- 4 files changed, 21 insertions(+), 30 deletions(-) diff --git a/dist/index.js b/dist/index.js index f2ac906..fdc053f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -3904,7 +3904,8 @@ var exec = __webpack_require__(986); // CONCATENATED MODULE: ./src/constants.ts const INSTALL_DIRECTORY = 'google-cloud-sdk'; -const WINDOWS_INSTALL_PATH = `C:\\${INSTALL_DIRECTORY}`; +const WINDOWS_INSTALL_PATH = `C:\\Program Files\\${INSTALL_DIRECTORY}`; +const MACOS_INSTALL_PATH = `/usr/lib/${INSTALL_DIRECTORY}`; const UBUNTU_INSTALL_PATH = `/usr/lib/${INSTALL_DIRECTORY}`; // CONCATENATED MODULE: ./src/utils.ts @@ -4033,23 +4034,24 @@ async function download() { const extractionPath = Object(external_path_.resolve)(getCloudSDKFolder(), '..'); await Object(io.mkdirP)(getCloudSDKFolder()); if (downloadLink.endsWith('.zip')) { + // Extract .zip (Windows). await Object(tool_cache.extractZip)(downloadPath, extractionPath); } else if (downloadLink.endsWith('.tar.gz')) { - // Remove the existing installation of Google Cloud SDK on Ubuntu Runners if (isUbuntu()) { - const cleanupScript = [ - `sudo rm -rf ${UBUNTU_INSTALL_PATH}`, - `sudo tar -xf ${downloadPath} -C ${Object(external_path_.resolve)(UBUNTU_INSTALL_PATH, '..')}`, - ]; - for (const line of cleanupScript) { - await Object(exec.exec)(line); - } + // Remove the existing installation of Google Cloud SDK on Ubuntu Runners + const parentInstallDir = Object(external_path_.resolve)(UBUNTU_INSTALL_PATH, '..'); + await Object(exec.exec)(`sudo rm -rf ${UBUNTU_INSTALL_PATH}`); + await Object(exec.exec)(`sudo tar -xf ${downloadPath} -C ${parentInstallDir}`); } else { + // Simply extract the tar.gz archive await Object(tool_cache.extractTar)(downloadPath, extractionPath); } } + else { + // Should never be reached + } } // EXTERNAL MODULE: external "child_process" @@ -4104,16 +4106,11 @@ async function setup() { - /** * 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(); diff --git a/src/constants.ts b/src/constants.ts index 27566b9..cb451bb 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,3 +1,4 @@ export const INSTALL_DIRECTORY = 'google-cloud-sdk'; -export const WINDOWS_INSTALL_PATH = `C:\\${INSTALL_DIRECTORY}`; +export const WINDOWS_INSTALL_PATH = `C:\\Program Files\\${INSTALL_DIRECTORY}`; +export const MACOS_INSTALL_PATH = `/usr/lib/${INSTALL_DIRECTORY}`; export const UBUNTU_INSTALL_PATH = `/usr/lib/${INSTALL_DIRECTORY}`; diff --git a/src/download.ts b/src/download.ts index 4b7e44a..17d619e 100644 --- a/src/download.ts +++ b/src/download.ts @@ -16,20 +16,20 @@ export async function download(): Promise { await io.mkdirP(getCloudSDKFolder()); if (downloadLink.endsWith('.zip')) { + // Extract .zip (Windows). await tc.extractZip(downloadPath, extractionPath); } else if (downloadLink.endsWith('.tar.gz')) { - // Remove the existing installation of Google Cloud SDK on Ubuntu Runners if (isUbuntu()) { - const cleanupScript = [ - `sudo rm -rf ${UBUNTU_INSTALL_PATH}`, - `sudo tar -xf ${downloadPath} -C ${resolve(UBUNTU_INSTALL_PATH, '..')}`, - ]; + // Remove the existing installation of Google Cloud SDK on Ubuntu Runners + const parentInstallDir = resolve(UBUNTU_INSTALL_PATH, '..'); - for (const line of cleanupScript) { - await exec.exec(line); - } + await exec.exec(`sudo rm -rf ${UBUNTU_INSTALL_PATH}`); + await exec.exec(`sudo tar -xf ${downloadPath} -C ${parentInstallDir}`); } else { + // Simply extract the tar.gz archive await tc.extractTar(downloadPath, extractionPath); } + } else { + // Should never be reached } } diff --git a/src/install.ts b/src/install.ts index 69bfbd3..b4a9bf9 100644 --- a/src/install.ts +++ b/src/install.ts @@ -9,13 +9,6 @@ import { isWindows } from './utils'; */ export async function install(): Promise { try { - // Currently, Windows is disabled because the installer does not work properly - if (isWindows()) { - core.error( - 'This action does not support Windows for now. PR are welcome!', - ); - } - await download(); await setup(); await authenticate(); From ab300ec19068ea786b51ea1059e690f901a56778 Mon Sep 17 00:00:00 2001 From: Mathieu Bour Date: Mon, 27 Jan 2020 02:46:05 +0100 Subject: [PATCH 07/19] feat(windows): escape installation directory spaces --- dist/index.js | 8 ++++++-- src/utils.ts | 12 ++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index fdc053f..3fbf485 100644 --- a/dist/index.js +++ b/dist/index.js @@ -3956,8 +3956,12 @@ function getDownloadLink() { } } async function gcloud(args, options = undefined) { - const gcloudPath = Object(external_path_.resolve)(getCloudSDKFolder(), 'bin', 'gcloud' + (isWindows() ? '.cmd' : '')); - args.unshift('--quiet'); + let gcloudPath = Object(external_path_.resolve)(getCloudSDKFolder(), 'bin', 'gcloud' + (isWindows() ? '.cmd' : '')); + if (isWindows()) { + // Windows installation directory is C:\Program Files and thus need to be escaped + gcloudPath = gcloudPath.replace(getCloudSDKFolder(), `"${getCloudSDKFolder()}"`); + } + args.unshift('--quiet'); // Add quiet to all commands await Object(exec.exec)(gcloudPath, args, options); } diff --git a/src/utils.ts b/src/utils.ts index 40073a6..d954cdc 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -55,13 +55,21 @@ export async function gcloud( args: string[], options: any = undefined, ): Promise { - const gcloudPath = resolve( + let gcloudPath = resolve( getCloudSDKFolder(), 'bin', 'gcloud' + (isWindows() ? '.cmd' : ''), ); - args.unshift('--quiet'); + if (isWindows()) { + // Windows installation directory is C:\Program Files and thus need to be escaped + gcloudPath = gcloudPath.replace( + getCloudSDKFolder(), + `"${getCloudSDKFolder()}"`, + ); + } + + args.unshift('--quiet'); // Add quiet to all commands await exec.exec(gcloudPath, args, options); } From de3952fea737ca1800094f314b9db0a67e0c7734 Mon Sep 17 00:00:00 2001 From: Mathieu Bour Date: Mon, 27 Jan 2020 02:55:21 +0100 Subject: [PATCH 08/19] feat(windows): update types and docs --- dist/index.js | 38 ++++++++++++++++++++++++++++++-------- src/authenticate.ts | 1 - src/download.ts | 10 +++++++--- src/setup.ts | 8 ++++---- src/utils.ts | 31 ++++++++++++++++++++++++++----- 5 files changed, 67 insertions(+), 21 deletions(-) diff --git a/dist/index.js b/dist/index.js index 3fbf485..8b4ba8c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -3913,16 +3913,28 @@ const UBUNTU_INSTALL_PATH = `/usr/lib/${INSTALL_DIRECTORY}`; +/** + * Check if the runner is Windows-based. + */ function isWindows() { return process.platform === 'win32'; } +/** + * Check if the runner is MacOS-based. + */ function isMacOS() { return process.platform === 'darwin'; } +/** + * Check if the runner is Ubuntu-based. + */ function isUbuntu() { return process.platform === 'linux'; } -function getCloudSDKFolder() { +/** + * Get the Google Cloud SDK installation directory. + */ +function getCloudSDKDirectory() { if (isWindows()) { return WINDOWS_INSTALL_PATH; } @@ -3934,6 +3946,9 @@ function getCloudSDKFolder() { return Object(external_path_.resolve)(home, INSTALL_DIRECTORY); } } +/** + * Get the Google Cloud SDK download link + */ function getDownloadLink() { const baseUrl = 'https://dl.google.com/dl/cloudsdk/channels/rapid'; const version = Object(core.getInput)('version'); @@ -3955,11 +3970,16 @@ function getDownloadLink() { return `${baseUrl}/downloads/google-cloud-sdk-${version}-linux-x86_64.tar.gz`; } } +/** + * Execute a gcloud command + * @param args The gcloud args + * @param options The command options + */ async function gcloud(args, options = undefined) { - let gcloudPath = Object(external_path_.resolve)(getCloudSDKFolder(), 'bin', 'gcloud' + (isWindows() ? '.cmd' : '')); + let gcloudPath = Object(external_path_.resolve)(getCloudSDKDirectory(), 'bin', 'gcloud' + (isWindows() ? '.cmd' : '')); if (isWindows()) { // Windows installation directory is C:\Program Files and thus need to be escaped - gcloudPath = gcloudPath.replace(getCloudSDKFolder(), `"${getCloudSDKFolder()}"`); + gcloudPath = gcloudPath.replace(getCloudSDKDirectory(), `"${getCloudSDKDirectory()}"`); } args.unshift('--quiet'); // Add quiet to all commands await Object(exec.exec)(gcloudPath, args, options); @@ -4029,14 +4049,15 @@ var tool_cache = __webpack_require__(533); + /** * 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()); + const extractionPath = Object(external_path_.resolve)(getCloudSDKDirectory(), '..'); + await Object(io.mkdirP)(getCloudSDKDirectory()); if (downloadLink.endsWith('.zip')) { // Extract .zip (Windows). await Object(tool_cache.extractZip)(downloadPath, extractionPath); @@ -4055,6 +4076,7 @@ async function download() { } else { // Should never be reached + Object(core.setFailed)(`Unexpected extension (expected zip or tar.gz), but got ${downloadLink}`); } } @@ -4072,7 +4094,7 @@ var external_child_process_ = __webpack_require__(129); */ async function setup() { const installScriptExtension = isWindows() ? 'bat' : 'sh'; - const installScript = Object(external_path_.resolve)(getCloudSDKFolder(), `install.${installScriptExtension}`); + const installScript = Object(external_path_.resolve)(getCloudSDKDirectory(), `install.${installScriptExtension}`); const args = [ '--usage-reporting=false', '--command-completion=false', @@ -4080,7 +4102,7 @@ async function setup() { '--usage-reporting=false', '--quiet', ]; - if (Object(core.getInput)('components')) { + if (Object(core.getInput)('components') !== '') { args.push('--additional-components=' + Object(core.getInput)('components')); } if (isWindows()) { @@ -4100,7 +4122,7 @@ async function setup() { else { await Object(exec.exec)(installScript, args); } - const binPath = Object(external_path_.resolve)(getCloudSDKFolder(), 'bin'); + const binPath = Object(external_path_.resolve)(getCloudSDKDirectory(), 'bin'); Object(core.addPath)(binPath); } diff --git a/src/authenticate.ts b/src/authenticate.ts index 3642ca5..e31b469 100644 --- a/src/authenticate.ts +++ b/src/authenticate.ts @@ -1,5 +1,4 @@ import * as core from '@actions/core'; -import * as exec from '@actions/exec'; import { unlinkSync, writeFileSync } from 'fs'; import { resolve } from 'path'; import { gcloud } from './utils'; diff --git a/src/download.ts b/src/download.ts index 17d619e..35d2832 100644 --- a/src/download.ts +++ b/src/download.ts @@ -1,9 +1,10 @@ +import * as core from '@actions/core'; import * as exec from '@actions/exec'; import * as io from '@actions/io'; import * as tc from '@actions/tool-cache'; import { resolve } from 'path'; import { UBUNTU_INSTALL_PATH } from './constants'; -import { getCloudSDKFolder, getDownloadLink, isUbuntu } from './utils'; +import { getCloudSDKDirectory, getDownloadLink, isUbuntu } from './utils'; /** * Download the Google Cloud SDK archive. @@ -11,9 +12,9 @@ import { getCloudSDKFolder, getDownloadLink, isUbuntu } from './utils'; export async function download(): Promise { const downloadLink = getDownloadLink(); const downloadPath = await tc.downloadTool(downloadLink); - const extractionPath = resolve(getCloudSDKFolder(), '..'); + const extractionPath = resolve(getCloudSDKDirectory(), '..'); - await io.mkdirP(getCloudSDKFolder()); + await io.mkdirP(getCloudSDKDirectory()); if (downloadLink.endsWith('.zip')) { // Extract .zip (Windows). @@ -31,5 +32,8 @@ export async function download(): Promise { } } else { // Should never be reached + core.setFailed( + `Unexpected extension (expected zip or tar.gz), but got ${downloadLink}`, + ); } } diff --git a/src/setup.ts b/src/setup.ts index 9d2646e..cf61345 100644 --- a/src/setup.ts +++ b/src/setup.ts @@ -2,7 +2,7 @@ import * as core from '@actions/core'; import * as exec from '@actions/exec'; import { execSync } from 'child_process'; import { resolve } from 'path'; -import { getCloudSDKFolder, isUbuntu, isWindows } from './utils'; +import { getCloudSDKDirectory, isUbuntu, isWindows } from './utils'; /** * Setup the Google Cloud SDK. @@ -10,7 +10,7 @@ import { getCloudSDKFolder, isUbuntu, isWindows } from './utils'; export async function setup(): Promise { const installScriptExtension = isWindows() ? 'bat' : 'sh'; const installScript = resolve( - getCloudSDKFolder(), + getCloudSDKDirectory(), `install.${installScriptExtension}`, ); @@ -22,7 +22,7 @@ export async function setup(): Promise { '--quiet', ]; - if (core.getInput('components')) { + if (core.getInput('components') !== '') { args.push('--additional-components=' + core.getInput('components')); } @@ -43,6 +43,6 @@ export async function setup(): Promise { await exec.exec(installScript, args); } - const binPath = resolve(getCloudSDKFolder(), 'bin'); + const binPath = resolve(getCloudSDKDirectory(), 'bin'); core.addPath(binPath); } diff --git a/src/utils.ts b/src/utils.ts index d954cdc..49292f6 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,5 +1,6 @@ import * as core from '@actions/core'; import * as exec from '@actions/exec'; +import { ExecOptions } from '@actions/exec/lib/interfaces'; import { resolve } from 'path'; import { INSTALL_DIRECTORY, @@ -7,19 +8,31 @@ import { WINDOWS_INSTALL_PATH, } from './constants'; +/** + * Check if the runner is Windows-based. + */ export function isWindows(): boolean { return process.platform === 'win32'; } +/** + * Check if the runner is MacOS-based. + */ export function isMacOS(): boolean { return process.platform === 'darwin'; } +/** + * Check if the runner is Ubuntu-based. + */ export function isUbuntu(): boolean { return process.platform === 'linux'; } -export function getCloudSDKFolder(): string { +/** + * Get the Google Cloud SDK installation directory. + */ +export function getCloudSDKDirectory(): string { if (isWindows()) { return WINDOWS_INSTALL_PATH; } else if (isUbuntu()) { @@ -30,6 +43,9 @@ export function getCloudSDKFolder(): string { } } +/** + * Get the Google Cloud SDK download link + */ export function getDownloadLink(): string { const baseUrl = 'https://dl.google.com/dl/cloudsdk/channels/rapid'; const version = core.getInput('version'); @@ -51,12 +67,17 @@ export function getDownloadLink(): string { } } +/** + * Execute a gcloud command + * @param args The gcloud args + * @param options The command options + */ export async function gcloud( args: string[], - options: any = undefined, + options: ExecOptions | undefined = undefined, ): Promise { let gcloudPath = resolve( - getCloudSDKFolder(), + getCloudSDKDirectory(), 'bin', 'gcloud' + (isWindows() ? '.cmd' : ''), ); @@ -64,8 +85,8 @@ export async function gcloud( if (isWindows()) { // Windows installation directory is C:\Program Files and thus need to be escaped gcloudPath = gcloudPath.replace( - getCloudSDKFolder(), - `"${getCloudSDKFolder()}"`, + getCloudSDKDirectory(), + `"${getCloudSDKDirectory()}"`, ); } From 626b0f54ae76df332482a0c496525cb29326e117 Mon Sep 17 00:00:00 2001 From: Mathieu Bour Date: Mon, 27 Jan 2020 03:00:25 +0100 Subject: [PATCH 09/19] feat(macos): update macos install path and docs --- .github/workflows/tests.yaml | 11 ++++++++++- dist/index.js | 27 +++++++++++---------------- src/constants.ts | 2 +- src/download.ts | 13 +++++-------- src/install.ts | 1 - src/setup.ts | 11 ++++++----- src/utils.ts | 4 ++-- 7 files changed, 35 insertions(+), 34 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index e73dd7e..7cf68b5 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -6,7 +6,7 @@ jobs: test: strategy: matrix: - os: [windows-latest] + os: [windows-latest, macos-latest] version: [latest] project: [auto] # os: [ubuntu-latest, macos-latest] @@ -24,6 +24,15 @@ jobs: # project: auto # - os: macos-latest # version: 245.0.0 +# project: matrix-education +# - os: windows-latest +# version: latest +# project: matrix-education +# - os: windows-latest +# version: 245.0.0 +# project: auto +# - os: windows-latest +# version: 245.0.0 # project: matrix-education fail-fast: false runs-on: ${{ matrix.os }} diff --git a/dist/index.js b/dist/index.js index 8b4ba8c..4dabe4d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -3906,7 +3906,7 @@ var exec = __webpack_require__(986); const INSTALL_DIRECTORY = 'google-cloud-sdk'; const WINDOWS_INSTALL_PATH = `C:\\Program Files\\${INSTALL_DIRECTORY}`; const MACOS_INSTALL_PATH = `/usr/lib/${INSTALL_DIRECTORY}`; -const UBUNTU_INSTALL_PATH = `/usr/lib/${INSTALL_DIRECTORY}`; +const UBUNTU_INSTALL_PATH = `${process.env.HOME}/opt/${INSTALL_DIRECTORY}`; // CONCATENATED MODULE: ./src/utils.ts @@ -3942,8 +3942,7 @@ function getCloudSDKDirectory() { return UBUNTU_INSTALL_PATH; } else { - const home = process.env.HOME ? process.env.HOME : process.cwd(); - return Object(external_path_.resolve)(home, INSTALL_DIRECTORY); + return MACOS_INSTALL_PATH; } } /** @@ -4036,9 +4035,6 @@ async function authenticate() { } } -// EXTERNAL MODULE: ./node_modules/@actions/io/lib/io.js -var io = __webpack_require__(1); - // EXTERNAL MODULE: ./node_modules/@actions/tool-cache/lib/tool-cache.js var tool_cache = __webpack_require__(533); @@ -4049,7 +4045,6 @@ var tool_cache = __webpack_require__(533); - /** * Download the Google Cloud SDK archive. */ @@ -4057,21 +4052,20 @@ async function download() { const downloadLink = getDownloadLink(); const downloadPath = await Object(tool_cache.downloadTool)(downloadLink); const extractionPath = Object(external_path_.resolve)(getCloudSDKDirectory(), '..'); - await Object(io.mkdirP)(getCloudSDKDirectory()); if (downloadLink.endsWith('.zip')) { - // Extract .zip (Windows). + // Windows: simply extract zip file await Object(tool_cache.extractZip)(downloadPath, extractionPath); } else if (downloadLink.endsWith('.tar.gz')) { if (isUbuntu()) { - // Remove the existing installation of Google Cloud SDK on Ubuntu Runners + // Ubuntu: Remove the existing installation of Google Cloud SDK const parentInstallDir = Object(external_path_.resolve)(UBUNTU_INSTALL_PATH, '..'); await Object(exec.exec)(`sudo rm -rf ${UBUNTU_INSTALL_PATH}`); await Object(exec.exec)(`sudo tar -xf ${downloadPath} -C ${parentInstallDir}`); } else { - // Simply extract the tar.gz archive - await Object(tool_cache.extractTar)(downloadPath, extractionPath); + // MacOS: simply extract tar.gz file + await Object(tool_cache.extractTar)(downloadPath, MACOS_INSTALL_PATH); } } else { @@ -4090,7 +4084,7 @@ var external_child_process_ = __webpack_require__(129); /** - * Setup the Google Cloud SDK. + * Setup the Google Cloud SDK by running the install script. */ async function setup() { const installScriptExtension = isWindows() ? 'bat' : 'sh'; @@ -4109,9 +4103,9 @@ async function setup() { // @actions/exec does not exit on windows Object(external_child_process_.execSync)(`"${installScript}" ${args.join(' ')}`, { stdio: 'inherit' }); } - else if (isUbuntu()) { + else if (isUbuntu() || isMacOS()) { /* - * Since we extracted the SDK to a procted directory, we have also to run the installer as root, which has + * Since we extracted the SDK to a protected directory, we have also to run the installer as root, which has * side-effects on the user $HOME folder. */ await Object(exec.exec)(`sudo ${installScript}`, args); @@ -4120,7 +4114,8 @@ async function setup() { await Object(exec.exec)(`sudo chown -R ${user} ${home}`); } else { - await Object(exec.exec)(installScript, args); + // Should never be reached + Object(core.setFailed)(`Unexpected os platform, got: ${process.platform}`); } const binPath = Object(external_path_.resolve)(getCloudSDKDirectory(), 'bin'); Object(core.addPath)(binPath); diff --git a/src/constants.ts b/src/constants.ts index cb451bb..70c43dc 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,4 +1,4 @@ export const INSTALL_DIRECTORY = 'google-cloud-sdk'; export const WINDOWS_INSTALL_PATH = `C:\\Program Files\\${INSTALL_DIRECTORY}`; export const MACOS_INSTALL_PATH = `/usr/lib/${INSTALL_DIRECTORY}`; -export const UBUNTU_INSTALL_PATH = `/usr/lib/${INSTALL_DIRECTORY}`; +export const UBUNTU_INSTALL_PATH = `${process.env.HOME}/opt/${INSTALL_DIRECTORY}`; diff --git a/src/download.ts b/src/download.ts index 35d2832..6ec5c48 100644 --- a/src/download.ts +++ b/src/download.ts @@ -1,9 +1,8 @@ import * as core from '@actions/core'; import * as exec from '@actions/exec'; -import * as io from '@actions/io'; import * as tc from '@actions/tool-cache'; import { resolve } from 'path'; -import { UBUNTU_INSTALL_PATH } from './constants'; +import { MACOS_INSTALL_PATH, UBUNTU_INSTALL_PATH } from './constants'; import { getCloudSDKDirectory, getDownloadLink, isUbuntu } from './utils'; /** @@ -14,21 +13,19 @@ export async function download(): Promise { const downloadPath = await tc.downloadTool(downloadLink); const extractionPath = resolve(getCloudSDKDirectory(), '..'); - await io.mkdirP(getCloudSDKDirectory()); - if (downloadLink.endsWith('.zip')) { - // Extract .zip (Windows). + // Windows: simply extract zip file await tc.extractZip(downloadPath, extractionPath); } else if (downloadLink.endsWith('.tar.gz')) { if (isUbuntu()) { - // Remove the existing installation of Google Cloud SDK on Ubuntu Runners + // Ubuntu: Remove the existing installation of Google Cloud SDK const parentInstallDir = resolve(UBUNTU_INSTALL_PATH, '..'); await exec.exec(`sudo rm -rf ${UBUNTU_INSTALL_PATH}`); await exec.exec(`sudo tar -xf ${downloadPath} -C ${parentInstallDir}`); } else { - // Simply extract the tar.gz archive - await tc.extractTar(downloadPath, extractionPath); + // MacOS: simply extract tar.gz file + await tc.extractTar(downloadPath, MACOS_INSTALL_PATH); } } else { // Should never be reached diff --git a/src/install.ts b/src/install.ts index b4a9bf9..f8490d8 100644 --- a/src/install.ts +++ b/src/install.ts @@ -2,7 +2,6 @@ import * as core from '@actions/core'; import { authenticate } from './authenticate'; import { download } from './download'; import { setup } from './setup'; -import { isWindows } from './utils'; /** * Install the Google Cloud SDK. diff --git a/src/setup.ts b/src/setup.ts index cf61345..80548f3 100644 --- a/src/setup.ts +++ b/src/setup.ts @@ -2,10 +2,10 @@ import * as core from '@actions/core'; import * as exec from '@actions/exec'; import { execSync } from 'child_process'; import { resolve } from 'path'; -import { getCloudSDKDirectory, isUbuntu, isWindows } from './utils'; +import { getCloudSDKDirectory, isMacOS, isUbuntu, isWindows } from './utils'; /** - * Setup the Google Cloud SDK. + * Setup the Google Cloud SDK by running the install script. */ export async function setup(): Promise { const installScriptExtension = isWindows() ? 'bat' : 'sh'; @@ -29,9 +29,9 @@ export async function setup(): Promise { if (isWindows()) { // @actions/exec does not exit on windows execSync(`"${installScript}" ${args.join(' ')}`, { stdio: 'inherit' }); - } else if (isUbuntu()) { + } else if (isUbuntu() || isMacOS()) { /* - * Since we extracted the SDK to a procted directory, we have also to run the installer as root, which has + * Since we extracted the SDK to a protected directory, we have also to run the installer as root, which has * side-effects on the user $HOME folder. */ await exec.exec(`sudo ${installScript}`, args); @@ -40,7 +40,8 @@ export async function setup(): Promise { const home = process.env.HOME || ''; await exec.exec(`sudo chown -R ${user} ${home}`); } else { - await exec.exec(installScript, args); + // Should never be reached + core.setFailed(`Unexpected os platform, got: ${process.platform}`); } const binPath = resolve(getCloudSDKDirectory(), 'bin'); diff --git a/src/utils.ts b/src/utils.ts index 49292f6..34438d1 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -4,6 +4,7 @@ import { ExecOptions } from '@actions/exec/lib/interfaces'; import { resolve } from 'path'; import { INSTALL_DIRECTORY, + MACOS_INSTALL_PATH, UBUNTU_INSTALL_PATH, WINDOWS_INSTALL_PATH, } from './constants'; @@ -38,8 +39,7 @@ export function getCloudSDKDirectory(): string { } else if (isUbuntu()) { return UBUNTU_INSTALL_PATH; } else { - const home = process.env.HOME ? process.env.HOME : process.cwd(); - return resolve(home, INSTALL_DIRECTORY); + return MACOS_INSTALL_PATH; } } From 304975faefd24efacefe43a9d8fd71116b2b0ad8 Mon Sep 17 00:00:00 2001 From: Mathieu Bour Date: Mon, 27 Jan 2020 03:19:14 +0100 Subject: [PATCH 10/19] docs: update changelog --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 086053c..ef9d0d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,10 @@ ## Version 1.0.0 - Stable release - **fixed**: inputs are now compared to strings - **fixed**: project guess using the `service-account-key` input -- **changed**: install directory on Ubuntu runners (overrides the already installed one) +- **changed**: new install directories + - `/usr/lib/google-cloud-sdk` on Ubuntu runners (overrides the already installed one) + - `$HOME/opt/google-cloud-sdk` on MacOS runners + - `C:\Program Files\google-cloud-sdk` on Windows runners ## Version 0.1.x - Pre-releases The versions are now deprecated and should not be used. From a44aa0f433f07a3cd4537eebc0acba7550671e3c Mon Sep 17 00:00:00 2001 From: Mathieu Bour Date: Mon, 27 Jan 2020 03:22:05 +0100 Subject: [PATCH 11/19] fix(macos): set macos path to $HOME/opt/... --- .github/workflows/tests.yaml | 2 +- dist/index.js | 4 ++-- src/constants.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 7cf68b5..f52e75a 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -6,7 +6,7 @@ jobs: test: strategy: matrix: - os: [windows-latest, macos-latest] + os: [ubuntu-latest, macos-latest, windows-latest] version: [latest] project: [auto] # os: [ubuntu-latest, macos-latest] diff --git a/dist/index.js b/dist/index.js index 4dabe4d..7f2c2f6 100644 --- a/dist/index.js +++ b/dist/index.js @@ -3904,9 +3904,9 @@ var exec = __webpack_require__(986); // CONCATENATED MODULE: ./src/constants.ts const INSTALL_DIRECTORY = 'google-cloud-sdk'; +const UBUNTU_INSTALL_PATH = `/usr/lib/${INSTALL_DIRECTORY}`; +const MACOS_INSTALL_PATH = `${process.env.HOME}/opt/${INSTALL_DIRECTORY}`; const WINDOWS_INSTALL_PATH = `C:\\Program Files\\${INSTALL_DIRECTORY}`; -const MACOS_INSTALL_PATH = `/usr/lib/${INSTALL_DIRECTORY}`; -const UBUNTU_INSTALL_PATH = `${process.env.HOME}/opt/${INSTALL_DIRECTORY}`; // CONCATENATED MODULE: ./src/utils.ts diff --git a/src/constants.ts b/src/constants.ts index 70c43dc..4b1b8d0 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,4 +1,4 @@ export const INSTALL_DIRECTORY = 'google-cloud-sdk'; +export const UBUNTU_INSTALL_PATH = `/usr/lib/${INSTALL_DIRECTORY}`; +export const MACOS_INSTALL_PATH = `${process.env.HOME}/opt/${INSTALL_DIRECTORY}`; export const WINDOWS_INSTALL_PATH = `C:\\Program Files\\${INSTALL_DIRECTORY}`; -export const MACOS_INSTALL_PATH = `/usr/lib/${INSTALL_DIRECTORY}`; -export const UBUNTU_INSTALL_PATH = `${process.env.HOME}/opt/${INSTALL_DIRECTORY}`; From a7acf345f5fdd28a2fd0cdbb0c3f3a51546cd57f Mon Sep 17 00:00:00 2001 From: Mathieu Bour Date: Mon, 27 Jan 2020 03:24:03 +0100 Subject: [PATCH 12/19] fix(macos): mkdirp the install path --- dist/index.js | 5 +++++ src/download.ts | 2 ++ 2 files changed, 7 insertions(+) diff --git a/dist/index.js b/dist/index.js index 7f2c2f6..2454358 100644 --- a/dist/index.js +++ b/dist/index.js @@ -4035,6 +4035,9 @@ async function authenticate() { } } +// EXTERNAL MODULE: ./node_modules/@actions/io/lib/io.js +var io = __webpack_require__(1); + // EXTERNAL MODULE: ./node_modules/@actions/tool-cache/lib/tool-cache.js var tool_cache = __webpack_require__(533); @@ -4045,6 +4048,7 @@ var tool_cache = __webpack_require__(533); + /** * Download the Google Cloud SDK archive. */ @@ -4065,6 +4069,7 @@ async function download() { } else { // MacOS: simply extract tar.gz file + await Object(io.mkdirP)(MACOS_INSTALL_PATH); await Object(tool_cache.extractTar)(downloadPath, MACOS_INSTALL_PATH); } } diff --git a/src/download.ts b/src/download.ts index 6ec5c48..d46844c 100644 --- a/src/download.ts +++ b/src/download.ts @@ -1,5 +1,6 @@ import * as core from '@actions/core'; import * as exec from '@actions/exec'; +import * as io from '@actions/io'; import * as tc from '@actions/tool-cache'; import { resolve } from 'path'; import { MACOS_INSTALL_PATH, UBUNTU_INSTALL_PATH } from './constants'; @@ -25,6 +26,7 @@ export async function download(): Promise { await exec.exec(`sudo tar -xf ${downloadPath} -C ${parentInstallDir}`); } else { // MacOS: simply extract tar.gz file + await io.mkdirP(MACOS_INSTALL_PATH); await tc.extractTar(downloadPath, MACOS_INSTALL_PATH); } } else { From eb076afaad1f48c23da929454226fd6591678114 Mon Sep 17 00:00:00 2001 From: Mathieu Bour Date: Mon, 27 Jan 2020 03:27:55 +0100 Subject: [PATCH 13/19] fix(macos): change exec command to non-sudo --- CHANGELOG.md | 1 + dist/index.js | 19 ++++++++++++------- src/setup.ts | 16 ++++++++++------ 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef9d0d2..9a72103 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ## Version 1.0.0 - Stable release +- **feat**: added support for Windows - **fixed**: inputs are now compared to strings - **fixed**: project guess using the `service-account-key` input - **changed**: new install directories diff --git a/dist/index.js b/dist/index.js index 2454358..8f3d812 100644 --- a/dist/index.js +++ b/dist/index.js @@ -4104,20 +4104,25 @@ async function setup() { 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 if (isUbuntu() || isMacOS()) { + if (isUbuntu()) { /* - * Since we extracted the SDK to a protected directory, we have also to run the installer as root, which has - * side-effects on the user $HOME folder. + * On Ubuntu, since we extracted the SDK to a protected directory, we have also to run the installer as root, which + * has side-effects on the user $HOME folder. */ await Object(exec.exec)(`sudo ${installScript}`, args); const user = process.env.USER || ''; const home = process.env.HOME || ''; await Object(exec.exec)(`sudo chown -R ${user} ${home}`); } + else if (isMacOS()) { + // On MacOS, we simply have to run the install script + await Object(exec.exec)(`ls -l ${getCloudSDKDirectory()}`); + await Object(exec.exec)(installScript, args); + } + else if (isWindows()) { + // @actions/exec does not exit on windows + Object(external_child_process_.execSync)(`"${installScript}" ${args.join(' ')}`, { stdio: 'inherit' }); + } else { // Should never be reached Object(core.setFailed)(`Unexpected os platform, got: ${process.platform}`); diff --git a/src/setup.ts b/src/setup.ts index 80548f3..02568f5 100644 --- a/src/setup.ts +++ b/src/setup.ts @@ -26,19 +26,23 @@ export async function setup(): Promise { args.push('--additional-components=' + core.getInput('components')); } - if (isWindows()) { - // @actions/exec does not exit on windows - execSync(`"${installScript}" ${args.join(' ')}`, { stdio: 'inherit' }); - } else if (isUbuntu() || isMacOS()) { + if (isUbuntu()) { /* - * Since we extracted the SDK to a protected directory, we have also to run the installer as root, which has - * side-effects on the user $HOME folder. + * On Ubuntu, since we extracted the SDK to a protected directory, we have also to run the installer as root, which + * has side-effects on the user $HOME folder. */ await exec.exec(`sudo ${installScript}`, args); const user = process.env.USER || ''; const home = process.env.HOME || ''; await exec.exec(`sudo chown -R ${user} ${home}`); + } else if (isMacOS()) { + // On MacOS, we simply have to run the install script + await exec.exec(`ls -l ${getCloudSDKDirectory()}`); + await exec.exec(installScript, args); + } else if (isWindows()) { + // @actions/exec does not exit on windows + execSync(`"${installScript}" ${args.join(' ')}`, { stdio: 'inherit' }); } else { // Should never be reached core.setFailed(`Unexpected os platform, got: ${process.platform}`); From 3a369f62419386f93aff9d12ffd25d711179daf4 Mon Sep 17 00:00:00 2001 From: Mathieu Bour Date: Mon, 27 Jan 2020 03:37:05 +0100 Subject: [PATCH 14/19] fix(macos): installation directory --- dist/index.js | 5 +++-- src/constants.ts | 9 +++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index 8f3d812..92dbbf9 100644 --- a/dist/index.js +++ b/dist/index.js @@ -3903,9 +3903,10 @@ var external_path_ = __webpack_require__(622); var exec = __webpack_require__(986); // CONCATENATED MODULE: ./src/constants.ts -const INSTALL_DIRECTORY = 'google-cloud-sdk'; + +const INSTALL_DIRECTORY = 'google-clou' + 'd-sdk'; const UBUNTU_INSTALL_PATH = `/usr/lib/${INSTALL_DIRECTORY}`; -const MACOS_INSTALL_PATH = `${process.env.HOME}/opt/${INSTALL_DIRECTORY}`; +const MACOS_INSTALL_PATH = Object(external_path_.resolve)(process.env.HOME ? process.env.HOME : process.cwd(), INSTALL_DIRECTORY); const WINDOWS_INSTALL_PATH = `C:\\Program Files\\${INSTALL_DIRECTORY}`; // CONCATENATED MODULE: ./src/utils.ts diff --git a/src/constants.ts b/src/constants.ts index 4b1b8d0..488c917 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,4 +1,9 @@ -export const INSTALL_DIRECTORY = 'google-cloud-sdk'; +import { resolve } from 'path'; + +export const INSTALL_DIRECTORY = 'google-clou' + 'd-sdk'; export const UBUNTU_INSTALL_PATH = `/usr/lib/${INSTALL_DIRECTORY}`; -export const MACOS_INSTALL_PATH = `${process.env.HOME}/opt/${INSTALL_DIRECTORY}`; +export const MACOS_INSTALL_PATH = resolve( + process.env.HOME ? process.env.HOME : process.cwd(), + INSTALL_DIRECTORY, +); export const WINDOWS_INSTALL_PATH = `C:\\Program Files\\${INSTALL_DIRECTORY}`; From 8962789d05229642ab2fbaf329debcdb1f39495f Mon Sep 17 00:00:00 2001 From: Mathieu Bour Date: Mon, 27 Jan 2020 03:37:54 +0100 Subject: [PATCH 15/19] ci(actions): run only on macos during tests --- .github/workflows/tests.yaml | 3 ++- dist/index.js | 16 +++++----------- src/constants.ts | 4 ++-- src/download.ts | 7 ++----- src/setup.ts | 1 - 5 files changed, 11 insertions(+), 20 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index f52e75a..0202f5f 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -6,7 +6,8 @@ jobs: test: strategy: matrix: - os: [ubuntu-latest, macos-latest, windows-latest] + #os: [ubuntu-latest, macos-latest, windows-latest] + os: [macos-latest] version: [latest] project: [auto] # os: [ubuntu-latest, macos-latest] diff --git a/dist/index.js b/dist/index.js index 92dbbf9..a0b549b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -3903,10 +3903,11 @@ var external_path_ = __webpack_require__(622); var exec = __webpack_require__(986); // CONCATENATED MODULE: ./src/constants.ts +var _a; -const INSTALL_DIRECTORY = 'google-clou' + 'd-sdk'; +const INSTALL_DIRECTORY = 'google-cloud-sdk'; const UBUNTU_INSTALL_PATH = `/usr/lib/${INSTALL_DIRECTORY}`; -const MACOS_INSTALL_PATH = Object(external_path_.resolve)(process.env.HOME ? process.env.HOME : process.cwd(), INSTALL_DIRECTORY); +const MACOS_INSTALL_PATH = Object(external_path_.resolve)((_a = process.env.HOME, (_a !== null && _a !== void 0 ? _a : process.cwd())), INSTALL_DIRECTORY); const WINDOWS_INSTALL_PATH = `C:\\Program Files\\${INSTALL_DIRECTORY}`; // CONCATENATED MODULE: ./src/utils.ts @@ -4036,9 +4037,6 @@ async function authenticate() { } } -// EXTERNAL MODULE: ./node_modules/@actions/io/lib/io.js -var io = __webpack_require__(1); - // EXTERNAL MODULE: ./node_modules/@actions/tool-cache/lib/tool-cache.js var tool_cache = __webpack_require__(533); @@ -4049,7 +4047,6 @@ var tool_cache = __webpack_require__(533); - /** * Download the Google Cloud SDK archive. */ @@ -4064,14 +4061,12 @@ async function download() { else if (downloadLink.endsWith('.tar.gz')) { if (isUbuntu()) { // Ubuntu: Remove the existing installation of Google Cloud SDK - const parentInstallDir = Object(external_path_.resolve)(UBUNTU_INSTALL_PATH, '..'); await Object(exec.exec)(`sudo rm -rf ${UBUNTU_INSTALL_PATH}`); - await Object(exec.exec)(`sudo tar -xf ${downloadPath} -C ${parentInstallDir}`); + await Object(exec.exec)(`sudo tar -xf ${downloadPath} -C ${extractionPath}`); } else { // MacOS: simply extract tar.gz file - await Object(io.mkdirP)(MACOS_INSTALL_PATH); - await Object(tool_cache.extractTar)(downloadPath, MACOS_INSTALL_PATH); + await Object(tool_cache.extractTar)(downloadPath, extractionPath); } } else { @@ -4117,7 +4112,6 @@ async function setup() { } else if (isMacOS()) { // On MacOS, we simply have to run the install script - await Object(exec.exec)(`ls -l ${getCloudSDKDirectory()}`); await Object(exec.exec)(installScript, args); } else if (isWindows()) { diff --git a/src/constants.ts b/src/constants.ts index 488c917..a306de2 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,9 +1,9 @@ import { resolve } from 'path'; -export const INSTALL_DIRECTORY = 'google-clou' + 'd-sdk'; +export const INSTALL_DIRECTORY = 'google-cloud-sdk'; export const UBUNTU_INSTALL_PATH = `/usr/lib/${INSTALL_DIRECTORY}`; export const MACOS_INSTALL_PATH = resolve( - process.env.HOME ? process.env.HOME : process.cwd(), + process.env.HOME ?? process.cwd(), INSTALL_DIRECTORY, ); export const WINDOWS_INSTALL_PATH = `C:\\Program Files\\${INSTALL_DIRECTORY}`; diff --git a/src/download.ts b/src/download.ts index d46844c..dcea399 100644 --- a/src/download.ts +++ b/src/download.ts @@ -20,14 +20,11 @@ export async function download(): Promise { } else if (downloadLink.endsWith('.tar.gz')) { if (isUbuntu()) { // Ubuntu: Remove the existing installation of Google Cloud SDK - const parentInstallDir = resolve(UBUNTU_INSTALL_PATH, '..'); - await exec.exec(`sudo rm -rf ${UBUNTU_INSTALL_PATH}`); - await exec.exec(`sudo tar -xf ${downloadPath} -C ${parentInstallDir}`); + await exec.exec(`sudo tar -xf ${downloadPath} -C ${extractionPath}`); } else { // MacOS: simply extract tar.gz file - await io.mkdirP(MACOS_INSTALL_PATH); - await tc.extractTar(downloadPath, MACOS_INSTALL_PATH); + await tc.extractTar(downloadPath, extractionPath); } } else { // Should never be reached diff --git a/src/setup.ts b/src/setup.ts index 02568f5..4fc4fb9 100644 --- a/src/setup.ts +++ b/src/setup.ts @@ -38,7 +38,6 @@ export async function setup(): Promise { await exec.exec(`sudo chown -R ${user} ${home}`); } else if (isMacOS()) { // On MacOS, we simply have to run the install script - await exec.exec(`ls -l ${getCloudSDKDirectory()}`); await exec.exec(installScript, args); } else if (isWindows()) { // @actions/exec does not exit on windows From 4249eabde788f2a9b2ce14dcdda7c33aa50221ff Mon Sep 17 00:00:00 2001 From: Mathieu Bour Date: Mon, 27 Jan 2020 03:50:36 +0100 Subject: [PATCH 16/19] ci(actions): re-instantiate all matrix tests --- .github/workflows/tests.yaml | 54 +++++++++++++++++------------------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 0202f5f..4d259de 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -6,35 +6,31 @@ jobs: test: strategy: matrix: - #os: [ubuntu-latest, macos-latest, windows-latest] - os: [macos-latest] - version: [latest] - project: [auto] -# os: [ubuntu-latest, macos-latest] -# version: [latest, 245.0.0] -# project: [auto, matrix-education] -# exclude: -# - os: ubuntu-latest -# version: 245.0.0 -# project: matrix-education -# - os: macos-latest -# version: latest -# project: matrix-education -# - os: macos-latest -# version: 245.0.0 -# project: auto -# - os: macos-latest -# version: 245.0.0 -# project: matrix-education -# - os: windows-latest -# version: latest -# project: matrix-education -# - os: windows-latest -# version: 245.0.0 -# project: auto -# - os: windows-latest -# version: 245.0.0 -# project: matrix-education + os: [ubuntu-latest, macos-latest, windows-latest] + version: [latest, 245.0.0] + project: [auto, matrix-education] + exclude: + - os: ubuntu-latest + version: 245.0.0 + project: matrix-education + - os: macos-latest + version: latest + project: matrix-education + - os: macos-latest + version: 245.0.0 + project: auto + - os: macos-latest + version: 245.0.0 + project: matrix-education + - os: windows-latest + version: latest + project: matrix-education + - os: windows-latest + version: 245.0.0 + project: auto + - os: windows-latest + version: 245.0.0 + project: matrix-education fail-fast: false runs-on: ${{ matrix.os }} steps: From 7f07c011530c97552b8a09ee74b91bdb08bd1449 Mon Sep 17 00:00:00 2001 From: Mathieu Bour Date: Mon, 27 Jan 2020 03:58:21 +0100 Subject: [PATCH 17/19] feat: setup default project even if there is no key provided --- README.md | 10 +++------- dist/index.js | 2 +- src/authenticate.ts | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 1f295a0..3975eb3 100644 --- a/README.md +++ b/README.md @@ -31,20 +31,16 @@ guessing and automatic Docker Configuration. ## Usage ### Supported operating systems -This action currently supports only Mac-OS and Ubuntu based systems. -Indeed, despite our efforts, we have not been able to launch the -installation of the Google Cloud SDK on Windows. - -The supported operating systems matrix is the following: +This action currently supports Ubuntu, Mac-OS and Windows based systems. The supported operating systems matrix is +the following: | Operating system | Status | |------------------|-------| | `ubuntu-latest` | ![3.1] | | `macos-latest` | ![3.1] | -| `windows-latest` | ![3.2] | +| `windows-latest` | ![3.1] | [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 | diff --git a/dist/index.js b/dist/index.js index a0b549b..6f13771 100644 --- a/dist/index.js +++ b/dist/index.js @@ -4027,7 +4027,7 @@ async function authenticate() { 'cannot be configured. Your service account key might malformed.'); } } - else if (Object(core.getInput)('project') !== 'none') { + else if (!['', 'none', 'auto'].includes(Object(core.getInput)('project'))) { // Project was passed as input await gcloud(['config', 'set', 'project', Object(core.getInput)('project')]); } diff --git a/src/authenticate.ts b/src/authenticate.ts index e31b469..8b3fc91 100644 --- a/src/authenticate.ts +++ b/src/authenticate.ts @@ -53,7 +53,7 @@ export async function authenticate(): Promise { 'cannot be configured. Your service account key might malformed.', ); } - } else if (core.getInput('project') !== 'none') { + } else if (!['', 'none', 'auto'].includes(core.getInput('project'))) { // Project was passed as input await gcloud(['config', 'set', 'project', core.getInput('project')]); } From d0b9a9761fefd3bdeb1926ea4d1ae960ae034a17 Mon Sep 17 00:00:00 2001 From: Mathieu Bour Date: Mon, 27 Jan 2020 04:03:02 +0100 Subject: [PATCH 18/19] docs: update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3975eb3..8895971 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# @mathrix-education/setup-gcloud +# mathrix-education/setup-gcloud Install the Google Cloud SDK in your GitHub Actions workflow. **This action is not supported by Google Cloud.** From db19ff014d7e016f2d169dac0c59b83acb0525dc Mon Sep 17 00:00:00 2001 From: Mathieu Bour Date: Mon, 27 Jan 2020 04:09:44 +0100 Subject: [PATCH 19/19] docs: add badges --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 8895971..c00da21 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,11 @@ # mathrix-education/setup-gcloud + +![Workflow status][workflow] +![Latest release][latest-release] + +[workflow]: https://img.shields.io/github/workflow/status/mathrix-education/setup-gcloud/Tests?style=flat-square +[latest-release]: https://img.shields.io/github/v/release/mathrix-education/setup-gcloud?label=latest%20release&style=flat-square + Install the Google Cloud SDK in your GitHub Actions workflow. **This action is not supported by Google Cloud.**