Skip to content

Commit

Permalink
chore: add automatic github release (#4466)
Browse files Browse the repository at this point in the history
This will automatically do a github release with the correct changelog entry and the built zip file.
If a publish is made with `--tag next` it will mark the release as a pre-release.

To use, just add `VJS_GITHUB_USER` and `VJS_GITHUB_TOKEN` env variables as part of the publish command:
```sh
$ VJS_GITHUB_USER=gkatsev VJS_GITHUB_TOKEN=test_token npm publish --tag next
```
  • Loading branch information
gkatsev authored Jul 14, 2017
1 parent 1e80e59 commit 3a600d0
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
33 changes: 33 additions & 0 deletions build/current-changelog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
var unified = require('unified');
var markdown = require('remark-parse');
var stringify = require('remark-stringify');
var fs = require('fs');

module.exports = function() {
var processor = unified()
.use(markdown, {commonmark: true})
.use(stringify);

var ast = processor.parse(fs.readFileSync('./CHANGELOG.md'));

var changelog = [];
changelog.push(processor.stringify(ast.children[0]));

// start at 1 so we get the first anchor tag
// and can break on the second
for (var i = 1; i < ast.children.length; i++) {
var item = processor.stringify(ast.children[i]);

if (/^<a name="/.test(item)) {
break;
}

if (/^###/.test(item)) {
item = '\n' + item + '\n';
}

changelog.push(item);
}

return changelog.join('\n');
};
33 changes: 33 additions & 0 deletions build/gh-release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
var ghrelease = require('gh-release');
var currentChangelog = require('./current-changelog.js');
var safeParse = require('safe-json-parse/tuple');
var pkg = require('../package.json')

var options = {
owner: 'videojs',
repo: 'video.js',
body: currentChangelog(),
assets: ['./dist/videojs-'+pkg.version+'.zip'],
endpoint: 'https://api.github.com',
auth: {
username: process.env.VJS_GITHUB_USER,
password: process.env.VJS_GITHUB_TOKEN
}
};

var tuple = safeParse(process.env.npm_config_argv);
var npmargs = tuple[0] ? [] : tuple[1].cooked;

if (npmargs.some(function(arg) { return /next/.test(arg); })) {
options.prerelease = true;
}

ghrelease(options, function(err, result) {
if (err) {
console.log('Unable to publish release to github');
console.log(err);
} else {
console.log('Publish release to github!');
console.log(result);
}
});
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"docs:fix": "remark --output -- './**/*.md'",
"babel": "babel src/js -d es5",
"prepublish": "not-in-install && run-p docs:api build || in-install",
"publish": "node build/gh-release.js",
"prepush": "npm run lint -- --errors",
"version": "node build/version.js && git add CHANGELOG.md"
},
Expand Down Expand Up @@ -78,6 +79,7 @@
"es5-shim": "^4.1.3",
"es6-shim": "^0.35.1",
"filesize": "^3.5.6",
"gh-release": "^3.0.0",
"grunt": "^0.4.5",
"grunt-accessibility": "^5.0.0",
"grunt-babel": "^6.0.0",
Expand Down Expand Up @@ -129,6 +131,8 @@
"qunitjs": "1.23.1",
"remark-cli": "^3.0.0",
"remark-lint": "^6.0.0",
"remark-parse": "^3.0.1",
"remark-stringify": "^3.0.1",
"remark-toc": "^4.0.0",
"remark-validate-links": "^6.0.0",
"replace": "^0.3.0",
Expand All @@ -147,6 +151,7 @@
"time-grunt": "^1.1.1",
"tui-jsdoc-template": "^1.1.0",
"uglify-js": "~2.8.8",
"unified": "^6.1.5",
"videojs-doc-generator": "0.0.1",
"videojs-flash": "^2.0.0",
"videojs-standard": "^6.0.1",
Expand Down

0 comments on commit 3a600d0

Please sign in to comment.