Store built bundle in github not bintray (#11893)

This commit is contained in:
Isaac A. Murchie
2018-12-21 16:47:44 -05:00
committed by GitHub
parent f60b12cae0
commit 29922f8931
5 changed files with 91 additions and 82 deletions
+1 -1
View File
@@ -59,7 +59,7 @@ jobs:
hub pull-request -b "appium:master" -h "appium:generate-docs-$TRAVIS_COMMIT" -m "Update auto-generated docs";
fi
- stage:
name: BinTray Bundle
name: Bundle
# only want to run this on the main master branch
if: branch = master AND type != pull_request
os:
+85
View File
@@ -0,0 +1,85 @@
/* eslint-disable promise/prefer-await-to-then */
/* eslint-disable promise/prefer-await-to-callbacks */
const octokit = require('@octokit/rest')();
const gulp = require('gulp');
const _ = require('lodash');
const log = require('fancy-log');
const fs = require('fs');
const path = require('path');
const owner = 'appium';
const repo = 'appium-build-store';
const BUILD_NAME = process.env.TRAVIS_TAG || process.env.TRAVIS_COMMIT || `${Date.now()}`; // The random number is for local, throwaway tests
const COMMIT_MESSAGE = process.env.TRAVIS_COMMIT_MESSAGE || 'No commit message provided';
gulp.task('authenticate', function (done) {
const githubToken = process.env.GITHUB_TOKEN;
if (_.isEmpty(githubToken)) {
log.warn('No GitHub token found in GITHUB_ACCESS_TOKEN environment variable');
return;
}
octokit.authenticate({
type: 'token',
token: githubToken,
});
done();
});
gulp.task('upload', function () {
const releaseTag = `appium-build-${BUILD_NAME}`;
const releaseFile = `appium-${BUILD_NAME}.zip`;
let releaseId;
log(`Creating release on '${owner}/${repo}'`);
return octokit.repos.createRelease({
owner,
repo,
tag_name: releaseTag,
name: `Appium build ${BUILD_NAME}`,
body: `Appium build for commit ${BUILD_NAME}\n'${COMMIT_MESSAGE}'`,
})
.then(function (res) {
releaseId = res.data.id;
log(`Created release '${releaseTag}' (id: ${releaseId})`);
return res.data.upload_url;
})
.then(function (url) {
const file = path.resolve(__dirname, '..', 'appium.zip');
log(`Uploading file '${file}'`);
return octokit.repos.uploadReleaseAsset({
headers: {
'content-length': fs.statSync(file).size,
'content-type': 'application/zip',
},
url,
file: fs.createReadStream(file),
name: releaseFile,
});
})
.then(function (/* res */) {
log(`Uploaded release file '${releaseFile}'`);
})
.catch(function (err) {
log.error(`Error uploading release asset: ${err.message}`);
if (err.errors) {
log.error(JSON.stringify(err.errors, 2));
}
log('Deleting release with no asset');
return octokit.repos.deleteRelease({
owner,
repo,
release_id: releaseId,
})
.then(function (/* res */) {
log('Release deleted');
});
});
});
gulp.task('github-upload', gulp.series(['authenticate', 'upload']));
+3
View File
@@ -13,6 +13,9 @@ const fs = require('fs');
const log = require('fancy-log');
require('./ci/gulp');
// remove 'fsevents' from shrinkwrap, since it causes errors on non-Mac hosts
// see https://github.com/npm/npm/issues/2679
gulp.task('fixShrinkwrap', function (done) {
+2 -1
View File
@@ -86,7 +86,7 @@
"generate-docs": "node ./build/commands-yml/parse.js",
"shrinkwrap-prod": "rimraf package-lock.json && npm prune --production && npm shrinkwrap && npm install --no-shrinkwrap",
"zip": "zip -qr appium.zip .",
"upload": "node ./build/test/scripts/bintray-upload.js",
"upload": "gulp github-upload",
"zip-and-upload": "npm run zip && npm run upload"
},
"pre-commit": [
@@ -94,6 +94,7 @@
"precommit-test"
],
"devDependencies": {
"@octokit/rest": "^16.3.0",
"ajv": "^6.5.3",
"appium-gulp-plugins": "^3.1.0",
"babel-eslint": "^10.0.0",
-80
View File
@@ -1,80 +0,0 @@
const request = require('request-promise');
const { logger } = require('appium-support');
const path = require('path');
const fs = require('fs');
// Bintray info
const BINTRAY_USERNAME = process.env.BINTRAY_USERNAME;
const BINTRAY_API_KEY = process.env.BINTRAY_API_KEY;
const BINTRAY_REPO = process.env.BINTRAY_REPO || 'appium';
const BINTRAY_SUBJECT = process.env.BINTRAY_SUBJECT || 'appium-builds';
const BINTRAY_PACKAGE = process.env.BINTRAY_PACKAGE || 'appium';
const BINTRAY_URL = `https://bintray.com/api/v1`;
const log = logger.getLogger('Bintray');
(async function () {
// Version info
const BUILD_NAME = process.env.TRAVIS_TAG || process.env.TRAVIS_COMMIT || (Math.random() + ""); // The random number is for local, throwaway tests
const COMMIT_MESSAGE = process.env.TRAVIS_COMMIT_MESSAGE || 'No commit message provided';
// 1. Create a new 'version' that uses the commit SHA as the name
log.info(`Creating a new Bintray version: ${BUILD_NAME}`);
const postVersionUrl = `${BINTRAY_URL}/packages/${BINTRAY_SUBJECT}/${BINTRAY_REPO}/${BINTRAY_PACKAGE}/versions`;
log.info(`Using Bintray REST API endpoint ${postVersionUrl}`);
try {
await request.post(postVersionUrl, {
body: {
name: BUILD_NAME,
desc: COMMIT_MESSAGE,
},
json: true,
auth: {
user: BINTRAY_USERNAME,
pass: BINTRAY_API_KEY,
}
});
} catch (e) {
// 409 means it was created already
if (e.statusCode !== 409) {
log.error(`Failed to create new version ${BUILD_NAME}. Reason: ${e.error.message}`);
process.exit(-1);
} else {
log.info(`Version ${BUILD_NAME} was already created. Continuing.`);
}
}
// 2. Upload and publish Appium.zip to Bintray
log.info(`Uploading 'appium.zip' to bintray at version ${BUILD_NAME}`);
const uploadZipUrl = `${BINTRAY_URL}/content/${BINTRAY_SUBJECT}/${BINTRAY_REPO}/${BINTRAY_PACKAGE}/${BUILD_NAME}/appium-${BUILD_NAME}.zip?publish=1&override=1`;
log.info(`Using Bintray REST API upload endpoint ${uploadZipUrl}`);
try {
await request.put(uploadZipUrl, {
formData: {
file: {
value: fs.createReadStream(path.resolve(__dirname, '..', '..', '..', 'appium.zip')),
options: {
filename: 'appium.zip',
contentType: 'application/octet-stream',
},
},
},
auth: {
user: BINTRAY_USERNAME,
pass: BINTRAY_API_KEY,
}
});
} catch (e) {
if (e.statusCode === 409) {
// Doesn't fail on 409 because sometimes 409 means that the asset was already published
// and if that's the case, we don't want it to fail
log.error(`Did not publish upload. Upload is already available. Reason: ${e.message}`);
} else {
log.error(`Failed to publish 'appium.zip' to ${BUILD_NAME}. Reason: ${JSON.stringify(e)}`);
process.exit(-1);
}
}
log.info(`Done publishing 'appium.zip' to ${BUILD_NAME}`);
})();