Skip to content
This repository has been archived by the owner on Jan 6, 2025. It is now read-only.

Commit

Permalink
build: switch release methods (#710)
Browse files Browse the repository at this point in the history
  • Loading branch information
CaerusKaru committed May 3, 2018
1 parent 7993e7c commit 93871d6
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 16 deletions.
1 change: 1 addition & 0 deletions tools/gulp/gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ createPackageBuildTasks(flexLayoutPackage);
import './tasks/aot';
import './tasks/build-release'; // release build `github.com/angular/flex-layout-builds`
import './tasks/clean';
import './tasks/changelog';
import './tasks/ci';
import './tasks/default';
import './tasks/development';
Expand Down
2 changes: 1 addition & 1 deletion tools/gulp/tasks/changelog.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {task, src, dest} from 'gulp';
import {buildConfig} from 'material2-build-tools';
import {buildConfig} from 'lib-build-tools';
import {join} from 'path';
import {yellow, red} from 'chalk';

Expand Down
41 changes: 31 additions & 10 deletions tools/gulp/tasks/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ export const releasePackages = [
'flex-layout'
];

/** Regular Expression that matches valid version numbers of Angular Material. */
export const validVersionRegex = /^\d+\.\d+\.\d+(-(alpha|beta|rc)\.\d+)?$/;

/** Parse command-line arguments for release task. */
const argv = minimist(process.argv.slice(3));

Expand All @@ -38,22 +41,40 @@ task(':publish:whoami', execTask('npm', ['whoami'], {
task(':publish:logout', execTask('npm', ['logout']));

task(':publish', async () => {
const label = argv['tag'];
const tag = argv['tag'];
const version = buildConfig.projectVersion;
const currentDir = process.cwd();

if (!version.match(validVersionRegex)) {
console.log(red(`Error: Cannot publish due to an invalid version name. Version "${version}" ` +
`is not following our semver format.`));
console.log(yellow(`A version should follow this format: d.d.d, d.d.d-beta.x, d.d.d-alpha.x, ` +
`d.d.d-rc.x`));
return;
}

console.log('');
if (!label) {
console.log(yellow('You can use a label with --tag=labelName.'));
console.log(yellow(`Publishing version ${version} using the latest tag.`));
if (!tag) {
console.log(grey('> You can specify the tag by passing --tag=labelName.\n'));
console.log(green(`Publishing version "${version}" to the latest tag...`));
} else {
console.log(yellow(`Publishing ${version} using the ${label} tag.`));
console.log(yellow(`Publishing version "${version}" to the ${tag} tag...`));
}
console.log('');


// TODO(CaerusKaru): uncomment when Layout exits beta/rc
// if (version.match(/(alpha|beta|rc)/) && (!tag || tag === 'latest')) {
// console.log(red(`Publishing ${version} to the "latest" tag is not allowed.`));
// console.log(red(`Alpha, Beta or RC versions shouldn't be published to "latest".`));
// console.log();
// return;
// }

if (releasePackages.length > 1) {
console.warn(red('Warning: Multiple packages will be released if proceeding.'));
console.warn(red('Warning: Packages to be released: ', releasePackages.join(', ')));
console.warn(red('Warning: Packages to be released:', releasePackages.join(', ')));
console.log();
}

console.log(yellow('> Make sure to check the "angularVersion" in the build config.'));
Expand All @@ -62,13 +83,13 @@ task(':publish', async () => {

// Iterate over every declared release package and publish it on NPM.
for (const packageName of releasePackages) {
await _execNpmPublish(label, packageName);
await _execNpmPublish(tag, packageName);
}

process.chdir(currentDir);
});

function _execNpmPublish(label: string, packageName: string): Promise<{}> | undefined {
function _execNpmPublish(tag: string, packageName: string): Promise<{}> | undefined {
const packageDir = join(buildConfig.outputDir, 'releases', packageName);

if (!statSync(packageDir).isDirectory()) {
Expand All @@ -89,8 +110,8 @@ function _execNpmPublish(label: string, packageName: string): Promise<{}> | unde
const command = 'npm';
const args = ['publish', '--access', 'public'];

if (label) {
args.push('--tag', label);
if (tag) {
args.push('--tag', tag);
}

return new Promise((resolve, reject) => {
Expand Down
18 changes: 13 additions & 5 deletions tools/gulp/tasks/validate-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {readFileSync} from 'fs';
import {join} from 'path';
import {green, red} from 'chalk';
import {releasePackages} from './publish';
import {sync as glob} from 'glob';
import {buildConfig, sequenceTask} from 'lib-build-tools';


/** Path to the directory where all releases are created. */
const releasesDir = join(buildConfig.outputDir, 'releases');

Expand Down Expand Up @@ -37,9 +37,19 @@ task('validate-release:check-bundles', () => {

/** Task that validates the given release package before releasing. */
function checkReleasePackage(packageName: string): string[] {
const bundlePath = join(releasesDir, packageName, '@angular', `${packageName}.js`);
return glob(join(releasesDir, packageName, 'esm2015/*.js'))
.reduce((failures: string[], bundlePath: string) => {
return failures.concat(checkEs2015ReleaseBundle(bundlePath));
}, []);
}

/**
* Checks an ES2015 bundle inside of a release package. Secondary entry-point bundles will be
* checked as well.
*/
function checkEs2015ReleaseBundle(bundlePath: string): string[] {
const bundleContent = readFileSync(bundlePath, 'utf8');
let failures = [];
let failures: string[] = [];

if (inlineStylesSourcemapRegex.exec(bundleContent) !== null) {
failures.push('Bundles contain sourcemap references in component styles.');
Expand All @@ -52,5 +62,3 @@ function checkReleasePackage(packageName: string): string[] {
return failures;
}



0 comments on commit 93871d6

Please sign in to comment.