mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-28 09:38:51 +00:00
83a76f7d6f
Change-Type: patch
68 lines
1.7 KiB
TypeScript
68 lines
1.7 KiB
TypeScript
import * as Promise from 'bluebird';
|
|
import * as path from 'path';
|
|
import * as os from 'os';
|
|
import * as fs from 'fs-extra';
|
|
import * as mkdirp from 'mkdirp';
|
|
import * as publishRelease from 'publish-release';
|
|
import * as archiver from 'archiver';
|
|
import * as packageJSON from '../package.json';
|
|
|
|
const publishReleaseAsync = Promise.promisify(publishRelease);
|
|
const mkdirpAsync = Promise.promisify<string | null, string>(mkdirp);
|
|
|
|
const { GITHUB_TOKEN } = process.env;
|
|
const ROOT = path.join(__dirname, '..');
|
|
|
|
const version = 'v' + packageJSON.version;
|
|
const outputFile = path.join(
|
|
ROOT,
|
|
'build-zip',
|
|
`resin-cli-${version}-${os.platform()}-${os.arch()}.zip`,
|
|
);
|
|
|
|
mkdirpAsync(path.dirname(outputFile))
|
|
.then(
|
|
() =>
|
|
new Promise((resolve, reject) => {
|
|
console.log('Zipping build...');
|
|
|
|
let archive = archiver('zip', {
|
|
zlib: { level: 7 },
|
|
});
|
|
archive.directory(path.join(ROOT, 'build-bin'), 'resin-cli');
|
|
|
|
let outputStream = fs.createWriteStream(outputFile);
|
|
|
|
outputStream.on('close', resolve);
|
|
outputStream.on('error', reject);
|
|
|
|
archive.on('error', reject);
|
|
archive.on('warning', console.warn);
|
|
|
|
archive.pipe(outputStream);
|
|
archive.finalize();
|
|
}),
|
|
)
|
|
.then(() => {
|
|
console.log('Build zipped');
|
|
console.log('Publishing build...');
|
|
|
|
return publishReleaseAsync({
|
|
token: <string>GITHUB_TOKEN,
|
|
owner: 'resin-io',
|
|
repo: 'resin-cli',
|
|
tag: version,
|
|
name: `Resin-CLI ${version}`,
|
|
reuseRelease: true,
|
|
assets: [outputFile],
|
|
});
|
|
})
|
|
.then(release => {
|
|
console.log(`Release ${version} successful: ${release.html_url}`);
|
|
})
|
|
.catch(err => {
|
|
console.error('Release failed');
|
|
console.error(err);
|
|
process.exit(1);
|
|
});
|