Skip to content

Instantly share code, notes, and snippets.

@leonardosnt
Last active November 24, 2016 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leonardosnt/85a3961efc46ac62c758e577e9ee92df to your computer and use it in GitHub Desktop.
Save leonardosnt/85a3961efc46ac62c758e577e9ee92df to your computer and use it in GitHub Desktop.
/*
* Copyright (C) 2015-2016 leonardosnt
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
"use strict";
const fs = require('fs');
const request = require('sync-request');
const ACCESS_TOKEN = process.env['GH_RELEASE_ACCESS_TOKEN'];
const CREATE_RELEASE_URL = `https://api.github.com/repos/leonardosnt/test/releases?access_token=${ACCESS_TOKEN}`;
const UPLOAD_RELEASE_URL = `https://uploads.github.com/repos/leonardosnt/test/releases/{id}/assets?access_token=${ACCESS_TOKEN}&name={name}`;
function createRelease(version) {
let res = request('POST', CREATE_RELEASE_URL, {
headers: {
'User-Agent': 'node'
},
body: JSON.stringify({
tag_name: version,
target_commitish: "master",
name: version,
body: "hl",
draft: false,
prerelease: true
})
});
return JSON.parse(res.getBody('utf8'));
}
function uploadAsset(releaseInfo, fileName) {
let id = releaseInfo['id'];
if (!id) {
throw 'id == undefined'
}
let res = request('POST', UPLOAD_RELEASE_URL.replace('{id}', id).replace('{name}', fileName), {
headers: {
'User-Agent': 'node',
'Content-Type': 'application/zip'
},
body: fs.readFileSync(fileName)
});
return JSON.parse(res.getBody('utf8'));
}
createRelease(`foo-${process.env['APPVEYOR_BUILD_NUMBER']}`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment