2020-10-28 06:23:51 -04:00
|
|
|
#!/usr/bin/env node
|
|
|
|
'use strict';
|
|
|
|
|
2020-11-02 12:54:24 -05:00
|
|
|
const {execSync} = require('child_process');
|
2020-10-28 06:23:58 -04:00
|
|
|
const {computeDeploymentInfo, computeInputVars, getLatestCommit} = require('./deploy-to-firebase');
|
2020-10-28 06:23:51 -04:00
|
|
|
|
|
|
|
|
|
|
|
describe('deploy-to-firebase:', () => {
|
|
|
|
it('master - skip deploy - not angular', () => {
|
2020-10-28 06:23:58 -04:00
|
|
|
expect(computeDeploymentInfo(computeInputVars({
|
2020-10-28 06:23:51 -04:00
|
|
|
CI_REPO_OWNER: 'angular',
|
|
|
|
CI_REPO_NAME: 'notangular',
|
2020-10-28 06:23:58 -04:00
|
|
|
}))).toEqual({
|
|
|
|
skipped: true,
|
|
|
|
reason: 'Skipping deploy because this is not angular/angular.',
|
|
|
|
});
|
2020-10-28 06:23:51 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('master - skip deploy - angular fork', () => {
|
2020-10-28 06:23:58 -04:00
|
|
|
expect(computeDeploymentInfo(computeInputVars({
|
2020-10-28 06:23:51 -04:00
|
|
|
CI_REPO_OWNER: 'notangular',
|
|
|
|
CI_REPO_NAME: 'angular',
|
2020-10-28 06:23:58 -04:00
|
|
|
}))).toEqual({
|
|
|
|
skipped: true,
|
|
|
|
reason: 'Skipping deploy because this is not angular/angular.',
|
|
|
|
});
|
2020-10-28 06:23:51 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('master - skip deploy - pull request', () => {
|
2020-10-28 06:23:58 -04:00
|
|
|
expect(computeDeploymentInfo(computeInputVars({
|
2020-10-28 06:23:51 -04:00
|
|
|
CI_REPO_OWNER: 'angular',
|
|
|
|
CI_REPO_NAME: 'angular',
|
|
|
|
CI_PULL_REQUEST: 'true',
|
2020-10-28 06:23:58 -04:00
|
|
|
}))).toEqual({
|
|
|
|
skipped: true,
|
|
|
|
reason: 'Skipping deploy because this is a PR build.',
|
|
|
|
});
|
2020-10-28 06:23:51 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('master - deploy success', () => {
|
2020-10-28 06:23:58 -04:00
|
|
|
expect(computeDeploymentInfo(computeInputVars({
|
2020-10-28 06:23:51 -04:00
|
|
|
CI_REPO_OWNER: 'angular',
|
|
|
|
CI_REPO_NAME: 'angular',
|
|
|
|
CI_PULL_REQUEST: 'false',
|
|
|
|
CI_BRANCH: 'master',
|
2020-10-28 06:23:58 -04:00
|
|
|
CI_COMMIT: getLatestCommit('master'),
|
|
|
|
}))).toEqual({
|
|
|
|
deployEnv: 'next',
|
2020-10-28 14:51:08 -04:00
|
|
|
projectId: 'angular-io',
|
|
|
|
siteId: 'next-angular-io-site',
|
2020-10-28 06:23:58 -04:00
|
|
|
deployedUrl: 'https://next.angular.io/',
|
|
|
|
});
|
2020-10-28 06:23:51 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('master - skip deploy - commit not HEAD', () => {
|
2020-10-28 06:23:58 -04:00
|
|
|
expect(computeDeploymentInfo(computeInputVars({
|
2020-10-28 06:23:51 -04:00
|
|
|
CI_REPO_OWNER: 'angular',
|
|
|
|
CI_REPO_NAME: 'angular',
|
|
|
|
CI_PULL_REQUEST: 'false',
|
|
|
|
CI_BRANCH: 'master',
|
|
|
|
CI_COMMIT: 'DUMMY_TEST_COMMIT',
|
2020-10-28 06:23:58 -04:00
|
|
|
}))).toEqual({
|
|
|
|
skipped: true,
|
|
|
|
reason:
|
|
|
|
'Skipping deploy because DUMMY_TEST_COMMIT is not the latest commit ' +
|
|
|
|
`(${getLatestCommit('master')}).`,
|
|
|
|
});
|
2020-10-28 06:23:51 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('stable - deploy success', () => {
|
2020-10-28 06:23:58 -04:00
|
|
|
expect(computeDeploymentInfo(computeInputVars({
|
2020-10-28 06:23:51 -04:00
|
|
|
CI_REPO_OWNER: 'angular',
|
|
|
|
CI_REPO_NAME: 'angular',
|
|
|
|
CI_PULL_REQUEST: 'false',
|
|
|
|
CI_BRANCH: '4.3.x',
|
|
|
|
CI_STABLE_BRANCH: '4.3.x',
|
2020-10-28 06:23:58 -04:00
|
|
|
CI_COMMIT: getLatestCommit('4.3.x'),
|
|
|
|
}))).toEqual({
|
|
|
|
deployEnv: 'stable',
|
|
|
|
projectId: 'angular-io',
|
2020-10-28 14:51:08 -04:00
|
|
|
siteId: 'v4-angular-io-site',
|
2020-10-28 06:23:58 -04:00
|
|
|
deployedUrl: 'https://angular.io/',
|
|
|
|
});
|
2020-10-28 06:23:51 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('stable - skip deploy - commit not HEAD', () => {
|
2020-10-28 06:23:58 -04:00
|
|
|
expect(computeDeploymentInfo(computeInputVars({
|
2020-10-28 06:23:51 -04:00
|
|
|
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',
|
2020-10-28 06:23:58 -04:00
|
|
|
}))).toEqual({
|
|
|
|
skipped: true,
|
|
|
|
reason:
|
|
|
|
'Skipping deploy because DUMMY_TEST_COMMIT is not the latest commit ' +
|
|
|
|
`(${getLatestCommit('4.3.x')}).`,
|
|
|
|
});
|
2020-10-28 06:23:51 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('archive - deploy success', () => {
|
2020-10-28 06:23:58 -04:00
|
|
|
expect(computeDeploymentInfo(computeInputVars({
|
2020-10-28 06:23:51 -04:00
|
|
|
CI_REPO_OWNER: 'angular',
|
|
|
|
CI_REPO_NAME: 'angular',
|
|
|
|
CI_PULL_REQUEST: 'false',
|
|
|
|
CI_BRANCH: '2.4.x',
|
|
|
|
CI_STABLE_BRANCH: '4.3.x',
|
2020-10-28 06:23:58 -04:00
|
|
|
CI_COMMIT: getLatestCommit('2.4.x'),
|
|
|
|
}))).toEqual({
|
|
|
|
deployEnv: 'archive',
|
2020-10-28 14:51:08 -04:00
|
|
|
projectId: 'angular-io',
|
|
|
|
siteId: 'v2-angular-io-site',
|
2020-10-28 06:23:58 -04:00
|
|
|
deployedUrl: 'https://v2.angular.io/',
|
|
|
|
});
|
2020-10-28 06:23:51 -04:00
|
|
|
});
|
|
|
|
|
2020-10-28 14:51:08 -04:00
|
|
|
// v9 used to be special-cased, because it was piloting the Firebase hosting "multisites" setup.
|
|
|
|
// See https://angular-team.atlassian.net/browse/DEV-125 for more info.
|
|
|
|
it('archive - deploy success (no special case for v9)', () => {
|
2020-10-28 06:23:58 -04:00
|
|
|
expect(computeDeploymentInfo(computeInputVars({
|
2020-10-28 06:23:51 -04:00
|
|
|
CI_REPO_OWNER: 'angular',
|
|
|
|
CI_REPO_NAME: 'angular',
|
|
|
|
CI_PULL_REQUEST: 'false',
|
|
|
|
CI_BRANCH: '9.1.x',
|
|
|
|
CI_STABLE_BRANCH: '10.0.x',
|
2020-10-28 06:23:58 -04:00
|
|
|
CI_COMMIT: getLatestCommit('9.1.x'),
|
|
|
|
}))).toEqual({
|
|
|
|
deployEnv: 'archive',
|
2020-10-28 14:51:08 -04:00
|
|
|
projectId: 'angular-io',
|
|
|
|
siteId: 'v9-angular-io-site',
|
2020-10-28 06:23:58 -04:00
|
|
|
deployedUrl: 'https://v9.angular.io/',
|
|
|
|
});
|
2020-10-28 06:23:51 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('archive - skip deploy - commit not HEAD', () => {
|
2020-10-28 06:23:58 -04:00
|
|
|
expect(computeDeploymentInfo(computeInputVars({
|
2020-10-28 06:23:51 -04:00
|
|
|
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',
|
2020-10-28 06:23:58 -04:00
|
|
|
}))).toEqual({
|
|
|
|
skipped: true,
|
|
|
|
reason:
|
|
|
|
'Skipping deploy because DUMMY_TEST_COMMIT is not the latest commit ' +
|
|
|
|
`(${getLatestCommit('2.4.x')}).`,
|
|
|
|
});
|
2020-10-28 06:23:51 -04:00
|
|
|
});
|
|
|
|
|
2020-10-28 06:23:57 -04:00
|
|
|
it('archive - skip deploy - major same as stable, minor less than stable', () => {
|
2020-10-28 06:23:58 -04:00
|
|
|
expect(computeDeploymentInfo(computeInputVars({
|
2020-10-28 06:23:51 -04:00
|
|
|
CI_REPO_OWNER: 'angular',
|
|
|
|
CI_REPO_NAME: 'angular',
|
|
|
|
CI_PULL_REQUEST: 'false',
|
|
|
|
CI_BRANCH: '2.1.x',
|
|
|
|
CI_STABLE_BRANCH: '2.2.x',
|
2020-10-28 06:23:58 -04:00
|
|
|
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"',
|
|
|
|
});
|
2020-10-28 06:23:51 -04:00
|
|
|
});
|
|
|
|
|
2020-10-28 06:23:57 -04:00
|
|
|
it('archive - skip deploy - major lower than stable, minor not latest', () => {
|
2020-10-28 06:23:58 -04:00
|
|
|
expect(computeDeploymentInfo(computeInputVars({
|
2020-10-28 06:23:57 -04:00
|
|
|
CI_REPO_OWNER: 'angular',
|
|
|
|
CI_REPO_NAME: 'angular',
|
|
|
|
CI_PULL_REQUEST: 'false',
|
|
|
|
CI_BRANCH: '2.1.x',
|
|
|
|
CI_STABLE_BRANCH: '4.3.x',
|
2020-10-28 06:23:58 -04:00
|
|
|
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"',
|
|
|
|
});
|
2020-10-28 06:23:57 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('rc - deploy success - major higher than stable', () => {
|
2020-10-28 06:23:58 -04:00
|
|
|
expect(computeDeploymentInfo(computeInputVars({
|
2020-10-28 06:23:57 -04:00
|
|
|
CI_REPO_OWNER: 'angular',
|
|
|
|
CI_REPO_NAME: 'angular',
|
|
|
|
CI_PULL_REQUEST: 'false',
|
|
|
|
CI_BRANCH: '4.4.x',
|
|
|
|
CI_STABLE_BRANCH: '2.2.x',
|
2020-10-28 06:23:58 -04:00
|
|
|
CI_COMMIT: getLatestCommit('4.4.x'),
|
|
|
|
}))).toEqual({
|
|
|
|
deployEnv: 'rc',
|
|
|
|
projectId: 'angular-io',
|
|
|
|
siteId: 'rc-angular-io-site',
|
|
|
|
deployedUrl: 'https://rc.angular.io/',
|
|
|
|
});
|
2020-10-28 06:23:57 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('rc - deploy success - major same as stable, minor higher', () => {
|
2020-10-28 06:23:58 -04:00
|
|
|
expect(computeDeploymentInfo(computeInputVars({
|
2020-10-28 06:23:51 -04:00
|
|
|
CI_REPO_OWNER: 'angular',
|
|
|
|
CI_REPO_NAME: 'angular',
|
|
|
|
CI_PULL_REQUEST: 'false',
|
|
|
|
CI_BRANCH: '2.4.x',
|
|
|
|
CI_STABLE_BRANCH: '2.2.x',
|
2020-10-28 06:23:58 -04:00
|
|
|
CI_COMMIT: getLatestCommit('2.4.x'),
|
|
|
|
}))).toEqual({
|
|
|
|
deployEnv: 'rc',
|
|
|
|
projectId: 'angular-io',
|
|
|
|
siteId: 'rc-angular-io-site',
|
|
|
|
deployedUrl: 'https://rc.angular.io/',
|
|
|
|
});
|
2020-10-28 06:23:57 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('rc - skip deploy - commit not HEAD', () => {
|
2020-10-28 06:23:58 -04:00
|
|
|
expect(computeDeploymentInfo(computeInputVars({
|
2020-10-28 06:23:57 -04:00
|
|
|
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',
|
2020-10-28 06:23:58 -04:00
|
|
|
}))).toEqual({
|
|
|
|
skipped: true,
|
|
|
|
reason:
|
|
|
|
'Skipping deploy because DUMMY_TEST_COMMIT is not the latest commit ' +
|
|
|
|
`(${getLatestCommit('2.4.x')}).`,
|
|
|
|
});
|
2020-10-28 06:23:51 -04:00
|
|
|
});
|
|
|
|
|
2020-10-28 06:23:57 -04:00
|
|
|
it('rc - skip deploy - major same as stable, minor not latest', () => {
|
2020-10-28 06:23:58 -04:00
|
|
|
expect(computeDeploymentInfo(computeInputVars({
|
2020-10-28 06:23:51 -04:00
|
|
|
CI_REPO_OWNER: 'angular',
|
|
|
|
CI_REPO_NAME: 'angular',
|
|
|
|
CI_PULL_REQUEST: 'false',
|
|
|
|
CI_BRANCH: '2.1.x',
|
2020-10-28 06:23:57 -04:00
|
|
|
CI_STABLE_BRANCH: '2.0.x',
|
2020-10-28 06:23:58 -04:00
|
|
|
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"',
|
|
|
|
});
|
2020-10-28 06:23:51 -04:00
|
|
|
});
|
2020-10-28 06:23:57 -04:00
|
|
|
|
|
|
|
it('rc - skip deploy - major higher than stable, minor not latest', () => {
|
2020-10-28 06:23:58 -04:00
|
|
|
expect(computeDeploymentInfo(computeInputVars({
|
2020-10-28 06:23:57 -04:00
|
|
|
CI_REPO_OWNER: 'angular',
|
|
|
|
CI_REPO_NAME: 'angular',
|
|
|
|
CI_PULL_REQUEST: 'false',
|
|
|
|
CI_BRANCH: '4.3.x',
|
|
|
|
CI_STABLE_BRANCH: '2.4.x',
|
2020-10-28 06:23:58 -04:00
|
|
|
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"',
|
|
|
|
});
|
2020-10-28 06:23:57 -04:00
|
|
|
});
|
2020-11-02 12:54:24 -05:00
|
|
|
|
|
|
|
it('integration - should run the main script without error', () => {
|
2020-11-05 11:26:14 -05:00
|
|
|
const commit = getLatestCommit('master');
|
2020-11-02 12:54:24 -05:00
|
|
|
const cmd = `"${process.execPath}" "${__dirname}/deploy-to-firebase" --dry-run`;
|
|
|
|
const env = {
|
|
|
|
CI_REPO_OWNER: 'angular',
|
|
|
|
CI_REPO_NAME: 'angular',
|
|
|
|
CI_PULL_REQUEST: 'false',
|
|
|
|
CI_BRANCH: 'master',
|
2020-11-05 11:26:14 -05:00
|
|
|
CI_COMMIT: commit,
|
2020-11-02 12:54:24 -05:00
|
|
|
};
|
|
|
|
const result = execSync(cmd, {encoding: 'utf8', env}).trim();
|
|
|
|
expect(result).toBe(
|
|
|
|
'Git branch : master\n' +
|
2020-11-05 11:26:14 -05:00
|
|
|
`Git commit : ${commit}\n` +
|
2020-11-02 12:54:24 -05:00
|
|
|
'Build/deploy mode : next\n' +
|
|
|
|
'Firebase project : angular-io\n' +
|
|
|
|
'Firebase site : next-angular-io-site\n' +
|
|
|
|
'Deployment URLs : https://next.angular.io/\n' +
|
|
|
|
' https://next-angular-io-site.web.app/');
|
|
|
|
});
|
2020-10-28 06:23:51 -04:00
|
|
|
});
|