Skip to content

Commit d96c57a

Browse files
committed
Address feedback
1 parent b7144e4 commit d96c57a

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

tools/gulp/tasks/publish.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const argv = minimist(process.argv.slice(3));
2525
task('publish', sequenceTask(
2626
':publish:whoami',
2727
':publish:build-releases',
28+
'validate-release:check-remote-tag',
2829
'validate-release:check-bundles',
2930
':publish',
3031
':publish:logout',

tools/gulp/tasks/validate-release.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@ import {join} from 'path';
44
import {green, red} from 'chalk';
55
import {releasePackages} from './publish';
66
import {sync as glob} from 'glob';
7+
import {spawnSync} from 'child_process';
78
import {buildConfig, sequenceTask} from 'material2-build-tools';
89

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;
14+
915
/** Path to the directory where all releases are created. */
10-
const releasesDir = join(buildConfig.outputDir, 'releases');
16+
const releasesDir = join(outputDir, 'releases');
1117

1218
/** RegExp that matches Angular component inline styles that contain a sourcemap reference. */
1319
const inlineStylesSourcemapRegex = /styles: ?\[["'].*sourceMappingURL=.*["']/;
@@ -17,6 +23,18 @@ const externalReferencesRegex = /(templateUrl|styleUrls): *["'[]/;
1723

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

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+
2038
/** Task that checks the release bundles for any common mistakes before releasing to the public. */
2139
task('validate-release:check-bundles', () => {
2240
const releaseFailures = releasePackages

tools/package-tools/package-version-stamp.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import {buildConfig} from './build-config';
1111
export function insertPackageJsonVersionStamp(packageJsonPath: string) {
1212
const packageJson = require(packageJsonPath);
1313

14-
packageJson['_gitCommitStamp'] = getCurrentCommitSha();
15-
packageJson['_gitBranchStamp'] = getCurrentBranchName();
14+
packageJson['releaseGitCommitSha'] = getCurrentCommitSha();
15+
packageJson['releaseGitBranch'] = getCurrentBranchName();
16+
packageJson['releaseGitUser'] = getCurrentGitUser();
1617

1718
writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
1819
}
@@ -28,3 +29,14 @@ function getCurrentBranchName(): string {
2829
return spawnSync('git', ['symbolic-ref', '--short', 'HEAD'], {cwd: buildConfig.projectDir})
2930
.stdout.toString().trim();
3031
}
32+
33+
/** Returns the name and email of the Git user that creates this release build. */
34+
function getCurrentGitUser() {
35+
const userName = spawnSync('git', ['config', 'user.name'], {cwd: buildConfig.projectDir})
36+
.stdout.toString().trim();
37+
38+
const userEmail = spawnSync('git', ['config', 'user.email'], {cwd: buildConfig.projectDir})
39+
.stdout.toString().trim();
40+
41+
return `${userName} <${userEmail}>`;
42+
}

0 commit comments

Comments
 (0)