From 4d86559a38009d60200526f5e6cd4d810043dd01 Mon Sep 17 00:00:00 2001 From: Luca Zeug Date: Wed, 11 Jan 2017 23:13:22 +0100 Subject: [PATCH 1/4] add gulp task 'upload-binaries' --- gulpfile.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + yarn.lock | 22 ++++++++++++++++++---- 3 files changed, 65 insertions(+), 4 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index fe3b4efd2..26ce4cd7c 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -21,6 +21,8 @@ const mocha = require('gulp-spawn-mocha'); const minimist = require('minimist'); const fs = require('fs'); const got = require('got'); +const Q = require('bluebird'); +const githubUpload = Q.promisify(require('gh-release-assets')); const options = minimist(process.argv.slice(2), { string: ['platform', 'walletSource'], @@ -347,6 +349,50 @@ gulp.task('release-dist', ['build-dist'], (done) => { done(); }); +gulp.task('upload-binaries', (cb) => { + const GITHUB_TOKEN = process.env.GITHUB_TOKEN; + + // query github releases + return got(`https://api.github.com/repos/luclu/mist/releases?access_token=${GITHUB_TOKEN}`, { + json: true, + }) + // filter draft with current version's tag + .then((res) => { + let draft; + + res.body.forEach((release) => { + if (release.tag_name.match(version) && release.draft === true) { + draft = release; + } + }); + + return draft; + }) + // upload binaries from release folders + .then((draft) => { + const dirs = ['dist_wallet/release', 'dist_mist/release']; + const files = []; + dirs.forEach((dir) => { + files.push(_.map(fs.readdirSync(dir), (file) => { return path.join(dir, file); })); + }); + const binaries = _.flatten(files); + + return githubUpload({ + url: `https://uploads.github.com/repos/luclu/mist/releases/${draft.id}/assets{?name}`, + token: [GITHUB_TOKEN], + assets: binaries, + }).then((res) => { + console.log(`Successfully uploaded ${res}`); + + cb(); + }); + }) + .catch((err) => { + if (err.message === "Cannot read property 'id' of undefined") { + console.log(Error(`Couldn't find github release draft for v${version} release tag`)); + } + }); +}); gulp.task('get-release-checksums', (done) => { const releasePath = `./dist_${type}/release`; diff --git a/package.json b/package.json index c4e5817c1..78ac6d5e5 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "eslint-plugin-import": "^1.16.0", "genomatic": "^1.0.0", "geth-private": "^1.3.0", + "gh-release-assets": "^1.1.0", "gulp": "^3.9.0", "gulp-flatten": "^0.3.0", "gulp-spawn-mocha": "^2.2.2", diff --git a/yarn.lock b/yarn.lock index ec86b88a9..719767931 100644 --- a/yarn.lock +++ b/yarn.lock @@ -212,6 +212,10 @@ async@>=0.1.0, async@^2.0.0, async@^2.0.1: dependencies: lodash "^4.8.0" +async@^0.9.0: + version "0.9.2" + resolved "https://registry.yarnpkg.com/async/-/async-0.9.2.tgz#aea74d5e61c1f899613bf64bda66d4c78f2fd17d" + async@~0.2.6: version "0.2.10" resolved "https://registry.yarnpkg.com/async/-/async-0.2.10.tgz#b6bbe0b0674b9d719708ca38de8c237cb526c3d1" @@ -1656,6 +1660,16 @@ getpass@^0.1.1: dependencies: assert-plus "^1.0.0" +gh-release-assets@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/gh-release-assets/-/gh-release-assets-1.1.0.tgz#00f76bd151d020032de10712f525d2a944814595" + dependencies: + async "^0.9.0" + mime "^1.3.4" + progress-stream "^1.1.1" + request "^2.55.0" + util-extend "^1.0.1" + glob-base@^0.3.0: version "0.3.0" resolved "https://registry.yarnpkg.com/glob-base/-/glob-base-0.3.0.tgz#dbb164f6221b1c0b1ccf82aea328b497df0ea3c4" @@ -1863,11 +1877,11 @@ graceful-fs@^3.0.0, graceful-fs@~3.0.2: dependencies: natives "^1.1.0" -graceful-fs@^4.0.0, graceful-fs@^4.1.10, graceful-fs@^4.1.6, graceful-fs@^4.1.9: +graceful-fs@^4.0.0, graceful-fs@^4.1.10: version "4.1.11" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658" -graceful-fs@^4.1.0, graceful-fs@^4.1.2: +graceful-fs@^4.1.0, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.1.9: version "4.1.9" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.9.tgz#baacba37d19d11f9d146d3578bc99958c3787e29" @@ -3411,7 +3425,7 @@ process-nextick-args@~1.0.6: version "1.0.7" resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-1.0.7.tgz#150e20b756590ad3f91093f25a4f2ad8bff30ba3" -progress-stream@^1.1.0, progress-stream@^1.2.0: +progress-stream@^1.1.0, progress-stream@^1.1.1, progress-stream@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/progress-stream/-/progress-stream-1.2.0.tgz#2cd3cfea33ba3a89c9c121ec3347abe9ab125f77" dependencies: @@ -3660,7 +3674,7 @@ request@2.74.0: tough-cookie "~2.3.0" tunnel-agent "~0.4.1" -request@^2.45.0, request@^2.65.0: +request@^2.45.0, request@^2.55.0, request@^2.65.0: version "2.75.0" resolved "https://registry.yarnpkg.com/request/-/request-2.75.0.tgz#d2b8268a286da13eaa5d01adf5d18cc90f657d93" dependencies: From 73de5b896d1e8b30b859cfb3f459e2f16cc85015 Mon Sep 17 00:00:00 2001 From: Luca Zeug Date: Wed, 11 Jan 2017 23:13:59 +0100 Subject: [PATCH 2/4] fix ESLint errors --- gulpfile.js | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 26ce4cd7c..ad148eff2 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -112,8 +112,10 @@ gulp.task('copy-app-source-files', ['clean:dist'], () => { './*.js', './clientBinaries.json', '!gulpfile.js', - ], { base: './' }) - .pipe(gulp.dest(`./dist_${type}/app`)); + ], { + base: './' + }) + .pipe(gulp.dest(`./dist_${type}/app`)); }); @@ -136,9 +138,11 @@ gulp.task('copy-build-folder-files', ['clean:dist', 'copy-app-folder-files'], () return gulp.src([ `./icons/${type}/*`, './interface/public/images/dmg-background.jpg', - ], { base: './' }) - .pipe(flatten()) - .pipe(gulp.dest(`./dist_${type}/build`)); + ], { + base: './' + }) + .pipe(flatten()) + .pipe(gulp.dest(`./dist_${type}/build`)); }); @@ -151,7 +155,7 @@ gulp.task('copy-node-folder-files', ['clean:dist'], () => { streams.push(gulp.src([ `./nodes/eth/${osArch}/*`, ]) - .pipe(gulp.dest(`./dist_${type}/app/nodes/eth/${osArch}`))); + .pipe(gulp.dest(`./dist_${type}/app/nodes/eth/${osArch}`))); } }); @@ -190,7 +194,7 @@ gulp.task('bundling-interface', ['switch-production'], (cb) => { if (options.walletSource === 'local') { console.log('Use local wallet at ../meteor-dapp-wallet/app'); exec(`cd interface/ && meteor-build-client ../dist_${type}/app/interface/ -p "" &&` + - `cd ../../meteor-dapp-wallet/app && meteor-build-client ../../mist/dist_${type}/app/interface/wallet -p ""`, (err, stdout) => { + `cd ../../meteor-dapp-wallet/app && meteor-build-client ../../mist/dist_${type}/app/interface/wallet -p ""`, (err, stdout) => { console.log(stdout); cb(err); @@ -198,7 +202,7 @@ gulp.task('bundling-interface', ['switch-production'], (cb) => { } else { console.log(`Pulling https://github.com/ethereum/meteor-dapp-wallet/tree/${options.walletSource} "${options.walletSource}" branch...`); exec(`cd interface/ && meteor-build-client ../dist_${type}/app/interface/ -p "" &&` + - `cd ../dist_${type}/ && git clone --depth 1 https://github.com/ethereum/meteor-dapp-wallet.git && cd meteor-dapp-wallet/app && meteor-build-client ../../app/interface/wallet -p "" && cd ../../ && rm -rf meteor-dapp-wallet`, (err, stdout) => { + `cd ../dist_${type}/ && git clone --depth 1 https://github.com/ethereum/meteor-dapp-wallet.git && cd meteor-dapp-wallet/app && meteor-build-client ../../app/interface/wallet -p "" && cd ../../ && rm -rf meteor-dapp-wallet`, (err, stdout) => { console.log(stdout); cb(err); @@ -213,8 +217,10 @@ gulp.task('copy-i18n', ['bundling-interface'], () => { return gulp.src([ './interface/i18n/*.*', './interface/project-tap.i18n', - ], { base: './' }) - .pipe(gulp.dest(`./dist_${type}/app`)); + ], { + base: './' + }) + .pipe(gulp.dest(`./dist_${type}/app`)); }); @@ -236,7 +242,7 @@ gulp.task('build-dist', ['download-signatures', 'copy-i18n'], (cb) => { 'build-dist.js', ], extraFiles: [ - 'nodes/eth/${os}-${arch}', // eslint-disable-line no-template-curly-in-string + 'nodes/eth/${os}-${arch}', // eslint-disable-line no-template-curly-in-string ], linux: { target: [ @@ -263,7 +269,8 @@ gulp.task('build-dist', ['download-signatures', 'copy-i18n'], (cb) => { x: 441, y: 142, type: 'file', - }], + } + ], }, }, directories: { @@ -322,7 +329,7 @@ gulp.task('release-dist', ['build-dist'], (done) => { _.each(osArchList, (osArch) => { if (platformIsActive(osArch)) { - switch (osArch) { // eslint-disable-line default-case + switch (osArch) { // eslint-disable-line default-case case 'win-ia32': // cp(path.join('win-ia32', `${applicationName} Setup ${version}-ia32.exe`), `${appNameHypen}-win32-${versionDashed}.exe`); cp(`${applicationName}-${version}-ia32-win.zip`, `${appNameHypen}-win32-${versionDashed}.zip`); @@ -400,7 +407,9 @@ gulp.task('get-release-checksums', (done) => { const files = fs.readdirSync(releasePath); for (const file of files) { - const sha = shell.exec(`shasum -a 256 "${file}"`, { cwd: releasePath }); + const sha = shell.exec(`shasum -a 256 "${file}"`, { + cwd: releasePath + }); if (sha.code !== 0) { return done(new Error(`Error executing shasum: ${sha.stderr}`)); From 85b652f484ca641c92dde884aebf996ff69fdc25 Mon Sep 17 00:00:00 2001 From: Luca Zeug Date: Wed, 11 Jan 2017 23:18:37 +0100 Subject: [PATCH 3/4] add comment --- gulpfile.js | 1 + 1 file changed, 1 insertion(+) diff --git a/gulpfile.js b/gulpfile.js index ad148eff2..fa13b9551 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -357,6 +357,7 @@ gulp.task('release-dist', ['build-dist'], (done) => { }); gulp.task('upload-binaries', (cb) => { + // token must be set using travis' ENVs const GITHUB_TOKEN = process.env.GITHUB_TOKEN; // query github releases From 24d213d949ddf462d32590f75a1303f39a3488b7 Mon Sep 17 00:00:00 2001 From: Luca Zeug Date: Thu, 12 Jan 2017 00:34:26 +0100 Subject: [PATCH 4/4] Integrate in gulp task sequence; add CI check --- gulpfile.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index fa13b9551..cc2de6318 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -367,9 +367,10 @@ gulp.task('upload-binaries', (cb) => { // filter draft with current version's tag .then((res) => { let draft; - res.body.forEach((release) => { - if (release.tag_name.match(version) && release.draft === true) { + if (release.tag_name.match(version) + && release.draft === true + ) { draft = release; } }); @@ -378,6 +379,8 @@ gulp.task('upload-binaries', (cb) => { }) // upload binaries from release folders .then((draft) => { + if (draft && draft.assets.length !== 0) throw new Error('Github release draft already contains assets; will not upload'); + const dirs = ['dist_wallet/release', 'dist_mist/release']; const files = []; dirs.forEach((dir) => { @@ -398,6 +401,8 @@ gulp.task('upload-binaries', (cb) => { .catch((err) => { if (err.message === "Cannot read property 'id' of undefined") { console.log(Error(`Couldn't find github release draft for v${version} release tag`)); + } else { + console.log(err); } }); }); @@ -444,9 +449,11 @@ gulp.task('download-signatures', (cb) => { .catch(cb); }); -gulp.task('taskQueue', [ - 'release-dist', -]); +gulp.task('taskQueue', ['release-dist'], () => { + if (process.env.CI) { + runSeq('upload-binaries'); + } +}); // MIST task gulp.task('mist', (cb) => {