refactor(docs-infra): break up `deploy-to-firebase.js` script into functions (#39470)

This commit breaks up the code in `deploy-to-firebase.js` script, that
we use for deploying angular.io to production, to smaller functions
(instead of a monolithic block). This makes the script easier to
maintain and also makes testing individual operations easier.

The commit also updates the `deploy-to-firebase.spec.js` spec file to
take advantage of the standalone functions to speed up testing by
calling the corresponding function instead of having to spawn a new
process and run the `deploy-to-firebase.js` script with the `--dry-run`
flag.

NOTE: Before updating the tests, I verified that the updated
      `deploy-to-firebase.js` script passed the old tests.

PR Close #39470
This commit is contained in:
George Kalpakas 2020-10-28 12:23:58 +02:00 committed by Joey Perrott
parent 1aaf556815
commit 699824a2a5
2 changed files with 300 additions and 251 deletions

View File

@ -9,165 +9,202 @@ const {cd, cp, exec: _exec, set} = require('shelljs');
set('-e');
// Arguments, environment variables and constants.
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;
// Constants
const REPO_SLUG = 'angular/angular';
const NG_REMOTE_URL = `https://github.com/${REPO_SLUG}.git`;
// Do not deploy if we are running in a fork.
if (`${CI_REPO_OWNER}/${CI_REPO_NAME}` !== REPO_SLUG) {
console.log(`Skipping deploy because this is not ${REPO_SLUG}.`);
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 ${NG_REMOTE_URL} ${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/',
},
rc: {
deployEnv: 'rc',
projectId: 'angular-io',
siteId: 'rc-angular-io-site',
deployedUrl: 'https://rc.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/`,
},
// Exports
module.exports = {
computeDeploymentInfo,
computeInputVars,
getLatestCommit,
};
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);
// Run
if (require.main === module) {
const isDryRun = process.argv[2] === '--dry-run';
const inputVars = computeInputVars(process.env);
const deploymentInfo = computeDeploymentInfo(inputVars);
// Find the branch that has highest minor version for the given `currentBranchMajorVersion`.
const mostRecentMinorVersionBranch =
// List the branches that start with the major version.
exec(`git ls-remote ${NG_REMOTE_URL} 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 if it is not the latest branch for the given major version.
// NOTE: At this point, we know the current branch is not the stable branch.
if (CI_BRANCH !== mostRecentMinorVersionBranch) {
if (deploymentInfo.skipped) {
console.log(deploymentInfo.reason);
} else {
console.log(
`Skipping deploy of branch "${CI_BRANCH}" to Firebase.\n` +
'There is a more recent branch with the same major version: ' +
`"${mostRecentMinorVersionBranch}"`);
process.exit(0);
`Git branch : ${currentBranch}\n` +
`Build/deploy mode : ${deploymentInfo.deployEnv}\n` +
`Firebase project : ${deploymentInfo.projectId}\n` +
`Firebase site : ${deploymentInfo.siteId}\n` +
`Deployment URLs : ${deploymentInfo.deployedUrl}\n`);
if (!isDryRun) {
deploy({...inputVars, ...deploymentInfo});
}
}
deployInfo = (currentBranchMajorVersion < stableBranchMajorVersion) ?
// This is the latest minor version for a major that is less than the stable major version:
// Deploy as `archive`.
deployInfoPerTarget.archive :
// This is the latest minor version for a major that is equal or greater than the stable major
// version, but not the stable version itself:
// Deploy as `rc`.
deployInfoPerTarget.rc;
}
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 computeDeploymentInfo(
{currentBranch, currentCommit, isPullRequest, repoName, repoOwner, stableBranch}) {
// Do not deploy if we are running in a fork.
if (`${repoOwner}/${repoName}` !== REPO_SLUG) {
return skipDeployment(`Skipping deploy because this is not ${REPO_SLUG}.`);
}
// Do not deploy if this is a PR. PRs are deployed in the `aio_preview` CircleCI job.
if (isPullRequest) {
return skipDeployment('Skipping deploy because this is a PR build.');
}
// Do not deploy if the current commit is not the latest on its branch.
const latestCommit = getLatestCommit(currentBranch);
if (currentCommit !== latestCommit) {
return skipDeployment(
`Skipping deploy because ${currentCommit} is not the latest commit (${latestCommit}).`);
}
// The deployment mode is computed based on the branch we are building.
const currentBranchMajorVersion = computeMajorVersion(currentBranch);
// 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 deploymentInfoPerTarget = {
next: {
deployEnv: 'next',
projectId: 'aio-staging',
siteId: 'aio-staging',
deployedUrl: 'https://next.angular.io/',
},
rc: {
deployEnv: 'rc',
projectId: 'angular-io',
siteId: 'rc-angular-io-site',
deployedUrl: 'https://rc.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/`,
},
};
if (currentBranch === 'master') {
return deploymentInfoPerTarget.next;
} else if (currentBranch === stableBranch) {
return deploymentInfoPerTarget.stable;
} else {
const stableBranchMajorVersion = computeMajorVersion(stableBranch);
// Find the branch that has highest minor version for the given `currentBranchMajorVersion`.
const mostRecentMinorVersionBranch =
// List the branches that start with the major version.
getRemoteRefs(`refs/heads/${currentBranchMajorVersion}.*.x`)
// 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 if it is not the latest branch for the given major version.
// NOTE: At this point, we know the current branch is not the stable branch.
if (currentBranch !== mostRecentMinorVersionBranch) {
return skipDeployment(
`Skipping deploy of branch "${currentBranch}" to Firebase.\n` +
'There is a more recent branch with the same major version: ' +
`"${mostRecentMinorVersionBranch}"`);
}
return (currentBranchMajorVersion < stableBranchMajorVersion) ?
// This is the latest minor version for a major that is less than the stable major version:
// Deploy as `archive`.
deploymentInfoPerTarget.archive :
// This is the latest minor version for a major that is equal or greater than the stable
// major version, but not the stable version itself:
// Deploy as `rc`.
deploymentInfoPerTarget.rc;
}
// We should never get here.
throw new Error('Failed to determine deployment info.');
}
function computeInputVars({
CI_AIO_MIN_PWA_SCORE: minPwaScore,
CI_BRANCH: currentBranch,
CI_COMMIT: currentCommit,
CI_PULL_REQUEST,
CI_REPO_NAME: repoName,
CI_REPO_OWNER: repoOwner,
CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN: firebaseToken,
CI_STABLE_BRANCH: stableBranch,
}) {
return {
currentBranch,
currentCommit,
firebaseToken,
isPullRequest: CI_PULL_REQUEST !== 'false',
minPwaScore,
repoName,
repoOwner,
stableBranch,
};
}
function computeMajorVersion(branchName) {
return +branchName.split('.', 1)[0];
}
function deploy(
{currentCommit, deployedUrl, deployEnv, firebaseToken, minPwaScore, projectId, siteId}) {
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 "${firebaseToken}"`);
yarn(`firebase target:apply hosting aio "${siteId}" --token "${firebaseToken}"`);
yarn(
`firebase deploy --only hosting:aio --message "Commit: ${currentCommit}" --non-interactive ` +
`--token "${firebaseToken}"`);
console.log('\n\n\n==== Run PWA-score tests. ====\n');
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) {
return exec(`git ls-remote ${remote} ${refOrPattern}`).split('\n');
}
function getLatestCommit(branchName, remote = undefined) {
return getRemoteRefs(branchName, remote)[0].slice(0, 40);
}
function skipDeployment(reason) {
return {reason, skipped: true};
}
function yarn(cmd) {
// Using `--silent` to ensure no secret env variables are printed.
return exec(`yarn --silent ${cmd}`);

View File

@ -1,248 +1,260 @@
#!/usr/bin/env node
'use strict';
const {execSync} = require('child_process');
const {computeDeploymentInfo, computeInputVars, getLatestCommit} = require('./deploy-to-firebase');
describe('deploy-to-firebase:', () => {
const deployToFirebaseCmd = `"${process.execPath}" "${__dirname}/deploy-to-firebase" --dry-run`;
const ngRemoteUrl = 'https://github.com/angular/angular.git';
// Helpers
const deployToFirebaseDryRun =
env => execSync(deployToFirebaseCmd, {encoding: 'utf8', env}).toString().trim();
const getLatestCommitForBranch =
branch => execSync(`git ls-remote ${ngRemoteUrl} ${branch}`).slice(0, 40);
it('master - skip deploy - not angular', () => {
expect(deployToFirebaseDryRun({
expect(computeDeploymentInfo(computeInputVars({
CI_REPO_OWNER: 'angular',
CI_REPO_NAME: 'notangular',
})).toBe('Skipping deploy because this is not angular/angular.');
}))).toEqual({
skipped: true,
reason: 'Skipping deploy because this is not angular/angular.',
});
});
it('master - skip deploy - angular fork', () => {
expect(deployToFirebaseDryRun({
expect(computeDeploymentInfo(computeInputVars({
CI_REPO_OWNER: 'notangular',
CI_REPO_NAME: 'angular',
})).toBe('Skipping deploy because this is not angular/angular.');
}))).toEqual({
skipped: true,
reason: 'Skipping deploy because this is not angular/angular.',
});
});
it('master - skip deploy - pull request', () => {
expect(deployToFirebaseDryRun({
expect(computeDeploymentInfo(computeInputVars({
CI_REPO_OWNER: 'angular',
CI_REPO_NAME: 'angular',
CI_PULL_REQUEST: 'true',
})).toBe('Skipping deploy because this is a PR build.');
}))).toEqual({
skipped: true,
reason: 'Skipping deploy because this is a PR build.',
});
});
it('master - deploy success', () => {
expect(deployToFirebaseDryRun({
expect(computeDeploymentInfo(computeInputVars({
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/');
CI_COMMIT: getLatestCommit('master'),
}))).toEqual({
deployEnv: 'next',
projectId: 'aio-staging',
siteId: 'aio-staging',
deployedUrl: 'https://next.angular.io/',
});
});
it('master - skip deploy - commit not HEAD', () => {
expect(deployToFirebaseDryRun({
expect(computeDeploymentInfo(computeInputVars({
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')}).`);
}))).toEqual({
skipped: true,
reason:
'Skipping deploy because DUMMY_TEST_COMMIT is not the latest commit ' +
`(${getLatestCommit('master')}).`,
});
});
it('stable - deploy success', () => {
expect(deployToFirebaseDryRun({
expect(computeDeploymentInfo(computeInputVars({
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/');
CI_COMMIT: getLatestCommit('4.3.x'),
}))).toEqual({
deployEnv: 'stable',
projectId: 'angular-io',
siteId: 'angular-io',
deployedUrl: 'https://angular.io/',
});
});
it('stable - skip deploy - commit not HEAD', () => {
expect(deployToFirebaseDryRun({
expect(computeDeploymentInfo(computeInputVars({
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')}).`);
}))).toEqual({
skipped: true,
reason:
'Skipping deploy because DUMMY_TEST_COMMIT is not the latest commit ' +
`(${getLatestCommit('4.3.x')}).`,
});
});
it('archive - deploy success', () => {
expect(deployToFirebaseDryRun({
expect(computeDeploymentInfo(computeInputVars({
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/');
CI_COMMIT: getLatestCommit('2.4.x'),
}))).toEqual({
deployEnv: 'archive',
projectId: 'v2-angular-io',
siteId: 'v2-angular-io',
deployedUrl: 'https://v2.angular.io/',
});
});
it('archive - v9-angular-io multisite special case - deploy success', () => {
expect(deployToFirebaseDryRun({
expect(computeDeploymentInfo(computeInputVars({
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/');
CI_COMMIT: getLatestCommit('9.1.x'),
}))).toEqual({
deployEnv: 'archive',
projectId: 'aio-staging',
siteId: 'v9-angular-io',
deployedUrl: 'https://v9.angular.io/',
});
});
it('archive - skip deploy - commit not HEAD', () => {
expect(deployToFirebaseDryRun({
expect(computeDeploymentInfo(computeInputVars({
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')}).`);
}))).toEqual({
skipped: true,
reason:
'Skipping deploy because DUMMY_TEST_COMMIT is not the latest commit ' +
`(${getLatestCommit('2.4.x')}).`,
});
});
it('archive - skip deploy - major same as stable, minor less than stable', () => {
expect(deployToFirebaseDryRun({
expect(computeDeploymentInfo(computeInputVars({
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' +
'There is a more recent branch with the same major version: "2.4.x"');
CI_COMMIT: getLatestCommit('2.1.x'),
}))).toEqual({
skipped: true,
reason:
'Skipping deploy of branch "2.1.x" to Firebase.\n' +
'There is a more recent branch with the same major version: "2.4.x"',
});
});
it('archive - skip deploy - major lower than stable, minor not latest', () => {
expect(deployToFirebaseDryRun({
expect(computeDeploymentInfo(computeInputVars({
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"');
CI_COMMIT: getLatestCommit('2.1.x'),
}))).toEqual({
skipped: true,
reason:
'Skipping deploy of branch "2.1.x" to Firebase.\n' +
'There is a more recent branch with the same major version: "2.4.x"',
});
});
it('rc - deploy success - major higher than stable', () => {
expect(deployToFirebaseDryRun({
expect(computeDeploymentInfo(computeInputVars({
CI_REPO_OWNER: 'angular',
CI_REPO_NAME: 'angular',
CI_PULL_REQUEST: 'false',
CI_BRANCH: '4.4.x',
CI_STABLE_BRANCH: '2.2.x',
CI_COMMIT: getLatestCommitForBranch('4.4.x'),
CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN: 'XXXXX',
})).toBe(
'Git branch : 4.4.x\n' +
'Build/deploy mode : rc\n' +
'Firebase project : angular-io\n' +
'Firebase site : rc-angular-io-site\n' +
'Deployment URL : https://rc.angular.io/');
CI_COMMIT: getLatestCommit('4.4.x'),
}))).toEqual({
deployEnv: 'rc',
projectId: 'angular-io',
siteId: 'rc-angular-io-site',
deployedUrl: 'https://rc.angular.io/',
});
});
it('rc - deploy success - major same as stable, minor higher', () => {
expect(deployToFirebaseDryRun({
expect(computeDeploymentInfo(computeInputVars({
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(
'Git branch : 2.4.x\n' +
'Build/deploy mode : rc\n' +
'Firebase project : angular-io\n' +
'Firebase site : rc-angular-io-site\n' +
'Deployment URL : https://rc.angular.io/');
CI_COMMIT: getLatestCommit('2.4.x'),
}))).toEqual({
deployEnv: 'rc',
projectId: 'angular-io',
siteId: 'rc-angular-io-site',
deployedUrl: 'https://rc.angular.io/',
});
});
it('rc - skip deploy - commit not HEAD', () => {
expect(deployToFirebaseDryRun({
expect(computeDeploymentInfo(computeInputVars({
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: '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')}).`);
}))).toEqual({
skipped: true,
reason:
'Skipping deploy because DUMMY_TEST_COMMIT is not the latest commit ' +
`(${getLatestCommit('2.4.x')}).`,
});
});
it('rc - skip deploy - major same as stable, minor not latest', () => {
expect(deployToFirebaseDryRun({
expect(computeDeploymentInfo(computeInputVars({
CI_REPO_OWNER: 'angular',
CI_REPO_NAME: 'angular',
CI_PULL_REQUEST: 'false',
CI_BRANCH: '2.1.x',
CI_STABLE_BRANCH: '2.0.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"');
CI_COMMIT: getLatestCommit('2.1.x'),
}))).toEqual({
skipped: true,
reason:
'Skipping deploy of branch "2.1.x" to Firebase.\n' +
'There is a more recent branch with the same major version: "2.4.x"',
});
});
it('rc - skip deploy - major higher than stable, minor not latest', () => {
expect(deployToFirebaseDryRun({
expect(computeDeploymentInfo(computeInputVars({
CI_REPO_OWNER: 'angular',
CI_REPO_NAME: 'angular',
CI_PULL_REQUEST: 'false',
CI_BRANCH: '4.3.x',
CI_STABLE_BRANCH: '2.4.x',
CI_COMMIT: getLatestCommitForBranch('4.3.x'),
CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN: 'XXXXX',
})).toBe(
'Skipping deploy of branch "4.3.x" to Firebase.\n' +
'There is a more recent branch with the same major version: "4.4.x"');
CI_COMMIT: getLatestCommit('4.3.x'),
}))).toEqual({
skipped: true,
reason:
'Skipping deploy of branch "4.3.x" to Firebase.\n' +
'There is a more recent branch with the same major version: "4.4.x"',
});
});
});