Skip to content

Commit d74f94c

Browse files
devversionjelbourn
authored andcommitted
build: run publish sanity checks before building (#13060)
Runs the publish sanity checks before building the release output of Angular Material. Building the release output is very time consuming, and therefore the sanity checks should run before. Closes #12918
1 parent 0a25fca commit d74f94c

File tree

5 files changed

+66
-42
lines changed

5 files changed

+66
-42
lines changed

tools/gulp/gulpfile.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@ import './tasks/unit-test';
3333
import './tasks/universal';
3434

3535
import './tasks/publish/publish-task';
36+
import './tasks/publish/sanity-checks';
3637
import './tasks/publish/validate-release';

tools/gulp/tasks/publish/branch-check.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {spawnSync} from 'child_process';
22
import {buildConfig} from 'material2-build-tools';
33

44
/** Regular expression that matches version names and the individual version segments. */
5-
export const versionNameRegex = /^(\d+)\.(\d+)\.(\d+)(?:-(alpha|beta|rc)\.(\d)+)?/;
5+
export const versionNameRegex = /^(\d+)\.(\d+)\.(\d+)(?:-(alpha|beta|rc)\.(\d)+)?$/;
66

77
/** Checks if the specified version can be released from the current Git branch. */
88
export function checkPublishBranch(version: string) {

tools/gulp/tasks/publish/publish-task.ts

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import {green, grey, red, yellow} from 'chalk';
1+
import {green, grey, yellow} from 'chalk';
22
import {spawn} from 'child_process';
33
import {existsSync, statSync} from 'fs-extra';
44
import {task} from 'gulp';
55
import {buildConfig, sequenceTask} from 'material2-build-tools';
66
import * as minimist from 'minimist';
77
import {join} from 'path';
88
import {execTask} from '../../util/task_helpers';
9-
import {checkPublishBranch, versionNameRegex} from './branch-check';
109

1110
/** Packages that will be published to NPM by the release task. */
1211
export const releasePackages = [
@@ -21,9 +20,9 @@ export const releasePackages = [
2120
const argv = minimist(process.argv.slice(3));
2221

2322
task('publish', sequenceTask(
23+
':publish:sanity-checks',
2424
':publish:whoami',
2525
':publish:build-releases',
26-
'validate-release:check-remote-tag',
2726
'validate-release:check-bundles',
2827
':publish',
2928
':publish:logout',
@@ -48,14 +47,6 @@ task(':publish', async () => {
4847
const version = buildConfig.projectVersion;
4948
const currentDir = process.cwd();
5049

51-
if (!version.match(versionNameRegex)) {
52-
console.error(red(`Error: Cannot publish due to an invalid version name. Version ` +
53-
`"${version}" is not following our semver format.`));
54-
console.error(yellow(`A version should follow this format: X.X.X, X.X.X-beta.X, ` +
55-
`X.X.X-alpha.X, X.X.X-rc.X`));
56-
return;
57-
}
58-
5950
console.log();
6051
if (!tag) {
6152
console.log(grey('> You can specify the tag by passing --tag=labelName.\n'));
@@ -65,21 +56,12 @@ task(':publish', async () => {
6556
}
6657
console.log();
6758

68-
if (version.match(/(alpha|beta|rc)/) && (!tag || tag === 'latest')) {
69-
console.error(red(`Publishing ${version} to the "latest" tag is not allowed.`));
70-
console.error(red(`Alpha, Beta or RC versions shouldn't be published to "latest".`));
71-
console.error();
72-
return;
73-
}
74-
7559
if (releasePackages.length > 1) {
7660
console.warn(yellow('Warning: Multiple packages will be released.'));
7761
console.warn(yellow('Warning: Packages to be released:', releasePackages.join(', ')));
7862
console.warn();
7963
}
8064

81-
checkPublishBranch(version);
82-
8365
console.log(yellow('> Make sure to check the "requiredAngularVersion" in the package.json.'));
8466
console.log(yellow('> The version in the config defines the peer dependency of Angular.'));
8567
console.log();
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import {red} from 'chalk';
2+
import {spawnSync} from 'child_process';
3+
import {task} from 'gulp';
4+
import {buildConfig} from 'material2-build-tools';
5+
import * as minimist from 'minimist';
6+
import {checkPublishBranch, versionNameRegex} from './branch-check';
7+
8+
const {projectDir, projectVersion} = buildConfig;
9+
10+
/** Git repository URL that has been read out from the project package.json file. */
11+
const repositoryGitUrl = require('../../../../package.json').repository.url;
12+
13+
/** Parse command-line arguments for release task. */
14+
const argv = minimist(process.argv.slice(3));
15+
16+
/** Task that runs various sanity checks before publishing. */
17+
task(':publish:sanity-checks', [
18+
':publish:check-project-version',
19+
':publish:check-remote-tag',
20+
':publish:check-publish-branch',
21+
]);
22+
23+
/** Task that checks the new project version. */
24+
task(':publish:check-project-version', () => {
25+
const tag = argv['tag'];
26+
27+
if (!projectVersion.match(versionNameRegex)) {
28+
console.error(red(`Error: Cannot publish due to an invalid version name. Version ` +
29+
`"${projectVersion}" is not following our semver format.`));
30+
console.error(red(`A version should follow this format: X.X.X, X.X.X-beta.X, ` +
31+
`X.X.X-alpha.X, X.X.X-rc.X`));
32+
process.exit(1);
33+
}
34+
35+
if (projectVersion.match(/(alpha|beta|rc)/) && (!tag || tag === 'latest')) {
36+
console.error(red(`Publishing ${projectVersion} to the "latest" tag is not allowed.`));
37+
console.error(red(`Alpha, Beta or RC versions shouldn't be published to "latest".`));
38+
process.exit(1);
39+
}
40+
});
41+
42+
/** Task that verifies that the new version can be published from the current branch. */
43+
task(':publish:check-publish-branch', () => checkPublishBranch(projectVersion));
44+
45+
/** Task that ensures that the new release tagged on GitHub before publishing to NPM. */
46+
task(':publish:check-remote-tag', () => {
47+
// Since we cannot assume that every developer uses `origin` as the default name for the upstream
48+
// remote, we just pass in the Git URL that refers to angular/material2 repository on Github.
49+
const tagCommitSha = spawnSync('git', ['ls-remote', '--tags', repositoryGitUrl, projectVersion],
50+
{cwd: projectDir}).stdout.toString().trim();
51+
52+
if (!tagCommitSha) {
53+
console.error(red(`Cannot publish v${projectVersion} because the release is not ` +
54+
`tagged on upstream yet. Please tag the release before publishing to NPM.`));
55+
process.exit(1);
56+
}
57+
});

tools/gulp/tasks/publish/validate-release.ts

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
import {task} from 'gulp';
2-
import {readFileSync, existsSync} from 'fs';
3-
import {join} from 'path';
41
import {green, red} from 'chalk';
5-
import {releasePackages} from './publish-task';
2+
import {existsSync, readFileSync} from 'fs';
63
import {sync as glob} from 'glob';
7-
import {spawnSync} from 'child_process';
4+
import {task} from 'gulp';
85
import {buildConfig, sequenceTask} from 'material2-build-tools';
6+
import {join} from 'path';
7+
import {releasePackages} from './publish-task';
98

10-
const {projectDir, projectVersion, outputDir} = buildConfig;
11-
12-
/** Git repository URL that has been read out from the project package.json file. */
13-
const repositoryGitUrl = require('../../../../package.json').repository.url;
9+
const {outputDir} = buildConfig;
1410

1511
/** Path to the directory where all releases are created. */
1612
const releasesDir = join(outputDir, 'releases');
@@ -23,18 +19,6 @@ const externalReferencesRegex = /(templateUrl|styleUrls): *["'[]/;
2319

2420
task('validate-release', sequenceTask(':publish:build-releases', 'validate-release:check-bundles'));
2521

26-
task('validate-release:check-remote-tag', () => {
27-
// Since we cannot assume that every developer uses `origin` as the default name for the upstream
28-
// remote, we just pass in the Git URL that refers to angular/material2 repository on Github.
29-
const tagCommitSha = spawnSync('git', ['ls-remote', '--tags', repositoryGitUrl, projectVersion],
30-
{cwd: projectDir}).stdout.toString().trim();
31-
32-
if (!tagCommitSha) {
33-
throw Error(red(`Cannot publish v${projectVersion} because the release is not ` +
34-
`tagged on upstream yet. Please tag the release before publishing to NPM.`));
35-
}
36-
});
37-
3822
/** Task that checks the release bundles for any common mistakes before releasing to the public. */
3923
task('validate-release:check-bundles', () => {
4024
const releaseFailures = releasePackages

0 commit comments

Comments
 (0)