Skip to content

Commit d3235c9

Browse files
devversionmmalerba
authored andcommitted
build: ensure angular version placeholder is up-to-date when staging release (#17465)
Ensures that the Angular version placeholder is properly updated when staging the release. We perform this as part of the staging script, since changes between staging and publishing are *not* expected and this is enforced by the publish script. Additionally, the rules are very strict. If something ever changes due to unknown reasons, the peer dependency checks needs to be disabled manually / or updated.
1 parent fc7288f commit d3235c9

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

tools/release/stage-release.ts

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as OctokitApi from '@octokit/rest';
22
import chalk from 'chalk';
3-
import {readFileSync, writeFileSync} from 'fs';
3+
import {existsSync, readFileSync, writeFileSync} from 'fs';
44
import {join} from 'path';
55
import {BaseReleaseTask} from './base-release-task';
66
import {promptAndGenerateChangelog} from './changelog';
@@ -12,6 +12,9 @@ import {parseVersionName, Version} from './version-name/parse-version';
1212
/** Default filename for the changelog. */
1313
export const CHANGELOG_FILE_NAME = 'CHANGELOG.md';
1414

15+
/** Path to the Bazel file that configures the release output. */
16+
const BAZEL_RELEASE_CONFIG_PATH = './packages.bzl';
17+
1518
/**
1619
* Class that can be instantiated in order to stage a new release. The tasks requires user
1720
* interaction/input through command line prompts.
@@ -89,6 +92,7 @@ class StageReleaseTask extends BaseReleaseTask {
8992
const publishBranch = this.switchToPublishBranch(newVersion);
9093

9194
this.verifyLocalCommitsMatchUpstream(publishBranch);
95+
this._verifyAngularPeerDependencyVersion(newVersion);
9296
await this._verifyPassingGithubStatus(publishBranch);
9397

9498
if (!this.git.checkoutNewBranch(stagingBranch)) {
@@ -147,6 +151,52 @@ class StageReleaseTask extends BaseReleaseTask {
147151
writeFileSync(this.packageJsonPath, JSON.stringify(newPackageJson, null, 2) + '\n');
148152
}
149153

154+
/**
155+
* Ensures that the Angular version placeholder has been correctly updated to support
156+
* given Angular versions. The following rules apply:
157+
* `N.x.x` requires Angular `^N.0.0 || (N+1).0.0-0`
158+
* `N.0.0-x` requires Angular `^N.0.0-0 || (N+1).0.0-0`
159+
*/
160+
private _verifyAngularPeerDependencyVersion(newVersion: Version) {
161+
const currentVersionRange = this._getAngularVersionPlaceholderOrExit();
162+
const isMajorWithPrerelease = newVersion.minor === 0 && newVersion.patch === 0 &&
163+
newVersion.prereleaseLabel !== null;
164+
const requiredRange = isMajorWithPrerelease ?
165+
`^${newVersion.major}.0.0-0 || ^${newVersion.major + 1}.0.0-0` :
166+
`^${newVersion.major}.0.0 || ^${newVersion.major + 1}.0.0-0`;
167+
168+
if (requiredRange !== currentVersionRange) {
169+
console.error(chalk.red(` ✘ Cannot stage release. The required Angular version range ` +
170+
`is invalid. The version range should be: ${requiredRange}`));
171+
console.error(chalk.red(` Please manually update the version range ` +
172+
`in: ${BAZEL_RELEASE_CONFIG_PATH}`));
173+
return process.exit(1);
174+
}
175+
}
176+
177+
/**
178+
* Gets the Angular version placeholder from the bazel release config. If
179+
* the placeholder could not be found, the process will be terminated.
180+
*/
181+
private _getAngularVersionPlaceholderOrExit(): string {
182+
const bzlConfigPath = join(this.projectDir, BAZEL_RELEASE_CONFIG_PATH);
183+
if (!existsSync(bzlConfigPath)) {
184+
console.error(chalk.red(` ✘ Cannot stage release. Could not find the file which sets ` +
185+
`the Angular peerDependency placeholder value. Looked for: ${bzlConfigPath}`));
186+
return process.exit(1);
187+
}
188+
189+
const configFileContent = readFileSync(bzlConfigPath, 'utf8');
190+
const matches = configFileContent.match(/ANGULAR_PACKAGE_VERSION = ["']([^"']+)/);
191+
if (!matches || !matches[1]) {
192+
console.error(chalk.red(` ✘ Cannot stage release. Could not find the ` +
193+
`"ANGULAR_PACKAGE_VERSION" variable. Please ensure this variable exists. ` +
194+
`Looked in: ${bzlConfigPath}`));
195+
return process.exit(1);
196+
}
197+
return matches[1];
198+
}
199+
150200
/** Verifies that the latest commit of the current branch is passing all Github statuses. */
151201
private async _verifyPassingGithubStatus(expectedPublishBranch: string) {
152202
const commitRef = this.git.getLocalCommitSha('HEAD');

0 commit comments

Comments
 (0)