From 6754b5070a42173afda88cb0d723d6d2ca31da13 Mon Sep 17 00:00:00 2001 From: Etienne Donneger Date: Mon, 22 Apr 2024 18:01:55 -0400 Subject: [PATCH] Include commit hash in `APP_VERSION` constant (#10) Try to read the commit hash from the `APP_VERSION` environment variable and export it along the API release version in `config.ts`. --- package.json | 10 +++++----- src/config.ts | 3 ++- src/logger.ts | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 4a04ba1..8e367ff 100644 --- a/package.json +++ b/package.json @@ -18,11 +18,11 @@ } ], "scripts": { - "start": "bun index.ts", - "dev": "bun --watch index.ts", - "lint": "bunx tsc --noEmit --skipLibCheck --pretty", - "test": "bun test --coverage", - "build": "bun build --compile ./index.ts --outfile antelope-token-api" + "start": "export APP_VERSION=$(git rev-parse --short HEAD) && bun index.ts", + "dev": "export APP_VERSION=$(git rev-parse --short HEAD) && bun --watch index.ts", + "lint": "export APP_VERSION=$(git rev-parse --short HEAD) && bunx tsc --noEmit --skipLibCheck --pretty", + "test": "export APP_VERSION=$(git rev-parse --short HEAD) && bun test --coverage", + "build": "export APP_VERSION=$(git rev-parse --short HEAD) && bun build --compile ./index.ts --outfile antelope-token-api" }, "dependencies": { "@clickhouse/client-web": "latest", diff --git a/src/config.ts b/src/config.ts index c0cf903..1fbd3f4 100644 --- a/src/config.ts +++ b/src/config.ts @@ -14,11 +14,12 @@ export const DEFAULT_MAX_LIMIT = 10000; export const DEFAULT_VERBOSE = false; export const DEFAULT_SORT_BY = "DESC"; export const APP_NAME = pkg.name; +export const APP_VERSION = `${pkg.version}+${process.env.APP_VERSION || "unknown"}`; // parse command line options const opts = program .name(pkg.name) - .version(pkg.version) + .version(APP_VERSION) .description(pkg.description) .showHelpAfterError() .addOption(new Option("-p, --port ", "HTTP port on which to attach the API").env("PORT").default(DEFAULT_PORT)) diff --git a/src/logger.ts b/src/logger.ts index 60b635a..1eac7ab 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -1,11 +1,11 @@ import { Logger, type ILogObj } from "tslog"; -import { name } from "../package.json" assert { type: "json" }; +import { APP_NAME, APP_VERSION } from "./config.js"; class TsLogger extends Logger { constructor() { super(); this.settings.minLevel = 5; - this.settings.name = name; + this.settings.name = `${APP_NAME}:${APP_VERSION}`; } public enable(type: "pretty" | "json" = "pretty") {