2020-04-26 20:33:39 +00:00
|
|
|
const { appConfig } = require('../config');
|
2019-10-09 20:31:42 +00:00
|
|
|
const glob = require('fast-glob');
|
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
|
|
|
const packageTask = require('./package');
|
|
|
|
const buildTask = require('./build');
|
2020-04-26 20:33:39 +00:00
|
|
|
const { Octokit } = require('@octokit/rest');
|
2019-10-09 20:31:42 +00:00
|
|
|
|
|
|
|
// Configure Octokit
|
|
|
|
const octokit = new Octokit({
|
2020-04-26 20:33:39 +00:00
|
|
|
auth: process.env.GH_TOKEN,
|
2019-10-09 20:31:42 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Start package if ran from CLI
|
|
|
|
if (require.main === module) {
|
|
|
|
process.nextTick(async () => {
|
|
|
|
try {
|
2020-08-24 20:40:40 +00:00
|
|
|
const buildContext = await buildTask.start(true);
|
2019-10-09 20:31:42 +00:00
|
|
|
await packageTask.start();
|
2020-04-26 20:33:39 +00:00
|
|
|
await start(buildContext.app, buildContext.version);
|
2019-10-09 20:31:42 +00:00
|
|
|
} catch (err) {
|
2020-08-24 20:40:40 +00:00
|
|
|
console.log('[release] ERROR:', err);
|
2019-10-09 20:31:42 +00:00
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-04-26 20:33:39 +00:00
|
|
|
async function start(app, version) {
|
|
|
|
console.log(`[release] Creating release for ${app} ${version}`);
|
2020-08-22 05:59:56 +00:00
|
|
|
const appId = appConfig().appId;
|
|
|
|
const distGlob = ext => path.join('dist', appId, '**', `*${ext}`);
|
2019-10-09 20:31:42 +00:00
|
|
|
|
2020-04-26 20:33:39 +00:00
|
|
|
const assetGlobs = {
|
2020-08-22 05:59:56 +00:00
|
|
|
darwin: [distGlob('.zip'), distGlob('.dmg')],
|
|
|
|
win32: [path.join('dist', appId, 'squirrel-windows', '*')],
|
2019-10-09 20:31:42 +00:00
|
|
|
linux: [
|
2020-08-22 05:59:56 +00:00
|
|
|
distGlob('.snap'),
|
|
|
|
distGlob('.rpm'),
|
|
|
|
distGlob('.deb'),
|
|
|
|
distGlob('.AppImage'),
|
|
|
|
distGlob('.tar.gz'),
|
2019-10-09 20:31:42 +00:00
|
|
|
],
|
|
|
|
};
|
|
|
|
|
2020-04-26 20:33:39 +00:00
|
|
|
const paths = await glob(assetGlobs[process.platform]);
|
2019-10-09 20:31:42 +00:00
|
|
|
|
2020-04-26 20:33:39 +00:00
|
|
|
const { data } = await getOrCreateRelease(app, version);
|
2019-10-09 20:31:42 +00:00
|
|
|
|
|
|
|
for (const p of paths) {
|
|
|
|
const name = path.basename(p);
|
2020-04-26 20:33:39 +00:00
|
|
|
|
|
|
|
console.log(`[release] Uploading ${name}`);
|
2019-10-09 20:31:42 +00:00
|
|
|
await octokit.request({
|
|
|
|
method: 'POST',
|
|
|
|
url: 'https://uploads.github.com/repos/:owner/:repo/releases/:id/assets{?name,label}"',
|
|
|
|
id: data.id,
|
|
|
|
name: name,
|
2020-04-26 20:33:39 +00:00
|
|
|
owner: appConfig().githubOrg,
|
|
|
|
repo: appConfig().githubRepo,
|
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}`);
|
|
|
|
}
|
|
|
|
|
2020-04-26 20:33:39 +00:00
|
|
|
async function getOrCreateRelease(app, version) {
|
|
|
|
const tag = `${app}@${version}`;
|
|
|
|
const releaseName = `${appConfig().productName} ${version} 📦`;
|
|
|
|
const changelogUrl = `https://insomnia.rest/changelog/${app}/${version}`;
|
|
|
|
|
2019-10-09 20:31:42 +00:00
|
|
|
try {
|
|
|
|
return await octokit.repos.getReleaseByTag({
|
2020-04-26 20:33:39 +00:00
|
|
|
owner: appConfig().githubOrg,
|
|
|
|
repo: appConfig().githubRepo,
|
|
|
|
tag,
|
2019-10-09 20:31:42 +00:00
|
|
|
});
|
|
|
|
} catch (err) {
|
|
|
|
// Doesn't exist
|
|
|
|
}
|
|
|
|
|
|
|
|
return octokit.repos.createRelease({
|
2020-04-26 20:33:39 +00:00
|
|
|
owner: appConfig().githubOrg,
|
|
|
|
repo: appConfig().githubRepo,
|
|
|
|
tag_name: tag,
|
|
|
|
name: releaseName,
|
|
|
|
body: `Full changelog ⇒ ${changelogUrl}`,
|
2019-10-09 20:31:42 +00:00
|
|
|
draft: false,
|
2020-04-26 20:33:39 +00:00
|
|
|
prerelease: true,
|
2019-10-09 20:31:42 +00:00
|
|
|
});
|
|
|
|
}
|