Skip to content

Commit a7849dd

Browse files
update app version build (#24)
1 parent 9f021f3 commit a7849dd

File tree

11 files changed

+65
-45
lines changed

11 files changed

+65
-45
lines changed

.github/workflows/ghcr.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,17 @@ jobs:
3838
type=sha,prefix=,suffix=-{{date 'X'}}
3939
type=raw,enable=${{ !startsWith(github.ref, 'refs/tags/') }},value=develop
4040
type=semver,pattern={{raw}}
41-
41+
- run: echo "GIT_DATE=$(git log -1 --format=%cd --date=short)" >> $GITHUB_ENV
42+
- run: echo "GIT_VERSION=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV
4243
- name: Build and push Docker image
4344
uses: docker/build-push-action@v5
4445
with:
4546
context: .
4647
push: true
4748
tags: ${{ steps.meta.outputs.tags }}
4849
labels: ${{ steps.meta.outputs.labels }}
49-
# Pass github.sha to Docker as GIT_COMMIT
50+
# Pass github.sha to Docker as GIT_COMMIT & GIT_DATE
5051
build-args: |
51-
GIT_COMMIT=${{ github.sha }}
52+
GIT_COMMIT=${{ github.sha }}
53+
GIT_DATE=${{ env.GIT_DATE }}
54+
GIT_VERSION=${{ env.GIT_VERSION }}

Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,17 @@ RUN bun install
66

77
# Declare a build argument for the Git commit hash
88
ARG GIT_COMMIT
9+
ARG GIT_VERSION
10+
ARG GIT_DATE
911

1012
# Set an environment variable inside the container
1113
ENV GIT_COMMIT=${GIT_COMMIT}
14+
ENV GIT_VERSION=${GIT_VERSION}
15+
ENV GIT_DATE=${GIT_DATE}
16+
17+
# https://github.com/opencontainers/image-spec/blob/main/annotations.md
18+
LABEL org.opencontainers.image.revision=$GIT_COMMIT
19+
LABEL org.opencontainers.image.version=$GIT_VERSION
20+
LABEL org.opencontainers.image.created=$GIT_DATE
1221

1322
ENTRYPOINT [ "bun", "run", "start" ]

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# The Graph: `Token API`
1+
# `Token API`
22

3-
[![.github/workflows/bun-test.yml](https://github.com/graphprotocol/token-api/actions/workflows/bun-test.yml/badge.svg)](https://github.com/graphprotocol/token-api/actions/workflows/bun-test.yml)
4-
![license](https://img.shields.io/github/license/graphprotocol/token-api)
3+
[![.github/workflows/bun-test.yml](https://github.com/pinax-network/pinax-token-api/actions/workflows/bun-test.yml/badge.svg)](https://github.com/pinax-network/pinax-token-api/actions/workflows/bun-test.yml)
4+
![license](https://img.shields.io/github/license/pinax-network/pinax-token-api)
55

6-
> Power your apps with real-time token data.
6+
> Power your apps & AI agents with real-time token data.
77
88
![banner](banner.jpg)
99

@@ -76,6 +76,8 @@ docker pull ghcr.io/graphprotocol/token-api:develop
7676
```bash
7777
docker build \
7878
--build-arg GIT_COMMIT="$(git rev-parse HEAD)" \
79+
--build-arg GIT_DATE="$(git log -1 --format=%cd --date=short)" \
80+
--build-arg GIT_VERSION="$(git describe --tags --abbrev=0)" \
7981
-t token-api .
8082
```
8183

bun.lock

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"zod-openapi": "^4.2.3",
2222
},
2323
"devDependencies": {
24-
"bun-types": "^1.2.5",
24+
"@types/bun": "^1.2.5",
2525
"typescript": "^5.8.2",
2626
},
2727
},
@@ -55,6 +55,8 @@
5555

5656
"@tokenizer/token": ["@tokenizer/[email protected]", "", {}, "sha512-OvjF+z51L3ov0OyAU0duzsYuvO01PH7x4t6DJx+guahgTnBHkhJdG7soQeTSFLWN3efnHyibZ4Z8l2EuWwJN3A=="],
5757

58+
"@types/bun": ["@types/[email protected]", "", { "dependencies": { "bun-types": "1.2.5" } }, "sha512-w2OZTzrZTVtbnJew1pdFmgV99H0/L+Pvw+z1P67HaR18MHOzYnTYOi6qzErhK8HyT+DB782ADVPPE92Xu2/Opg=="],
59+
5860
"@types/json-schema": ["@types/[email protected]", "", {}, "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA=="],
5961

6062
"@types/node": ["@types/[email protected]", "", { "dependencies": { "undici-types": "~6.20.0" } }, "sha512-iEUCUJoU0i3VnrCmgoWCXttklWcvoCIx4jzcP22fioIVSdTmjgoEvmAO/QPw6TcS9k5FrNgn4w7q5lGOd1CT5g=="],

index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ app.get('/openapi', openAPISpecs(app, {
2727
documentation: {
2828
info: {
2929
title: 'Token API (Beta)',
30-
version: APP_VERSION.version,
30+
version: APP_VERSION,
3131
description: 'Power your apps & AI agents with real-time token data.',
3232
},
3333
servers: [

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
{
22
"private": true,
33
"name": "token-api",
4-
"description": "The Graph: Token API",
5-
"version": "0.1.0",
6-
"homepage": "https://github.com/graphprotocol/token-api",
4+
"description": "Token API",
5+
"homepage": "https://github.com/pinax-network/pinax-token-api",
76
"license": "Apache-2.0",
87
"type": "module",
98
"authors": [
@@ -51,6 +50,6 @@
5150
},
5251
"devDependencies": {
5352
"typescript": "^5.8.2",
54-
"bun-types": "^1.2.5"
53+
"@types/bun": "^1.2.5"
5554
}
5655
}

src/config.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import "dotenv/config";
2-
import { z } from 'zod';
2+
import { date, z } from 'zod';
33
import { Option, program } from "commander";
4+
import { $ } from "bun";
45

56
import pkg from "../package.json" with { type: "json" };
67

@@ -20,24 +21,30 @@ export const DEFAULT_IDLE_TIMEOUT = 60;
2021
export const DEFAULT_PRETTY_LOGGING = false;
2122
export const DEFAULT_VERBOSE = false;
2223
export const DEFAULT_SORT_BY = "DESC";
23-
export const APP_NAME = pkg.name;
24-
export const APP_DESCRIPTION = pkg.description;
25-
export const GIT_COMMIT = process.env.GIT_COMMIT || "unknown";
26-
export const APP_VERSION = {
27-
version: pkg.version as `${number}.${number}.${number}`,
28-
commit: GIT_COMMIT
29-
};
3024
export const DEFAULT_AGE = 30;
3125
export const DEFAULT_MAX_AGE = 180;
3226
export const DEFAULT_PAGE = 1;
3327
export const DEFAULT_LIMIT = 10;
3428
export const DEFAULT_NETWORK_ID = "mainnet";
3529
export const DEFAULT_NETWORKS = "arbitrum-one,base,bsc,mainnet"
3630

31+
// GitHub metadata
32+
const GIT_COMMIT = process.env.GIT_COMMIT || await $`git rev-parse HEAD`.text();
33+
const GIT_DATE = process.env.GIT_DATE ?? await $`git log -1 --format=%cd --date=short`.text();
34+
const GIT_VERSION = process.env.GIT_VERSION ?? await $`git describe --tags --abbrev=0`.text();
35+
export const GIT_APP = {
36+
version: GIT_VERSION.replace(/\n/, "") as `${number}.${number}.${number}`,
37+
commit: GIT_COMMIT.slice(0, 7),
38+
date: GIT_DATE.replace(/\n/, "") as `${number}-${number}-${number}`,
39+
};
40+
export const APP_NAME = pkg.name;
41+
export const APP_DESCRIPTION = pkg.description;
42+
export const APP_VERSION = `${GIT_APP.version}+${GIT_APP.commit} (${GIT_APP.date})`;
43+
3744
// parse command line options
3845
const opts = program
3946
.name(pkg.name)
40-
.version(`${APP_VERSION.version}+${APP_VERSION.commit}`)
47+
.version(APP_VERSION)
4148
.description(APP_DESCRIPTION)
4249
.showHelpAfterError()
4350
.addOption(new Option("-p, --port <number>", "HTTP port on which to attach the API").env("PORT").default(DEFAULT_PORT))

src/logger.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { Logger, type ILogObj } from "tslog";
2-
import { APP_NAME, APP_VERSION, config } from "./config.js";
2+
import { APP_VERSION, config } from "./config.js";
33

44
class TsLogger extends Logger<ILogObj> {
55
constructor() {
66
super();
77
this.settings.minLevel = 5;
8-
this.settings.name = `${APP_NAME}:${APP_VERSION.version}+${APP_VERSION.commit}`;
8+
this.settings.name = APP_VERSION;
99
}
1010

1111
public enable(type: "pretty" | "json" = "pretty") {

src/mcp/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { FastMCP } from "fastmcp";
22

3-
import { APP_DESCRIPTION, APP_VERSION, config } from "../config.js";
3+
import { APP_VERSION, config, GIT_APP } from "../config.js";
44
import { logger } from "../logger.js";
55
import tools from "./tools.js";
66
import prompts from "./prompts.js";
77
import { resources, resourceTemplates } from "./resources.js";
88

99
const mcp = new FastMCP({
10-
name: APP_DESCRIPTION,
11-
version: APP_VERSION.version,
10+
name: APP_VERSION,
11+
version: GIT_APP.version,
1212
});
1313

1414
// Catch session errors (default MCP SDK timeout of 10 seconds) and close connection

src/routes/version.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { Hono } from 'hono'
22
import { describeRoute } from 'hono-openapi'
33
import { resolver } from 'hono-openapi/zod'
4-
import { APP_VERSION } from '../config.js'
4+
import { GIT_APP } from '../config.js'
55
import { z } from 'zod'
66

77
const route = new Hono();
88

99
const responseSchema = z.object({
1010
version: z.string(),
11+
date: z.string(),
1112
commit: z.string(),
1213
});
1314

@@ -18,17 +19,14 @@ const openapi = describeRoute({
1819
200: {
1920
description: 'Successful Response',
2021
content: {
21-
'application/json': { schema: resolver(responseSchema), example: {
22-
version: APP_VERSION.version,
23-
commit: APP_VERSION.commit,
24-
} },
22+
'application/json': { schema: resolver(responseSchema), example: GIT_APP },
2523
},
2624
},
2725
},
2826
})
2927

3028
route.get('/version', openapi, (c) => {
31-
return c.json(APP_VERSION)
29+
return c.json(GIT_APP)
3230
});
3331

3432
export default route;

0 commit comments

Comments
 (0)