diff --git a/admin/changelog.js b/admin/changelog.js index 36ba70e60..eaa5e89c7 100644 --- a/admin/changelog.js +++ b/admin/changelog.js @@ -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, } - diff --git a/admin/cmds/publish.js b/admin/cmds/publish.js index e7d8ef052..3bff1680e 100644 --- a/admin/cmds/publish.js +++ b/admin/cmds/publish.js @@ -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(" "); } + // 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(` ${ link }...`); + } + })(); diff --git a/admin/config.js b/admin/config.js index c61587d7b..2e73235c2 100644 --- a/admin/config.js +++ b/admin/config.js @@ -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(); } diff --git a/admin/github.js b/admin/github.js index 8183a9de9..3a42a563c 100644 --- a/admin/github.js +++ b/admin/github.js @@ -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, } +