From 2c9b80c17787486b3a7e22037203a0a8abc15c87 Mon Sep 17 00:00:00 2001 From: Tim Perry Date: Wed, 13 Dec 2017 18:33:03 +0100 Subject: [PATCH] Add manual script to deploy built CLI binaries to GitHub --- .gitignore | 1 + automation/deploy-bin.ts | 53 ++++++++++++++++++++++++++++++++++++++++ package.json | 4 +++ 3 files changed, 58 insertions(+) create mode 100644 automation/deploy-bin.ts diff --git a/.gitignore b/.gitignore index afa7f9b7..0dcd94ac 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,4 @@ resinrc.yml /tmp build/ build-bin/ +resin-cli-*.zip diff --git a/automation/deploy-bin.ts b/automation/deploy-bin.ts new file mode 100644 index 00000000..2ccc89a3 --- /dev/null +++ b/automation/deploy-bin.ts @@ -0,0 +1,53 @@ +import * as Promise from 'bluebird'; +import * as path from 'path'; +import * as os from 'os'; +import * as fs from 'fs-extra'; +import * as publishRelease from 'publish-release'; +import * as archiver from 'archiver'; + +const publishReleaseAsync = Promise.promisify(publishRelease); + +const { GITHUB_TOKEN } = process.env; +const ROOT = path.join(__dirname, '..'); + +const version = 'v' + require('../package.json').version; +const outputFile = path.join(ROOT, `resin-cli-${version}-${os.platform()}-${os.arch()}.zip`); + +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: 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); +}); diff --git a/package.json b/package.json index 8001c631..c4029a41 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "build": "npm run build:src && npm run build:bin", "build:src": "gulp build && tsc && npm run doc", "build:bin": "ts-node automation/build-bin.ts", + "release": "npm run build && ts-node automation/deploy-bin.ts", "pretest": "npm run build", "test": "gulp test", "ci": "npm run test && catch-uncommitted", @@ -51,6 +52,7 @@ "node": ">=6.0" }, "devDependencies": { + "@types/archiver": "^2.0.1", "@types/fs-extra": "^5.0.0", "catch-uncommitted": "^1.0.0", "ent": "^2.2.0", @@ -64,6 +66,7 @@ "gulp-shell": "^0.5.2", "mochainon": "^2.0.0", "pkg": "^4.3.0-beta.1", + "publish-release": "^1.3.3", "require-npm4-to-publish": "^1.0.0", "ts-node": "^4.0.1", "typescript": "^2.6.1" @@ -72,6 +75,7 @@ "@resin.io/valid-email": "^0.1.0", "ansi-escapes": "^2.0.0", "any-promise": "^1.3.0", + "archiver": "^2.1.0", "bash": "0.0.1", "bluebird": "^3.3.3", "body-parser": "^1.14.1",