build(docs-infra): switch `deploy-to-firebase.sh` script to JS (#39470)
This commit switches the `deploy-to-firebase.sh` script, that we use for deploying angular.io to production, from Bash to JavaScript. This makes the script easier to maintain. For the same reasons, it also switches the `deploy-to-firebase.test.sh` script, that we use for testing the `deploy-to-firebase` script, from Bash to JavaScript (using jasmine as the test runner). Finally, this commit also updates ShellJS to the latest version to get better error messages (including the actual error) when `exec()` fails. NOTE: Before switching the test script to JS, I verified that the new `deploy-to-firebase.js` script passed the tests with the old `deploy-to-firebase.test.sh` script. PR Close #39470
This commit is contained in:
parent
8317042483
commit
5143d52d2b
|
@ -6,4 +6,4 @@ TODO (gkalpak): Add docs. Mention:
|
|||
Relevant files: `aio/aio-builds-setup/scripts/test.sh`
|
||||
- Deploying from CI.
|
||||
Relevant files: `.circleci/config.yml`, `scripts/ci/deploy.sh`, `aio/scripts/build-artifacts.sh`,
|
||||
`aio/scripts/deploy-to-firebase.sh`
|
||||
`aio/scripts/deploy-to-firebase.js`
|
||||
|
|
|
@ -49,7 +49,7 @@
|
|||
"example-use-local": "node tools/ng-packages-installer overwrite ./tools/examples/shared --debug --force",
|
||||
"example-use-npm": "node tools/ng-packages-installer restore ./tools/examples/shared",
|
||||
"example-check-local": "node tools/ng-packages-installer check ./tools/examples/shared",
|
||||
"deploy-production": "scripts/deploy-to-firebase.sh",
|
||||
"deploy-production": "node scripts/deploy-to-firebase",
|
||||
"check-env": "yarn ~~check-env",
|
||||
"postcheck-env": "yarn aio-check-local",
|
||||
"payload-size": "scripts/payload.sh",
|
||||
|
@ -62,7 +62,7 @@
|
|||
"redirects-test": "node tests/deployment/unit/test",
|
||||
"firebase-utils-test": "node tools/firebase-test-utils/test",
|
||||
"tools-lint": "tslint --config \"tools/tslint.json\" --project \"tools/firebase-test-utils\"",
|
||||
"tools-test": "./scripts/deploy-to-firebase.test.sh && yarn docs-test && yarn boilerplate:test && jasmine tools/ng-packages-installer/index.spec.js && yarn firebase-utils-test",
|
||||
"tools-test": "yarn docs-test && yarn boilerplate:test && jasmine tools/ng-packages-installer/index.spec.js && jasmine scripts/deploy-to-firebase.spec.js && yarn firebase-utils-test",
|
||||
"preserve-and-sync": "yarn docs",
|
||||
"serve-and-sync": "run-p \"docs-watch --watch-only\" \"start {@}\" --",
|
||||
"boilerplate:add": "node ./tools/examples/example-boilerplate add",
|
||||
|
@ -161,7 +161,7 @@
|
|||
"remark-html": "^8.0.0",
|
||||
"rimraf": "^2.6.1",
|
||||
"semver": "^5.3.0",
|
||||
"shelljs": "^0.7.7",
|
||||
"shelljs": "^0.8.4",
|
||||
"tree-kill": "^1.1.0",
|
||||
"ts-node": "^8.4.1",
|
||||
"tslint": "~6.1.0",
|
||||
|
|
|
@ -0,0 +1,165 @@
|
|||
#!/bin/env node
|
||||
//
|
||||
// WARNING: `CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN` should NOT be printed.
|
||||
//
|
||||
'use strict';
|
||||
|
||||
const {cd, cp, exec: _exec, set} = require('shelljs');
|
||||
|
||||
set('-e');
|
||||
|
||||
|
||||
// Arguments and environment variables
|
||||
const args = process.argv.slice(2);
|
||||
const dryRun = args[0] === '--dry-run';
|
||||
|
||||
const {
|
||||
CI_AIO_MIN_PWA_SCORE,
|
||||
CI_BRANCH,
|
||||
CI_COMMIT,
|
||||
CI_PULL_REQUEST,
|
||||
CI_REPO_NAME,
|
||||
CI_REPO_OWNER,
|
||||
CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN,
|
||||
CI_STABLE_BRANCH,
|
||||
} = process.env;
|
||||
|
||||
// Do not deploy if we are running in a fork.
|
||||
if (`${CI_REPO_OWNER}/${CI_REPO_NAME}` !== 'angular/angular') {
|
||||
console.log('Skipping deploy because this is not angular/angular.');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
// Do not deploy if this is a PR. PRs are deployed in the `aio_preview` CircleCI job.
|
||||
if (CI_PULL_REQUEST !== 'false') {
|
||||
console.log('Skipping deploy because this is a PR build.');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
// Do not deploy if the current commit is not the latest on its branch.
|
||||
const latestCommit = exec(`git ls-remote origin ${CI_BRANCH}`).slice(0, 40);
|
||||
if (CI_COMMIT !== latestCommit) {
|
||||
console.log(`Skipping deploy because ${CI_COMMIT} is not the latest commit (${latestCommit}).`);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
// The deployment mode is computed based on the branch we are building.
|
||||
const currentBranchMajorVersion = computeMajorVersion(CI_BRANCH);
|
||||
// Special-case v9, because it is piloting the Firebase hosting "multisites" setup.
|
||||
// See https://angular-team.atlassian.net/browse/DEV-125 for more info.
|
||||
const isV9 = currentBranchMajorVersion === 9;
|
||||
const deployInfoPerTarget = {
|
||||
next: {
|
||||
deployEnv: 'next',
|
||||
projectId: 'aio-staging',
|
||||
siteId: 'aio-staging',
|
||||
deployedUrl: 'https://next.angular.io/',
|
||||
},
|
||||
stable: {
|
||||
deployEnv: 'stable',
|
||||
projectId: 'angular-io',
|
||||
siteId: 'angular-io',
|
||||
deployedUrl: 'https://angular.io/',
|
||||
},
|
||||
archive: {
|
||||
deployEnv: 'archive',
|
||||
projectId: isV9 ? 'aio-staging' : `v${currentBranchMajorVersion}-angular-io`,
|
||||
siteId: isV9 ? 'v9-angular-io' : `v${currentBranchMajorVersion}-angular-io`,
|
||||
deployedUrl: `https://v${currentBranchMajorVersion}.angular.io/`,
|
||||
},
|
||||
};
|
||||
let deployInfo = null;
|
||||
|
||||
if (CI_BRANCH === 'master') {
|
||||
deployInfo = deployInfoPerTarget.next;
|
||||
} else if (CI_BRANCH === CI_STABLE_BRANCH) {
|
||||
deployInfo = deployInfoPerTarget.stable;
|
||||
} else {
|
||||
const stableBranchMajorVersion = computeMajorVersion(CI_STABLE_BRANCH);
|
||||
|
||||
// Do not deploy if the major version is not less than the stable branch major version.
|
||||
if (currentBranchMajorVersion >= stableBranchMajorVersion) {
|
||||
console.log(
|
||||
`Skipping deploy of branch "${CI_BRANCH}" to Firebase.\n` +
|
||||
'We only deploy archive branches with the major version less than the stable branch: ' +
|
||||
`"${CI_STABLE_BRANCH}"`);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
// Find the branch that has highest minor version for the given `currentBranchMajorVersion`.
|
||||
const mostRecentMinorVersion =
|
||||
// List the branches that start with the major version.
|
||||
exec(`git ls-remote origin refs/heads/${currentBranchMajorVersion}.*.x`).split('\n')
|
||||
// Extract the version number.
|
||||
.map(line => line.split('/')[2])
|
||||
// Sort by the minor version.
|
||||
.sort((a, b) => a.split('.')[1] - b.split('.')[1])
|
||||
// Get the highest version.
|
||||
.pop();
|
||||
|
||||
// Do not deploy as it is not the latest branch for the given major version.
|
||||
if (CI_BRANCH !== mostRecentMinorVersion) {
|
||||
console.log(
|
||||
`Skipping deploy of branch "${CI_BRANCH}" to Firebase.\n` +
|
||||
`There is a more recent branch with the same major version: "${mostRecentMinorVersion}"`);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
deployInfo = deployInfoPerTarget.archive;
|
||||
}
|
||||
|
||||
const {deployEnv, projectId, siteId, deployedUrl} = deployInfo;
|
||||
console.log(
|
||||
`Git branch : ${CI_BRANCH}\n` +
|
||||
`Build/deploy mode : ${deployEnv}\n` +
|
||||
`Firebase project : ${projectId}\n` +
|
||||
`Firebase site : ${siteId}\n` +
|
||||
`Deployment URL : ${deployedUrl}\n`);
|
||||
|
||||
if (dryRun) {
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
// Deploy
|
||||
cd(`${__dirname}/..`);
|
||||
|
||||
console.log('\n\n\n==== Build the AIO app. ====\n');
|
||||
yarn(`build --configuration=${deployEnv} --progress=false`);
|
||||
|
||||
console.log('\n\n\n==== Add any mode-specific files into the AIO distribution. ====\n');
|
||||
cp('-rf', `src/extra-files/${deployEnv}/.`, 'dist/');
|
||||
|
||||
|
||||
console.log('\n\n\n==== Update opensearch descriptor for AIO with `deployedUrl`. ====\n');
|
||||
yarn(`set-opensearch-url ${deployedUrl.replace(/[^/]$/, '$&/')}`); // The URL must end with `/`.
|
||||
|
||||
console.log('\n\n\n==== Check payload size and upload the numbers to Firebase DB. ====\n');
|
||||
yarn('payload-size');
|
||||
|
||||
console.log('\n\n\n==== Deploy AIO to Firebase hosting. ====\n');
|
||||
yarn(`firebase use "${projectId}" --token "${CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN}"`);
|
||||
yarn(
|
||||
`firebase target:apply hosting aio "${siteId}" --token ` +
|
||||
`"${CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN}"`);
|
||||
yarn(
|
||||
`firebase deploy --only hosting:aio --message "Commit: ${CI_COMMIT}" --non-interactive ` +
|
||||
`--token ${CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN}`);
|
||||
|
||||
console.log('\n\n\n==== Run PWA-score tests. ====\n');
|
||||
yarn(`test-pwa-score "${deployedUrl}" "${CI_AIO_MIN_PWA_SCORE}"`);
|
||||
|
||||
|
||||
// Helpers
|
||||
function computeMajorVersion(branchName) {
|
||||
return +branchName.split('.', 1)[0];
|
||||
}
|
||||
|
||||
function exec(cmd, opts) {
|
||||
// Using `silent: true` to ensure no secret env variables are printed.
|
||||
return _exec(cmd, {silent: true, ...opts}).trim();
|
||||
}
|
||||
|
||||
function yarn(cmd) {
|
||||
// Using `--silent` to ensure no secret env variables are printed.
|
||||
return exec(`yarn --silent ${cmd}`);
|
||||
}
|
|
@ -1,132 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# WARNING: CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN should NOT be printed.
|
||||
set +x -eu -o pipefail
|
||||
|
||||
# Do not deploy if we are running in a fork.
|
||||
if [[ "$CI_REPO_OWNER/$CI_REPO_NAME" != "angular/angular" ]]; then
|
||||
echo "Skipping deploy because this is not angular/angular."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Do not deploy if this is a PR. PRs are deployed in the `aio_preview` CircleCI job.
|
||||
if [[ $CI_PULL_REQUEST != "false" ]]; then
|
||||
echo "Skipping deploy because this is a PR build."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Do not deploy if the current commit is not the latest on its branch.
|
||||
readonly latestCommit=$(git ls-remote origin $CI_BRANCH | cut -c1-40)
|
||||
if [[ $CI_COMMIT != $latestCommit ]]; then
|
||||
echo "Skipping deploy because $CI_COMMIT is not the latest commit ($latestCommit)."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# The deployment mode is computed based on the branch we are building
|
||||
if [[ $CI_BRANCH == master ]]; then
|
||||
readonly deployEnv=next
|
||||
elif [[ $CI_BRANCH == $CI_STABLE_BRANCH ]]; then
|
||||
readonly deployEnv=stable
|
||||
else
|
||||
# Extract the major versions from the branches, e.g. the 4 from 4.3.x
|
||||
readonly majorVersion=${CI_BRANCH%%.*}
|
||||
readonly majorVersionStable=${CI_STABLE_BRANCH%%.*}
|
||||
|
||||
# Do not deploy if the major version is not less than the stable branch major version
|
||||
if (( $majorVersion >= $majorVersionStable )); then
|
||||
echo "Skipping deploy of branch \"$CI_BRANCH\" to firebase."
|
||||
echo "We only deploy archive branches with the major version less than the stable branch: \"$CI_STABLE_BRANCH\""
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Find the branch that has highest minor version for the given `$majorVersion`
|
||||
readonly mostRecentMinorVersion=$(
|
||||
# List the branches that start with the major version
|
||||
git ls-remote origin refs/heads/${majorVersion}.*.x |
|
||||
# Extract the version number
|
||||
awk -F'/' '{print $3}' |
|
||||
# Sort by the minor version
|
||||
sort -t. -k 2,2n |
|
||||
# Get the highest version
|
||||
tail -n1
|
||||
)
|
||||
|
||||
# Do not deploy as it is not the latest branch for the given major version
|
||||
if [[ $CI_BRANCH != $mostRecentMinorVersion ]]; then
|
||||
echo "Skipping deploy of branch \"$CI_BRANCH\" to firebase."
|
||||
echo "There is a more recent branch with the same major version: \"$mostRecentMinorVersion\""
|
||||
exit 0
|
||||
fi
|
||||
|
||||
readonly deployEnv=archive
|
||||
fi
|
||||
|
||||
case $deployEnv in
|
||||
next)
|
||||
readonly projectId=aio-staging
|
||||
readonly siteId=$projectId
|
||||
readonly deployedUrl=https://next.angular.io/
|
||||
readonly firebaseToken=$CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN
|
||||
;;
|
||||
stable)
|
||||
readonly projectId=angular-io
|
||||
readonly siteId=$projectId
|
||||
readonly deployedUrl=https://angular.io/
|
||||
readonly firebaseToken=$CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN
|
||||
;;
|
||||
archive)
|
||||
# Special case v9-angular-io because its piloting the firebase hosting "multisites" setup
|
||||
# See https://angular-team.atlassian.net/browse/DEV-125 for more info.
|
||||
if [[ "$majorVersion" == "9" ]]; then
|
||||
readonly projectId=aio-staging
|
||||
readonly siteId=v9-angular-io
|
||||
else
|
||||
readonly projectId=v${majorVersion}-angular-io
|
||||
readonly siteId=$projectId
|
||||
fi
|
||||
|
||||
readonly deployedUrl=https://v${majorVersion}.angular.io/
|
||||
readonly firebaseToken=$CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "Git branch : $CI_BRANCH"
|
||||
echo "Build/deploy mode : $deployEnv"
|
||||
echo "Firebase project : $projectId"
|
||||
echo "Firebase site : $siteId"
|
||||
echo "Deployment URL : $deployedUrl"
|
||||
|
||||
if [[ ${1:-} == "--dry-run" ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Deploy
|
||||
(
|
||||
cd "`dirname $0`/.."
|
||||
|
||||
echo "\n\n\n==== Build the aio app ====\n"
|
||||
yarn build --configuration=$deployEnv --progress=false
|
||||
|
||||
|
||||
echo "\n\n\n==== Add any mode-specific files into the aio distribution ====\n"
|
||||
cp -rf src/extra-files/$deployEnv/. dist/
|
||||
|
||||
|
||||
echo "\n\n\n==== Update opensearch descriptor for aio with the deployedUrl ====\n"
|
||||
# deployedUrl must end with /
|
||||
yarn set-opensearch-url $deployedUrl
|
||||
|
||||
echo "\n\n\n==== Check payload size and upload the numbers to firebase db ====\n"
|
||||
yarn payload-size
|
||||
|
||||
|
||||
echo "\n\n\n==== Deploy aio to firebase hosting ====\n"
|
||||
|
||||
yarn firebase use "${projectId}" --token "$firebaseToken"
|
||||
yarn firebase target:apply hosting aio $siteId --token "$firebaseToken"
|
||||
yarn firebase deploy --only hosting:aio --message "Commit: $CI_COMMIT" --non-interactive --token "$firebaseToken"
|
||||
|
||||
|
||||
echo "\n\n\n==== Run PWA-score tests ====\n"
|
||||
yarn test-pwa-score "$deployedUrl" "$CI_AIO_MIN_PWA_SCORE"
|
||||
)
|
|
@ -0,0 +1,187 @@
|
|||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
|
||||
const {execSync} = require('child_process');
|
||||
|
||||
|
||||
describe('deploy-to-firebase:', () => {
|
||||
const deployToFirebaseCmd = `"${process.execPath}" "${__dirname}/deploy-to-firebase" --dry-run`;
|
||||
|
||||
// Helpers
|
||||
const deployToFirebaseDryRun =
|
||||
env => execSync(deployToFirebaseCmd, {encoding: 'utf8', env}).toString().trim();
|
||||
const getLatestCommitForBranch =
|
||||
branch => execSync(`git ls-remote origin ${branch}`).slice(0, 40);
|
||||
|
||||
it('master - skip deploy - not angular', () => {
|
||||
expect(deployToFirebaseDryRun({
|
||||
CI_REPO_OWNER: 'angular',
|
||||
CI_REPO_NAME: 'notangular',
|
||||
})).toBe('Skipping deploy because this is not angular/angular.');
|
||||
});
|
||||
|
||||
it('master - skip deploy - angular fork', () => {
|
||||
expect(deployToFirebaseDryRun({
|
||||
CI_REPO_OWNER: 'notangular',
|
||||
CI_REPO_NAME: 'angular',
|
||||
})).toBe('Skipping deploy because this is not angular/angular.');
|
||||
});
|
||||
|
||||
it('master - skip deploy - pull request', () => {
|
||||
expect(deployToFirebaseDryRun({
|
||||
CI_REPO_OWNER: 'angular',
|
||||
CI_REPO_NAME: 'angular',
|
||||
CI_PULL_REQUEST: 'true',
|
||||
})).toBe('Skipping deploy because this is a PR build.');
|
||||
});
|
||||
|
||||
it('master - deploy success', () => {
|
||||
expect(deployToFirebaseDryRun({
|
||||
CI_REPO_OWNER: 'angular',
|
||||
CI_REPO_NAME: 'angular',
|
||||
CI_PULL_REQUEST: 'false',
|
||||
CI_BRANCH: 'master',
|
||||
CI_COMMIT: getLatestCommitForBranch('master'),
|
||||
CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN: 'XXXXX',
|
||||
})).toBe(
|
||||
'Git branch : master\n' +
|
||||
'Build/deploy mode : next\n' +
|
||||
'Firebase project : aio-staging\n' +
|
||||
'Firebase site : aio-staging\n' +
|
||||
'Deployment URL : https://next.angular.io/');
|
||||
});
|
||||
|
||||
it('master - skip deploy - commit not HEAD', () => {
|
||||
expect(deployToFirebaseDryRun({
|
||||
CI_REPO_OWNER: 'angular',
|
||||
CI_REPO_NAME: 'angular',
|
||||
CI_PULL_REQUEST: 'false',
|
||||
CI_BRANCH: 'master',
|
||||
CI_COMMIT: 'DUMMY_TEST_COMMIT',
|
||||
})).toBe(
|
||||
'Skipping deploy because DUMMY_TEST_COMMIT is not the latest commit ' +
|
||||
`(${getLatestCommitForBranch('master')}).`);
|
||||
});
|
||||
|
||||
it('stable - deploy success', () => {
|
||||
expect(deployToFirebaseDryRun({
|
||||
CI_REPO_OWNER: 'angular',
|
||||
CI_REPO_NAME: 'angular',
|
||||
CI_PULL_REQUEST: 'false',
|
||||
CI_BRANCH: '4.3.x',
|
||||
CI_STABLE_BRANCH: '4.3.x',
|
||||
CI_COMMIT: getLatestCommitForBranch('4.3.x'),
|
||||
CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN: 'XXXXX',
|
||||
})).toBe(
|
||||
'Git branch : 4.3.x\n' +
|
||||
'Build/deploy mode : stable\n' +
|
||||
'Firebase project : angular-io\n' +
|
||||
'Firebase site : angular-io\n' +
|
||||
'Deployment URL : https://angular.io/');
|
||||
});
|
||||
|
||||
it('stable - skip deploy - commit not HEAD', () => {
|
||||
expect(deployToFirebaseDryRun({
|
||||
CI_REPO_OWNER: 'angular',
|
||||
CI_REPO_NAME: 'angular',
|
||||
CI_PULL_REQUEST: 'false',
|
||||
CI_BRANCH: '4.3.x',
|
||||
CI_STABLE_BRANCH: '4.3.x',
|
||||
CI_COMMIT: 'DUMMY_TEST_COMMIT',
|
||||
})).toBe(
|
||||
'Skipping deploy because DUMMY_TEST_COMMIT is not the latest commit ' +
|
||||
`(${getLatestCommitForBranch('4.3.x')}).`);
|
||||
});
|
||||
|
||||
it('archive - deploy success', () => {
|
||||
expect(deployToFirebaseDryRun({
|
||||
CI_REPO_OWNER: 'angular',
|
||||
CI_REPO_NAME: 'angular',
|
||||
CI_PULL_REQUEST: 'false',
|
||||
CI_BRANCH: '2.4.x',
|
||||
CI_STABLE_BRANCH: '4.3.x',
|
||||
CI_COMMIT: getLatestCommitForBranch('2.4.x'),
|
||||
CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN: 'XXXXX',
|
||||
})).toBe(
|
||||
'Git branch : 2.4.x\n' +
|
||||
'Build/deploy mode : archive\n' +
|
||||
'Firebase project : v2-angular-io\n' +
|
||||
'Firebase site : v2-angular-io\n' +
|
||||
'Deployment URL : https://v2.angular.io/');
|
||||
});
|
||||
|
||||
it('archive - v9-angular-io multisite special case - deploy success', () => {
|
||||
expect(deployToFirebaseDryRun({
|
||||
CI_REPO_OWNER: 'angular',
|
||||
CI_REPO_NAME: 'angular',
|
||||
CI_PULL_REQUEST: 'false',
|
||||
CI_BRANCH: '9.1.x',
|
||||
CI_STABLE_BRANCH: '10.0.x',
|
||||
CI_COMMIT: getLatestCommitForBranch('9.1.x'),
|
||||
CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN: 'XXXXX',
|
||||
})).toBe(
|
||||
'Git branch : 9.1.x\n' +
|
||||
'Build/deploy mode : archive\n' +
|
||||
'Firebase project : aio-staging\n' +
|
||||
'Firebase site : v9-angular-io\n' +
|
||||
'Deployment URL : https://v9.angular.io/');
|
||||
});
|
||||
|
||||
it('archive - skip deploy - commit not HEAD', () => {
|
||||
expect(deployToFirebaseDryRun({
|
||||
CI_REPO_OWNER: 'angular',
|
||||
CI_REPO_NAME: 'angular',
|
||||
CI_PULL_REQUEST: 'false',
|
||||
CI_BRANCH: '2.4.x',
|
||||
CI_STABLE_BRANCH: '4.3.x',
|
||||
CI_COMMIT: 'DUMMY_TEST_COMMIT',
|
||||
CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN: 'XXXXX',
|
||||
})).toBe(
|
||||
'Skipping deploy because DUMMY_TEST_COMMIT is not the latest commit ' +
|
||||
`(${getLatestCommitForBranch('2.4.x')}).`);
|
||||
});
|
||||
|
||||
it('archive - skip deploy - major version too high, lower minor', () => {
|
||||
expect(deployToFirebaseDryRun({
|
||||
CI_REPO_OWNER: 'angular',
|
||||
CI_REPO_NAME: 'angular',
|
||||
CI_PULL_REQUEST: 'false',
|
||||
CI_BRANCH: '2.1.x',
|
||||
CI_STABLE_BRANCH: '2.2.x',
|
||||
CI_COMMIT: getLatestCommitForBranch('2.1.x'),
|
||||
CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN: 'XXXXX',
|
||||
})).toBe(
|
||||
'Skipping deploy of branch "2.1.x" to Firebase.\n' +
|
||||
'We only deploy archive branches with the major version less than the stable branch: ' +
|
||||
'"2.2.x"');
|
||||
});
|
||||
|
||||
it('archive - skip deploy - major version too high, higher minor', () => {
|
||||
expect(deployToFirebaseDryRun({
|
||||
CI_REPO_OWNER: 'angular',
|
||||
CI_REPO_NAME: 'angular',
|
||||
CI_PULL_REQUEST: 'false',
|
||||
CI_BRANCH: '2.4.x',
|
||||
CI_STABLE_BRANCH: '2.2.x',
|
||||
CI_COMMIT: getLatestCommitForBranch('2.4.x'),
|
||||
CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN: 'XXXXX',
|
||||
})).toBe(
|
||||
'Skipping deploy of branch "2.4.x" to Firebase.\n' +
|
||||
'We only deploy archive branches with the major version less than the stable branch: ' +
|
||||
'"2.2.x"');
|
||||
});
|
||||
|
||||
it('archive - skip deploy - minor version too low', () => {
|
||||
expect(deployToFirebaseDryRun({
|
||||
CI_REPO_OWNER: 'angular',
|
||||
CI_REPO_NAME: 'angular',
|
||||
CI_PULL_REQUEST: 'false',
|
||||
CI_BRANCH: '2.1.x',
|
||||
CI_STABLE_BRANCH: '4.3.x',
|
||||
CI_COMMIT: getLatestCommitForBranch('2.1.x'),
|
||||
CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN: 'XXXXX',
|
||||
})).toBe(
|
||||
'Skipping deploy of branch "2.1.x" to Firebase.\n' +
|
||||
'There is a more recent branch with the same major version: "2.4.x"');
|
||||
});
|
||||
});
|
|
@ -1,244 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
set +x -eu -o pipefail
|
||||
|
||||
readonly deployToFirebaseDryRun="`dirname $0`/deploy-to-firebase.sh --dry-run"
|
||||
|
||||
function check {
|
||||
if [[ $1 == $2 ]]; then
|
||||
echo Pass
|
||||
exit 0
|
||||
fi
|
||||
echo Fail
|
||||
echo ---- Expected ----
|
||||
echo "$2"
|
||||
echo ---- Actual ----
|
||||
echo "$1"
|
||||
exit 1
|
||||
}
|
||||
|
||||
(
|
||||
echo ===== master - skip deploy - not angular
|
||||
actual=$(
|
||||
export BASH_ENV=/dev/null
|
||||
export CI_REPO_OWNER=angular
|
||||
export CI_REPO_NAME=notangular
|
||||
$deployToFirebaseDryRun
|
||||
)
|
||||
expected="Skipping deploy because this is not angular/angular."
|
||||
check "$actual" "$expected"
|
||||
)
|
||||
|
||||
(
|
||||
echo ===== master - skip deploy - angular fork
|
||||
actual=$(
|
||||
export BASH_ENV=/dev/null
|
||||
export CI_REPO_OWNER=notangular
|
||||
export CI_REPO_NAME=angular
|
||||
$deployToFirebaseDryRun
|
||||
)
|
||||
expected="Skipping deploy because this is not angular/angular."
|
||||
check "$actual" "$expected"
|
||||
)
|
||||
|
||||
(
|
||||
echo ===== master - skip deploy - pull request
|
||||
actual=$(
|
||||
export BASH_ENV=/dev/null
|
||||
export CI_REPO_OWNER=angular
|
||||
export CI_REPO_NAME=angular
|
||||
export CI_PULL_REQUEST=true
|
||||
$deployToFirebaseDryRun
|
||||
)
|
||||
expected="Skipping deploy because this is a PR build."
|
||||
check "$actual" "$expected"
|
||||
)
|
||||
|
||||
(
|
||||
echo ===== master - deploy success
|
||||
actual=$(
|
||||
export BASH_ENV=/dev/null
|
||||
export CI_REPO_OWNER=angular
|
||||
export CI_REPO_NAME=angular
|
||||
export CI_PULL_REQUEST=false
|
||||
export CI_BRANCH=master
|
||||
export CI_COMMIT=$(git ls-remote origin master | cut -c1-40)
|
||||
export CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN=XXXXX
|
||||
$deployToFirebaseDryRun
|
||||
)
|
||||
expected="Git branch : master
|
||||
Build/deploy mode : next
|
||||
Firebase project : aio-staging
|
||||
Firebase site : aio-staging
|
||||
Deployment URL : https://next.angular.io/"
|
||||
check "$actual" "$expected"
|
||||
)
|
||||
|
||||
(
|
||||
echo ===== master - skip deploy - commit not HEAD
|
||||
actual=$(
|
||||
export BASH_ENV=/dev/null
|
||||
export CI_REPO_OWNER=angular
|
||||
export CI_REPO_NAME=angular
|
||||
export CI_PULL_REQUEST=false
|
||||
export CI_BRANCH=master
|
||||
export CI_COMMIT=DUMMY_TEST_COMMIT
|
||||
$deployToFirebaseDryRun
|
||||
)
|
||||
expected="Skipping deploy because DUMMY_TEST_COMMIT is not the latest commit ($(git ls-remote origin master | cut -c1-40))."
|
||||
check "$actual" "$expected"
|
||||
)
|
||||
|
||||
(
|
||||
echo ===== stable - deploy success
|
||||
actual=$(
|
||||
export BASH_ENV=/dev/null
|
||||
export CI_REPO_OWNER=angular
|
||||
export CI_REPO_NAME=angular
|
||||
export CI_PULL_REQUEST=false
|
||||
export CI_BRANCH=4.3.x
|
||||
export CI_STABLE_BRANCH=4.3.x
|
||||
export CI_COMMIT=$(git ls-remote origin 4.3.x | cut -c1-40)
|
||||
export CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN=XXXXX
|
||||
$deployToFirebaseDryRun
|
||||
)
|
||||
expected="Git branch : 4.3.x
|
||||
Build/deploy mode : stable
|
||||
Firebase project : angular-io
|
||||
Firebase site : angular-io
|
||||
Deployment URL : https://angular.io/"
|
||||
check "$actual" "$expected"
|
||||
)
|
||||
|
||||
(
|
||||
echo ===== stable - skip deploy - commit not HEAD
|
||||
actual=$(
|
||||
export BASH_ENV=/dev/null
|
||||
export CI_REPO_OWNER=angular
|
||||
export CI_REPO_NAME=angular
|
||||
export CI_PULL_REQUEST=false
|
||||
export CI_BRANCH=4.3.x
|
||||
export CI_STABLE_BRANCH=4.3.x
|
||||
export CI_COMMIT=DUMMY_TEST_COMMIT
|
||||
$deployToFirebaseDryRun
|
||||
)
|
||||
expected="Skipping deploy because DUMMY_TEST_COMMIT is not the latest commit ($(git ls-remote origin 4.3.x | cut -c1-40))."
|
||||
check "$actual" "$expected"
|
||||
)
|
||||
|
||||
(
|
||||
echo ===== archive - deploy success
|
||||
actual=$(
|
||||
export BASH_ENV=/dev/null
|
||||
export CI_REPO_OWNER=angular
|
||||
export CI_REPO_NAME=angular
|
||||
export CI_PULL_REQUEST=false
|
||||
export CI_BRANCH=2.4.x
|
||||
export CI_STABLE_BRANCH=4.3.x
|
||||
export CI_COMMIT=$(git ls-remote origin 2.4.x | cut -c1-40)
|
||||
export CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN=XXXXX
|
||||
$deployToFirebaseDryRun
|
||||
)
|
||||
expected="Git branch : 2.4.x
|
||||
Build/deploy mode : archive
|
||||
Firebase project : v2-angular-io
|
||||
Firebase site : v2-angular-io
|
||||
Deployment URL : https://v2.angular.io/"
|
||||
check "$actual" "$expected"
|
||||
)
|
||||
|
||||
(
|
||||
echo ===== archive - v9-angular-io multisite special case - deploy success
|
||||
actual=$(
|
||||
export BASH_ENV=/dev/null
|
||||
export CI_REPO_OWNER=angular
|
||||
export CI_REPO_NAME=angular
|
||||
export CI_PULL_REQUEST=false
|
||||
export CI_BRANCH=9.1.x
|
||||
export CI_STABLE_BRANCH=10.0.x
|
||||
export CI_COMMIT=$(git ls-remote origin 9.1.x | cut -c1-40)
|
||||
export CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN=XXXXX
|
||||
$deployToFirebaseDryRun
|
||||
)
|
||||
expected="Git branch : 9.1.x
|
||||
Build/deploy mode : archive
|
||||
Firebase project : aio-staging
|
||||
Firebase site : v9-angular-io
|
||||
Deployment URL : https://v9.angular.io/"
|
||||
# TODO: This test incorrectly expects the Firebase project to be v9-angular-io.
|
||||
# v9-angular-io is a "multisites" project currently within the aio-staging project
|
||||
# This setup is temporary and was created in order to deploy v9.angular.io without
|
||||
# disruptions.
|
||||
# See https://angular-team.atlassian.net/browse/DEV-125 for more info.
|
||||
check "$actual" "$expected"
|
||||
)
|
||||
|
||||
(
|
||||
echo ===== archive - skip deploy - commit not HEAD
|
||||
actual=$(
|
||||
export BASH_ENV=/dev/null
|
||||
export CI_REPO_OWNER=angular
|
||||
export CI_REPO_NAME=angular
|
||||
export CI_PULL_REQUEST=false
|
||||
export CI_BRANCH=2.4.x
|
||||
export CI_STABLE_BRANCH=4.3.x
|
||||
export CI_COMMIT=DUMMY_TEST_COMMIT
|
||||
export CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN=XXXXX
|
||||
$deployToFirebaseDryRun
|
||||
)
|
||||
expected="Skipping deploy because DUMMY_TEST_COMMIT is not the latest commit ($(git ls-remote origin 2.4.x | cut -c1-40))."
|
||||
check "$actual" "$expected"
|
||||
)
|
||||
|
||||
(
|
||||
echo ===== archive - skip deploy - major version too high, lower minor
|
||||
actual=$(
|
||||
export BASH_ENV=/dev/null
|
||||
export CI_REPO_OWNER=angular
|
||||
export CI_REPO_NAME=angular
|
||||
export CI_PULL_REQUEST=false
|
||||
export CI_BRANCH=2.1.x
|
||||
export CI_STABLE_BRANCH=2.2.x
|
||||
export CI_COMMIT=$(git ls-remote origin 2.1.x | cut -c-40)
|
||||
export CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN=XXXXX
|
||||
$deployToFirebaseDryRun
|
||||
)
|
||||
expected="Skipping deploy of branch \"2.1.x\" to firebase.
|
||||
We only deploy archive branches with the major version less than the stable branch: \"2.2.x\""
|
||||
check "$actual" "$expected"
|
||||
)
|
||||
|
||||
(
|
||||
echo ===== archive - skip deploy - major version too high, higher minor
|
||||
actual=$(
|
||||
export BASH_ENV=/dev/null
|
||||
export CI_REPO_OWNER=angular
|
||||
export CI_REPO_NAME=angular
|
||||
export CI_PULL_REQUEST=false
|
||||
export CI_BRANCH=2.4.x
|
||||
export CI_STABLE_BRANCH=2.2.x
|
||||
export CI_COMMIT=$(git ls-remote origin 2.4.x | cut -c-40)
|
||||
export CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN=XXXXX
|
||||
$deployToFirebaseDryRun
|
||||
)
|
||||
expected="Skipping deploy of branch \"2.4.x\" to firebase.
|
||||
We only deploy archive branches with the major version less than the stable branch: \"2.2.x\""
|
||||
check "$actual" "$expected"
|
||||
)
|
||||
|
||||
(
|
||||
echo ===== archive - skip deploy - minor version too low
|
||||
actual=$(
|
||||
export BASH_ENV=/dev/null
|
||||
export CI_REPO_OWNER=angular
|
||||
export CI_REPO_NAME=angular
|
||||
export CI_PULL_REQUEST=false
|
||||
export CI_BRANCH=2.1.x
|
||||
export CI_STABLE_BRANCH=4.3.x
|
||||
export CI_COMMIT=$(git ls-remote origin 2.1.x | cut -c-40)
|
||||
export CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN=XXXXX
|
||||
$deployToFirebaseDryRun
|
||||
)
|
||||
expected="Skipping deploy of branch \"2.1.x\" to firebase.
|
||||
There is a more recent branch with the same major version: \"2.4.x\""
|
||||
check "$actual" "$expected"
|
||||
)
|
|
@ -6,8 +6,8 @@ After the AIO application had been built and before it is deployed all files and
|
|||
inside the folder with the same name as the current deployment mode (next, stable, archive)
|
||||
will be copied to the `dist` folder.
|
||||
|
||||
See the `scripts/deploy-to-firebase.sh` script for more detail.
|
||||
See the `scripts/deploy-to-firebase.js` script for more details.
|
||||
|
||||
**Note:**
|
||||
The `deploy-to-firebase.sh` script always expects there to be a folder for the current deployment
|
||||
The `deploy-to-firebase.js` script always expects there to be a folder for the current deployment
|
||||
mode (even if it is empty).
|
||||
|
|
|
@ -11863,7 +11863,7 @@ shell-quote@^1.6.1:
|
|||
resolved "https://registry.yarnpkg.com/shell-quote/-/shell-quote-1.7.2.tgz#67a7d02c76c9da24f99d20808fcaded0e0e04be2"
|
||||
integrity sha512-mRz/m/JVscCrkMyPqHc/bczi3OQHkLTqXHEFu0zDhK/qfv3UcOA4SVmRCLmos4bhjr9ekVQubj/R7waKapmiQg==
|
||||
|
||||
shelljs@^0.7.5, shelljs@^0.7.7:
|
||||
shelljs@^0.7.5:
|
||||
version "0.7.8"
|
||||
resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.7.8.tgz#decbcf874b0d1e5fb72e14b164a9683048e9acb3"
|
||||
integrity sha1-3svPh0sNHl+3LhSxZKloMEjprLM=
|
||||
|
@ -11872,6 +11872,15 @@ shelljs@^0.7.5, shelljs@^0.7.7:
|
|||
interpret "^1.0.0"
|
||||
rechoir "^0.6.2"
|
||||
|
||||
shelljs@^0.8.4:
|
||||
version "0.8.4"
|
||||
resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.8.4.tgz#de7684feeb767f8716b326078a8a00875890e3c2"
|
||||
integrity sha512-7gk3UZ9kOfPLIAbslLzyWeGiEqx9e3rxwZM0KE6EL8GlGwjym9Mrlx5/p33bWTu9YG6vcS4MBxYZDHYr5lr8BQ==
|
||||
dependencies:
|
||||
glob "^7.0.0"
|
||||
interpret "^1.0.0"
|
||||
rechoir "^0.6.2"
|
||||
|
||||
signal-exit@^3.0.0, signal-exit@^3.0.2:
|
||||
version "3.0.2"
|
||||
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
|
||||
|
|
Loading…
Reference in New Issue