forked from vmware-archive/react-console
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease.js
executable file
·76 lines (67 loc) · 1.57 KB
/
release.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env node
'use strict';
const USER = 'autochthe';
const REPO = 'react-console';
const CHANGELOG = './CHANGELOG.md';
const ASSETS = [
'dist/dist.tar.gz',
'dist/dist.zip',
'dist/dist-min.tar.gz',
'dist/dist-min.zip',
];
const token = require('./.token.json');
const project = require('./package.json');
const changelogParser = require('changelog-parser');
const GitHubAPI = require('github');
const path = require('path');
const semver = require('semver');
// Read changelog
changelogParser(CHANGELOG, (err, result) => {
if (err) throw err;
let found = false;
for(let elem of result.versions) {
if (elem.version == project.version) {
found = true;
if(!elem.body) {
console.log('Changelog body is required');
process.exit(1);
}
createRelease(project.version, elem.body);
}
}
if(!found) {
console.log(`No changelog found for v${project.version}`);
process.exit(1);
}
})
function createRelease(version, body) {
console.log(`Creating new Github release for v${version}`);
console.log(body);
// Connect to github
let github = new GitHubAPI();
github.authenticate(token);
github.repos.createRelease({
user: USER,
repo: REPO,
tag_name: `v${version}`,
body: body,
prerelease: semver.prerelease(version)?true:false,
}, (err,res) => {
if(err) {
console.log(err);
} else {
let id = res.id;
console.log('Uploading assets')
for(let asset of ASSETS) {
github.repos.uploadAsset({
user: USER,
repo: REPO,
id: id,
name: path.basename(asset),
filePath: asset,
});
}
console.log('DONE')
}
});
}