2019-03-12 22:07:57 +00:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright 2019 Balena Ltd.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
import * as archiver from 'archiver';
|
2017-12-13 17:33:03 +00:00
|
|
|
import * as Promise from 'bluebird';
|
|
|
|
import * as fs from 'fs-extra';
|
2017-12-18 13:49:45 +00:00
|
|
|
import * as mkdirp from 'mkdirp';
|
2019-03-12 22:07:57 +00:00
|
|
|
import * as os from 'os';
|
|
|
|
import * as path from 'path';
|
2017-12-13 17:33:03 +00:00
|
|
|
import * as publishRelease from 'publish-release';
|
2019-03-12 22:07:57 +00:00
|
|
|
|
2018-01-04 14:07:55 +00:00
|
|
|
import * as packageJSON from '../package.json';
|
2017-12-13 17:33:03 +00:00
|
|
|
|
2017-12-14 11:29:54 +00:00
|
|
|
const publishReleaseAsync = Promise.promisify(publishRelease);
|
2017-12-18 13:49:45 +00:00
|
|
|
const mkdirpAsync = Promise.promisify<string | null, string>(mkdirp);
|
2017-12-13 17:33:03 +00:00
|
|
|
|
|
|
|
const { GITHUB_TOKEN } = process.env;
|
|
|
|
const ROOT = path.join(__dirname, '..');
|
|
|
|
|
2018-01-04 14:07:55 +00:00
|
|
|
const version = 'v' + packageJSON.version;
|
2018-01-09 15:05:24 +00:00
|
|
|
const outputFile = path.join(
|
|
|
|
ROOT,
|
|
|
|
'build-zip',
|
2018-10-19 14:38:50 +00:00
|
|
|
`balena-cli-${version}-${os.platform()}-${os.arch()}.zip`,
|
2018-01-09 15:05:24 +00:00
|
|
|
);
|
2017-12-13 17:33:03 +00:00
|
|
|
|
2018-01-09 15:05:24 +00:00
|
|
|
mkdirpAsync(path.dirname(outputFile))
|
|
|
|
.then(
|
|
|
|
() =>
|
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
console.log('Zipping build...');
|
2017-12-13 17:33:03 +00:00
|
|
|
|
2019-03-12 22:07:57 +00:00
|
|
|
const archive = archiver('zip', {
|
2018-01-09 15:05:24 +00:00
|
|
|
zlib: { level: 7 },
|
|
|
|
});
|
2018-10-19 14:38:50 +00:00
|
|
|
archive.directory(path.join(ROOT, 'build-bin'), 'balena-cli');
|
2018-01-09 15:05:24 +00:00
|
|
|
|
2019-03-12 22:07:57 +00:00
|
|
|
const outputStream = fs.createWriteStream(outputFile);
|
2018-01-09 15:05:24 +00:00
|
|
|
|
|
|
|
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({
|
2019-03-12 22:07:57 +00:00
|
|
|
token: GITHUB_TOKEN || '',
|
2018-10-19 14:38:50 +00:00
|
|
|
owner: 'balena-io',
|
|
|
|
repo: 'balena-cli',
|
2018-01-09 15:05:24 +00:00
|
|
|
tag: version,
|
2018-10-19 14:38:50 +00:00
|
|
|
name: `balena-CLI ${version}`,
|
2018-01-09 15:05:24 +00:00
|
|
|
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);
|
2017-12-13 17:33:03 +00:00
|
|
|
});
|