-
Notifications
You must be signed in to change notification settings - Fork 6.8k
/
Copy pathdeploy-ci-push.mts
118 lines (98 loc) · 4.48 KB
/
deploy-ci-push.mts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env node
import {
ActiveReleaseTrains,
getBranchesForMajorVersions,
convertVersionBranchToSemVer,
isVersionBranch,
} from '@angular/ng-dev';
import {firebaseConfig, sites} from './utils.mjs';
import {buildAndDeployWithSnapshots} from './snapshot-deploy.mjs';
import {getReleaseRepoWithApi} from './github-versioning.mjs';
import {updateVersionsFile} from './update-versions-file.mjs';
async function main() {
if (process.env['CIRCLE_PR_NUMBER'] !== undefined) {
console.log('Skipping deployment for pull request build.');
return;
}
const branchName = process.env['CIRCLE_BRANCH'];
if (branchName === undefined) {
throw new Error('Deployment script is unable to determine CI branch.');
}
const repo = await getReleaseRepoWithApi();
const active = await ActiveReleaseTrains.fetch(repo);
const description = `${branchName} - ${process.env['CIRCLE_SHA1']!}`;
const {projectId, serviceKey} = firebaseConfig;
if (branchName === active.next.branchName) {
const major = active.next.version.major;
const targets = [{projectId, description, site: sites.next}];
// If the next release train is for a new major that is not published as part of the
// other active release trains, we also publish to e.g. `v14.material.angular.io`.
// Note: If both `rc` and `next` have the same major, we want the `rc` release-train
// to take precedence and be responsible for the `<major>.material.angular.io` deploy.
if (major > (active.releaseCandidate ?? active.latest).version.major) {
targets.push({projectId, description, site: sites.forMajor(major)});
}
await buildAndDeployWithSnapshots(serviceKey, major, targets);
return;
}
if (branchName === active.latest.branchName) {
const major = active.latest.version.major;
const targets = [
{projectId, description, site: sites.stable},
{projectId, description, site: sites.forMajor(major)},
];
// If there is no active RC train, we also push the current stable to the `rc` site.
// TODO: This can be improved by using redirects from rc -> stable.
if (active.releaseCandidate === null) {
targets.push({projectId, description, site: sites.rc});
}
await buildAndDeployWithSnapshots(serviceKey, major, targets, {
// For the stable deployment, we want to update the versions file which is loaded
// by all docs sites (archives, rc, next etc.). The source of truth for all versions
// shown in the "docs version picker" is the versions file deployed in stable.
prebuild: workspaceDir => updateVersionsFile(workspaceDir, active),
});
return;
}
if (branchName === active.releaseCandidate?.branchName) {
const major = active.releaseCandidate.version.major;
const targets = [{projectId, description, site: sites.rc}];
// If the RC is for a new major that `latest` does not publish yet, we will deploy
// the dedicated major site like `v13.material.angular.io` using the `rc` branch.
// Note: If both `rc` and `next` have the same major, we want the `rc` release-train
// to take precedence and be responsible for the `<major>.material.angular.io` deploy.
if (major > active.latest.version.major) {
targets.push({projectId, description, site: sites.forMajor(major)});
}
await buildAndDeployWithSnapshots(serviceKey, major, targets);
return;
}
// In other cases, we are potentially deploying an archived major, regardless
// of LTS being active or not.
if (!isVersionBranch(branchName)) {
console.log('Skipping deployment as the current branch is not a version branch.');
return;
}
const branchVersion = convertVersionBranchToSemVer(branchName)!;
const branchMajor = branchVersion.major;
const branchesForMajor = await getBranchesForMajorVersions(repo, [branchMajor]);
// The `branchesForMajor` array will hold the most recent version branch for current major.
// If the latest branch does not match the current one, we know that this is not the
// most recent minor and should not be re-deployed to e.g. `<major>.material.angular.io`.
if (branchesForMajor[0].name !== branchName) {
console.log(
`Skipping deployment as version branch is not the most recent ` +
`one for v${branchMajor}. Expected: ${branchesForMajor[0].name}`,
);
return;
}
await buildAndDeployWithSnapshots(serviceKey, branchMajor, [
{projectId, description, site: sites.forMajor(branchMajor)},
]);
}
try {
await main();
} catch (e) {
console.error(e);
process.exitCode = 1;
}