admin: added script to create github releases (#3784)
This commit is contained in:
parent
47ef3ebde3
commit
4a581b9944
40
src.ts/_admin/create-release.ts
Normal file
40
src.ts/_admin/create-release.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import { getChanges } from "./utils/changelog.js";
|
||||
import { getDateTime } from "./utils/date.js";
|
||||
import { resolve } from "./utils/path.js";
|
||||
import { run } from "./utils/run.js";
|
||||
import { getVersions } from "./utils/npm.js";
|
||||
|
||||
|
||||
const version = process.argv[2] || null;
|
||||
|
||||
(async function() {
|
||||
|
||||
// Get the change from the CHANGELOG
|
||||
const changes = getChanges();
|
||||
const change = version ? changes.filter((c) => (c.version === version))[0]: changes.shift();
|
||||
if (change == null) { throw new Error(`version not found: ${ version }`); }
|
||||
console.log(change);
|
||||
|
||||
// Find the gitHead and release date
|
||||
const versions = await getVersions("ethers");
|
||||
const ver = versions.filter((c) => (c.version === change.version))[0];
|
||||
if (ver == null) { throw new Error(`no npm version found: ${ change.version }`); }
|
||||
console.log(ver);
|
||||
|
||||
const title = `${ change.title.split("(")[0].trim() } (${ getDateTime(new Date(ver.date) ) })`;
|
||||
|
||||
const args = [
|
||||
"release", "create", `v${ change.version }`,
|
||||
// "--draft", // DEBUGGING
|
||||
"--title", title,
|
||||
"--target", ver.gitHead,
|
||||
"--notes", change.body.join("\n"),
|
||||
];
|
||||
console.log(args);
|
||||
const result = await run("gh", args, resolve("."));
|
||||
console.log("Published");
|
||||
console.log(`See: ${ (result.stdout || "").trim() }`);
|
||||
})().catch((e) => {
|
||||
console.log("ERROR");
|
||||
console.log(e);
|
||||
});
|
@ -4,6 +4,7 @@ import { getLogs } from "./utils/git.js";
|
||||
import { loadJson } from "./utils/json.js";
|
||||
import { resolve } from "./utils/path.js";
|
||||
import { getVersions } from "./utils/npm.js";
|
||||
import { getDateTime } from "./utils/date.js";
|
||||
|
||||
function repeat(c: string, length: number): string {
|
||||
if (c.length === 0) { throw new Error("too short"); }
|
||||
@ -11,27 +12,6 @@ function repeat(c: string, length: number): string {
|
||||
return c.substring(0, length);
|
||||
}
|
||||
|
||||
function zpad(value: number, length?: number): string {
|
||||
if (length == null) { length = 2; }
|
||||
const str = String(value);
|
||||
return repeat("0", length - str.length) + str;
|
||||
}
|
||||
|
||||
function getDate(date: Date): string {
|
||||
return [
|
||||
date.getFullYear(),
|
||||
zpad(date.getMonth() + 1),
|
||||
zpad(date.getDate())
|
||||
].join("-");
|
||||
}
|
||||
|
||||
export function getDateTime(date: Date): string {
|
||||
return getDate(date) + " " + [
|
||||
zpad(date.getHours()) ,
|
||||
zpad(date.getMinutes() + 1)
|
||||
].join(":");
|
||||
}
|
||||
|
||||
type Change = {
|
||||
message: string;
|
||||
issues: Array<string>;
|
||||
|
31
src.ts/_admin/utils/changelog.ts
Normal file
31
src.ts/_admin/utils/changelog.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import fs from "fs";
|
||||
import { resolve } from "./path.js";
|
||||
|
||||
export type ChangeVersion = {
|
||||
version: string;
|
||||
title: string;
|
||||
body: Array<string>;
|
||||
};
|
||||
|
||||
export function getChanges(): Array<ChangeVersion> {
|
||||
const changes: Array<ChangeVersion> = [
|
||||
{ title: "", version: "null", body: [ ] }
|
||||
];
|
||||
|
||||
const content = fs.readFileSync(resolve("CHANGELOG.md")).toString();
|
||||
for (const line of content.split("\n")) {
|
||||
let match = line.match(/^ethers\/v(\S+)\s/);
|
||||
if (match) {
|
||||
changes.push({ version: match[1], title: line.trim(), body: [ ] });
|
||||
} else {
|
||||
const l = line.trim();
|
||||
if (l && !l.match(/^-+$/)) {
|
||||
changes[changes.length - 1].body.push(l);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
changes.shift();
|
||||
|
||||
return changes;
|
||||
}
|
27
src.ts/_admin/utils/date.ts
Normal file
27
src.ts/_admin/utils/date.ts
Normal file
@ -0,0 +1,27 @@
|
||||
|
||||
function repeat(c: string, length: number): string {
|
||||
if (c.length === 0) { throw new Error("too short"); }
|
||||
while(c.length < length) { c += c; }
|
||||
return c.substring(0, length);
|
||||
}
|
||||
|
||||
function zpad(value: number, length?: number): string {
|
||||
if (length == null) { length = 2; }
|
||||
const str = String(value);
|
||||
return repeat("0", length - str.length) + str;
|
||||
}
|
||||
|
||||
function getDate(date: Date): string {
|
||||
return [
|
||||
date.getFullYear(),
|
||||
zpad(date.getMonth() + 1),
|
||||
zpad(date.getDate())
|
||||
].join("-");
|
||||
}
|
||||
|
||||
export function getDateTime(date: Date): string {
|
||||
return getDate(date) + " " + [
|
||||
zpad(date.getHours()) ,
|
||||
zpad(date.getMinutes() + 1)
|
||||
].join(":");
|
||||
}
|
Loading…
Reference in New Issue
Block a user