ci: log commands output when deploying angular.io to Firebase (#39596)

In #39470, the `deploy-to-firebase.sh` script (used to deploy AIO to
Firebase when building an upstream branch), was replaced by an
equivalent JS script. In this new `deploy-to-firebase.js` script, we
were overly aggressive with suppressing command output, which made it
hard to investigate failures ([example failing CI job][1]).

This commit updates the `deploy-to-firebase.js` script to capture
command output as usual in the CI job logs. This makes the output
similar to the one generated by the old [deploy-to-firebase.sh][2]
script ([example CI logs][3]).

One concern with capturing command output is having the value of a
secret environment variables leaked in the logs. This is not the case
here, since:
1. The secret env vars are not printed from the commands that use them.
2. CircleCI will [mask the values of secret env vars][4] in the output.

As an extra precaution (although not strictly necessary), we run `yarn`
with the `--silent` option, which avoid echoing the executed yarn
commands.

[1]: https://circleci.com/gh/angular/angular/849310
[2]: https://github.com/angular/angular/blob/3b0b7d22109c79b4dceb/aio/scripts/deploy-to-firebase.sh
[3]: https://circleci.com/gh/angular/angular/848109
[4]: https://circleci.com/docs/2.0/env-vars/#secrets-masking

PR Close #39596
This commit is contained in:
George Kalpakas 2020-11-07 15:11:47 +02:00 committed by Misko Hevery
parent b9bf03af33
commit 0edf6fc7f6
1 changed files with 7 additions and 7 deletions

View File

@ -4,7 +4,7 @@
// //
'use strict'; 'use strict';
const {cd, cp, exec: _exec, set} = require('shelljs'); const {cd, cp, exec, set} = require('shelljs');
set('-e'); set('-e');
@ -187,13 +187,8 @@ function deploy(
yarn(`test-pwa-score "${deployedUrl}" "${minPwaScore}"`); yarn(`test-pwa-score "${deployedUrl}" "${minPwaScore}"`);
} }
function exec(cmd, opts) {
// Using `silent: true` to ensure no secret env variables are printed.
return _exec(cmd, {silent: true, ...opts}).trim();
}
function getRemoteRefs(refOrPattern, remote = NG_REMOTE_URL) { function getRemoteRefs(refOrPattern, remote = NG_REMOTE_URL) {
return exec(`git ls-remote ${remote} ${refOrPattern}`).split('\n'); return exec(`git ls-remote ${remote} ${refOrPattern}`, {silent: true}).trim().split('\n');
} }
function getLatestCommit(branchName, remote = undefined) { function getLatestCommit(branchName, remote = undefined) {
@ -206,5 +201,10 @@ function skipDeployment(reason) {
function yarn(cmd) { function yarn(cmd) {
// Using `--silent` to ensure no secret env variables are printed. // Using `--silent` to ensure no secret env variables are printed.
//
// NOTE:
// This is not strictly necessary, since CircleCI will mask secret environment variables in the
// output (see https://circleci.com/docs/2.0/env-vars/#secrets-masking), but is an extra
// precaution.
return exec(`yarn --silent ${cmd}`); return exec(`yarn --silent ${cmd}`);
} }