Added automatic createRelease to publish-all.

This commit is contained in:
Richard Moore 2020-02-12 17:18:43 -05:00
parent ca25c2f13d
commit 0e1cd4282d
No known key found for this signature in database
GPG Key ID: 665176BE8E9DC651
4 changed files with 91 additions and 1 deletions

@ -105,9 +105,41 @@ async function generate() {
return formatted.join("\n") + "\n";
}
function getChanges() {
const changes = [ ];
let lastLine = null;
fs.readFileSync(ChangelogPath).toString().split("\n").forEach((line) => {
line = line.trim();
if (line === "") { return; }
if (line.substring(0, 5) === "-----") {
changes.push({ title: lastLine, lines: [ ] });
} else if (line.substring(0, 1) === "-" && changes.length) {
changes[changes.length - 1].lines.push(line);
}
lastLine = line;
});
return changes;
}
function latestChange() {
const recent = getChanges()[0];
const match = recent.title.match(/ethers\/([^\(]*)\(([^\)]*)\)/);
return {
title: recent.title,
version: match[1].trim(),
data: match[2].trim(),
content: recent.lines.join("\n")
};
}
module.exports = {
generate: generate,
latestChange: latestChange,
ChangelogPath: ChangelogPath,
}

@ -2,13 +2,16 @@
const config = require("../config");
const { latestChange } = require("../changelog");
const { getOrdered, loadPackage } = require("../depgraph");
const { createRelease } = require("../github");
const { getPackageVersion, publish } = require("../npm");
const { log } = require("../log");
const USER_AGENT = "ethers-dist@0.0.0";
const TAG = "next";
let dirnames = getOrdered();
// Only publish specific packages
@ -32,6 +35,8 @@ if (process.argv.length > 2) {
(async function() {
let token = null;
let includeEthers = false;
// @TODO: Fail if there are any untracked files or unchecked in files
// Load the token from the encrypted store
@ -68,6 +73,7 @@ if (process.argv.length > 2) {
if (dirname === "ethers") {
options.tag = "next";
includeEthers = true;
} else {
options.tag = "latest";
}
@ -89,4 +95,20 @@ if (process.argv.length > 2) {
log(" <green:Done.>");
}
// Publish the GitHub release (currently beta)
const beta = true;
if (includeEthers) {
// The password above already succeeded
const username = await config.get("github-user");
const password = await config.get("github-release");
// Get the latest change from the changelog
const change = latestChange();
// Publish the release
const link = await createRelease(username, password, change.version, change.title, change.content, beta);
log(`<bold:Published Release:> ${ link }...`);
}
})();

@ -57,6 +57,11 @@ Config.prototype.load = async function() {
}
};
Config.prototype.keys = async function() {
await this.load();
return Object.keys(this.values);
}
Config.prototype.save = function() {
this.values._junk = Buffer.from(randomBytes(16 + parseInt(Math.random() * 48))).toString("base64")
@ -102,6 +107,9 @@ module.exports = {
set: function(key, value) {
config.set(key, value);
},
keys: function() {
return config.keys();
},
lock: function() {
config.lock();
}

@ -128,7 +128,35 @@ function syncIssues(user, password) {
return _getIssues(user, password);
}
async function createRelease(user, password, tagName, title, body, prerelease, commit) {
const payload = {
tag_name: tagName,
target_commitish: (commit || "master"),
name: title,
body: body,
//draft: true,
draft: false,
prerelease: !!prerelease
};
const headers = {
"User-Agent": "ethers-io",
};
const result = await fetchJson({
url: "https://api.github.com/repos/ethers-io/ethers.js/releases",
user: user,
password: password,
headers: headers
}, JSON.stringify(payload));
return result.html_url;
}
module.exports = {
getIssues,
syncIssues,
createRelease,
}