2019-10-09 20:31:42 +00:00
|
|
|
const packageJson = require('../package.json');
|
|
|
|
const glob = require('fast-glob');
|
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
|
|
|
const packageTask = require('./package');
|
|
|
|
const buildTask = require('./build');
|
|
|
|
const Octokit = require('@octokit/rest');
|
|
|
|
|
|
|
|
// Configure Octokit
|
|
|
|
const octokit = new Octokit({
|
|
|
|
auth: process.env.GITHUB_TOKEN,
|
|
|
|
});
|
|
|
|
|
2019-10-10 17:29:49 +00:00
|
|
|
const OWNER = 'getinsomnia';
|
|
|
|
const REPO = 'insomnia';
|
|
|
|
|
2019-10-09 20:31:42 +00:00
|
|
|
// Start package if ran from CLI
|
|
|
|
if (require.main === module) {
|
2019-10-10 19:17:42 +00:00
|
|
|
if (!process.env.GITHUB_REF.match(/v\d+\.\d+\.\d+(-(beta|alpha)\.\d+)?$/)) {
|
2019-10-09 20:31:42 +00:00
|
|
|
console.log(`[release] Not running release for ref ${process.env.GITHUB_REF}`);
|
|
|
|
process.exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
process.nextTick(async () => {
|
|
|
|
try {
|
|
|
|
await buildTask.start();
|
|
|
|
await packageTask.start();
|
|
|
|
await start();
|
|
|
|
} catch (err) {
|
|
|
|
console.log('[package] ERROR:', err);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function start() {
|
|
|
|
const tagName = `v${packageJson.app.version}`;
|
|
|
|
console.log(`[release] Creating release ${tagName}`);
|
|
|
|
|
|
|
|
const globs = {
|
|
|
|
darwin: ['dist/**/*.zip', 'dist/**/*.dmg'],
|
|
|
|
win32: ['dist/squirrel-windows/*'],
|
|
|
|
linux: [
|
|
|
|
'dist/**/*.snap',
|
|
|
|
'dist/**/*.rpm',
|
|
|
|
'dist/**/*.deb',
|
|
|
|
'dist/**/*.AppImage',
|
|
|
|
'dist/**/*.tar.gz',
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
const paths = await glob(globs[process.platform]);
|
|
|
|
|
|
|
|
const { data } = await getOrCreateRelease(tagName);
|
|
|
|
|
|
|
|
for (const p of paths) {
|
|
|
|
const name = path.basename(p);
|
|
|
|
console.log(`[release] Uploading ${p}`);
|
|
|
|
await octokit.request({
|
|
|
|
method: 'POST',
|
|
|
|
url: 'https://uploads.github.com/repos/:owner/:repo/releases/:id/assets{?name,label}"',
|
|
|
|
id: data.id,
|
|
|
|
name: name,
|
2019-10-10 17:29:49 +00:00
|
|
|
owner: OWNER,
|
|
|
|
repo: REPO,
|
2019-10-09 20:31:42 +00:00
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/octet-stream',
|
|
|
|
},
|
|
|
|
data: fs.readFileSync(p),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(`[release] Release created ${data.url}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getOrCreateRelease(tagName) {
|
|
|
|
try {
|
|
|
|
return await octokit.repos.getReleaseByTag({
|
2019-10-10 17:29:49 +00:00
|
|
|
owner: OWNER,
|
|
|
|
repo: REPO,
|
2019-10-09 20:31:42 +00:00
|
|
|
tag: tagName,
|
|
|
|
});
|
|
|
|
} catch (err) {
|
|
|
|
// Doesn't exist
|
|
|
|
}
|
|
|
|
|
|
|
|
return octokit.repos.createRelease({
|
2019-10-10 17:29:49 +00:00
|
|
|
owner: OWNER,
|
|
|
|
repo: REPO,
|
2019-10-09 20:31:42 +00:00
|
|
|
tag_name: tagName,
|
|
|
|
name: tagName,
|
2019-10-18 14:48:39 +00:00
|
|
|
body: `Full changelog ⇒ https://insomnia.rest/changelog/${packageJson.app.version}`,
|
2019-10-09 20:31:42 +00:00
|
|
|
draft: false,
|
|
|
|
preRelease: true,
|
|
|
|
});
|
|
|
|
}
|