admin: update admin scripts to find meaningful head..

This commit is contained in:
Richard Moore 2022-09-29 23:17:36 -04:00
parent ad5b8da8bf
commit 7096b067da
2 changed files with 46 additions and 2 deletions

View File

@ -3,7 +3,7 @@ import semver from "semver";
import { FetchRequest } from "../utils/index.js";
import { atomicWrite } from "./utils/fs.js";
import { getGitTag } from "./utils/git.js";
import { getGitLog } from "./utils/git.js";
import { loadJson, saveJson } from "./utils/json.js";
import { resolve } from "./utils/path.js";
@ -39,7 +39,14 @@ function writeVersion(version: string): void {
const remotePkgInfo = remoteInfo.versions[remoteVersion];
const remoteGitHead = remotePkgInfo.gitHead;
const gitHead = await getGitTag(resolve("."));
//const gitHead = await getGitTag(resolve("."));
let gitHead = "";
for (const log of await getGitLog(".")) {
if (log.body.startsWith("admin:")) { continue; }
gitHead = log.commit;
break;
}
if (gitHead === "") { throw new Error("no meaningful commit found"); }
// There are new commits, not reflected in the package
// published on npm; update the gitHead and version

View File

@ -12,3 +12,40 @@ export async function getGitTag(filename: string): Promise<null | string> {
if (!hashMatch) { return null; }
return hashMatch[1];
}
export interface GitLog {
commit: string;
author: string;
date: string;
body: string;
}
export async function getGitLog(filename: string, limit?: number): Promise<Array<GitLog>> {
if (limit == null) { limit = 100; }
const result = await run("git", [ "log", "-n", String(limit), "--", filename ]);
if (!result.ok) { throw new Error(`git log error`); }
let log = result.stdout.trim();
if (!log) { return [ ]; }
const logs: Array<GitLog> = [ { commit: "", author: "", date: "", body: "" } ];
for (const line of log.split("\n")) {
const hashMatch = line.match(/^commit\s+([0-9a-f]{40})/i);
if (hashMatch) {
logs.push({ commit: hashMatch[1], author: "", date: "", body: "" });
} else {
if (line.startsWith("Author:")) {
logs[logs.length - 1].author = line.substring(7).trim();
} else if (line.startsWith("Date:")) {
logs[logs.length - 1].date = line.substring(5).trim();
} else {
logs[logs.length - 1].body = (logs[logs.length - 1].body + " " + line).trim();
}
}
}
// Nix the bootstrap entry
logs.shift();
return logs;
}