Skip to content

Commit

Permalink
Improve the release pipeline (#31)
Browse files Browse the repository at this point in the history
* add changelog file to the root

* add npm install instructions

* add release scripts

* improve the release scripts

* use origin and master as github references

* fix changelog release 0.1.0 link

* add the publish script

* stop building docs before npm publishing
  • Loading branch information
lbalmaceda authored Aug 14, 2020
1 parent e84aa1e commit 9f0a70b
Show file tree
Hide file tree
Showing 13 changed files with 260 additions and 33 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.

# release pipeline tmp files
.release*/
.release

# compiled output
/dist
/tmp
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Change Log

## [v0.1.0](https://github.com/auth0/auth0-angular/tree/v0.1.0) (2020-07-31)

**Early Access Release**
Do not use it in a Production environment.

### Installation

In order to install this package on your application, download the `auth0-auth0-angular-0.1.0.tgz` file from the Releases section on the Github repository and run the following command:

```bash
npm install /path/to/auth0-auth0-angular-0.1.0.tgz
```
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,12 @@ A library for integrating [Auth0](https://auth0.com) into an Angular 9+ applicat

## Installation

The package is still not available on the NPM public registry.
Using npm:

In order to install it, visit the [RELEASES](https://github.com/auth0/auth0-angular/releases) section, download the `.tgz` file, and run the following `npm` command:

```
npm install /path/to/auth0-auth0-angular-x.y.z.tgz
```sh
npm install @auth0/auth0-angular
```

Make sure the path and filename matches the file you've downloaded.

## Getting Started

- [Register the authentication module](#register-the-authentication-module)
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@
"scripts": {
"ng": "ng",
"start": "ng serve",
"prebuid": "npm run update-useragent",
"prebuild": "npm run update-useragent",
"build": "ng build",
"build:prod": "ng build --prod",
"prepublishOnly": "node scripts/prepublish-stopper.js",
"postbuild": "npm run docs",
"test": "ng test",
"test-ci": "ng test --no-watch --no-progress --browsers=ChromeHeadlessCI --codeCoverage=true",
"lint": "ng lint",
"docs": "typedoc",
"e2e": "ng e2e",
"pretty-quick": "pretty-quick",
"release": "node scripts/release.js",
"release:publish": "node scripts/publish.js",
"release:clean": "node scripts/cleanup.js",
"update-useragent": "node projects/auth0-angular/scripts/update-useragent.js"
},
"private": true,
Expand All @@ -34,10 +39,10 @@
"@angular-devkit/build-ng-packagr": "^0.1000.4",
"@angular/cli": "^10.0.4",
"@angular/compiler-cli": "^10.0.5",
"@angular/forms": "^10.0.5",
"@types/jasmine": "~3.5.0",
"@types/jasminewd2": "~2.0.3",
"@types/node": "^12.12.53",
"@angular/forms": "^10.0.5",
"codecov": "^3.7.2",
"codelyzer": "^6.0.0-next.1",
"husky": "^4.2.5",
Expand All @@ -49,6 +54,7 @@
"karma-jasmine": "~3.3.0",
"karma-jasmine-html-reporter": "^1.5.0",
"karma-junit-reporter": "^2.0.1",
"moment": "^2.27.0",
"ng-packagr": "^10.0.3",
"prettier": "^2.0.5",
"pretty-quick": "^2.0.1",
Expand Down
24 changes: 0 additions & 24 deletions projects/auth0-angular/README.md

This file was deleted.

3 changes: 3 additions & 0 deletions projects/auth0-angular/scripts/update-useragent.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const fs = require('fs');
const pkg = require('../package.json');

console.log(
`Updating the "useragent.ts" file using name=${pkg.name} and version=${pkg.version}`
);
fs.writeFileSync(
'projects/auth0-angular/src/useragent.ts',
`export default { name: '${pkg.name}', version: '${pkg.version}' };
Expand Down
62 changes: 62 additions & 0 deletions scripts/changelog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
if (process.platform === 'win32') {
console.error('Must be run on a Unix OS');
process.exit(1);
}

const fs = require('fs');
const path = require('path');
const execSync = require('child_process').execSync;
const moment = require('moment');

module.exports = function (newVersion) {
return new Promise((resolve, reject) => {
const tmp = fs.readFileSync('.release', 'utf-8');

const currentVersion = fs.readFileSync(
path.resolve(tmp, 'current-version'),
'utf-8'
);

const repo = 'auth0-angular';
const changelogPath = path.resolve(tmp, 'CHANGELOG.md');
const stream = fs.createWriteStream(changelogPath);
const webtask = `https://webtask.it.auth0.com/api/run/wt-hernan-auth0_com-0/oss-changelog.js?webtask_no_cache=1&repo=${repo}&milestone=v${newVersion}`;
const command = `curl -f -s -H "Accept: text/markdown" "${webtask}"`;
const changes = execSync(command, { encoding: 'utf-8' });

const previous = execSync(
'sed "s/# Change Log//" CHANGELOG.md | sed \'1,2d\''
);

stream.once('open', function (fd) {
stream.write('# Change Log');
stream.write('\n');
stream.write('\n');

stream.write(
`## [v${newVersion}](https://github.com/auth0/${repo}/tree/v${newVersion}) (${moment().format(
'YYYY-MM-DD'
)})`
);

stream.write('\n');

stream.write(
`[Full Changelog](https://github.com/auth0/${repo}/compare/v${currentVersion}...v${newVersion})`
);

stream.write('\n');
stream.write(changes);
stream.write('\n');
stream.write(previous);
stream.end();
});

stream.once('close', function (fd) {
execSync(`mv ${changelogPath} CHANGELOG.md`, {
stdio: 'inherit',
});
resolve();
});
});
};
23 changes: 23 additions & 0 deletions scripts/cleanup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const execSync = require('child_process').execSync;
const fs = require('fs');

if (fs.existsSync('dist')) {
execSync(`rm -r dist`, { stdio: 'inherit' });
}

if (fs.existsSync('coverage')) {
execSync(`rm -r coverage`, { stdio: 'inherit' });
}

if (!fs.existsSync('.release')) {
console.log('No in progress release found');
process.exit(0);
}

const tmp = fs.readFileSync('.release');

if (fs.existsSync(tmp)) {
execSync(`rm -r ${tmp}`, { stdio: 'inherit' });
}

execSync(`rm -r .release`, { stdio: 'inherit' });
12 changes: 12 additions & 0 deletions scripts/exec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const exec = require('child_process').exec;

module.exports = (cmd) => {
return new Promise((resolve, reject) => {
exec(cmd, (error, stdout, stderr) => {
if (error) {
reject(error);
}
resolve(stdout ? stdout : stderr);
});
});
};
6 changes: 6 additions & 0 deletions scripts/prepublish-stopper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const ALLOWED = !!process.env.ALLOWED;

if (!ALLOWED) {
console.log('Run `npm run release:publish` to publish the package');
process.exit(1); //which terminates the publish process
}
47 changes: 47 additions & 0 deletions scripts/publish.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const fs = require('fs');
const exec = require('./exec');
const execSync = require('child_process').execSync;
const path = require('path');
const { syncBuiltinESMExports } = require('module');

if (!fs.existsSync('.release')) {
console.error(`There's no release pending publication.`);
process.exit(1);
}

const tmp = fs.readFileSync('.release', 'utf-8');
const versionFilePath = path.resolve(tmp, 'current-version');
const unpublishedFilePath = path.resolve(tmp, 'unpublished');

if (!fs.existsSync(unpublishedFilePath) || !fs.existsSync(versionFilePath)) {
console.error(
`The last release preparation did not complete successfully. Run 'npm run release:clean' and then 'npm run release' to start all over again.`
);
console.info(
`If the Release PR was already merged into the base branch and only the npm publication is pending, manually run 'npm run build:prod' and then 'ALLOWED=true npm publish ./dist/auth0-angular'.`
);
process.exit(1);
}

const currentVersion = fs.readFileSync(versionFilePath, 'utf-8');

(async () => {
console.log('Preparing the package for publication...');
await exec(`git checkout v${currentVersion}`);

/*
The command below ensures the ./dist folder has prod-ready content.
It will NOT regenerate the docs nor the useragent file, which
should already be updated as part of the last tagged commit.
*/
await exec('npm run build:prod');

console.log('Uploading to npm, you might be prompted for the OTP...');

execSync(`ALLOWED=true npm publish ./dist/auth0-angular`, {
stdio: 'inherit',
});

console.log('Done!');
await exec('npm run release:clean');
})();
72 changes: 72 additions & 0 deletions scripts/release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
const fs = require('fs');
const exec = require('./exec');
const writeChangelog = require('./changelog');
const path = require('path');
const tmp = fs.mkdtempSync(`.release-tmp-`);
const libPkg = require('../projects/auth0-angular/package.json');

if (!fs.existsSync('.release')) {
fs.writeFileSync('.release', tmp);
} else {
console.error('Found a pending release. Please run `npm run release:clean`');
process.exit(1);
}

const newVersion = process.argv[2];
if (!newVersion) {
throw new Error('usage: `release new_version [branch]`');
}

var lastVersionFile = path.resolve(tmp, 'current-version');
fs.writeFileSync(lastVersionFile, libPkg.version);

const branch = process.argv[3] || 'master';

(async () => {
if (branch) {
await exec(`git checkout ${branch}`);
}

await exec('git pull origin master');
await exec(`git checkout -b prepare/${newVersion}`);

const newReadme = fs
.readFileSync('./README.md')
.toString()
.replace(libPkg.version, newVersion);

fs.writeFileSync('./README.md', newReadme);

fs.writeFileSync(
'./projects/auth0-angular/package.json',
JSON.stringify({ ...libPkg, version: newVersion }, null, 2)
);

/*
This will take care of:
1. Updating the user agent version
2. Build the app and ensure there are no errors.
3. Generating the docs
*/
console.log('Building the library...');
await exec('npm run build');

console.log('Fetching the next version changelog...');
await writeChangelog(newVersion);

console.log('Committing files and creating the tag...');
await exec('git add ./projects/auth0-angular/package.json');
await exec('git add ./projects/auth0-angular/src/useragent.ts');
await exec('git add ./README.md');
await exec('git add ./CHANGELOG.md');
await exec('git add ./docs/');
await exec(`git commit -am 'Release v${newVersion}'`);
await exec(`git tag v${newVersion}`);

var unpublishedFile = path.resolve(tmp, 'unpublished');
fs.closeSync(fs.openSync(unpublishedFile, 'w'));

console.log(
'Done! If the diff looks OK, push the changes along with the new tag using "git push origin master --tags". Once the PR is merged, come back and run "npm run release:publish".'
);
})();

0 comments on commit 9f0a70b

Please sign in to comment.