Skip to content

Commit 792b2c0

Browse files
feat: migrate injection script to typescript (#547)
add
1 parent 4787af2 commit 792b2c0

File tree

4 files changed

+65
-61
lines changed

4 files changed

+65
-61
lines changed

.github/workflows/build-frontend.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@ jobs:
3232
- name: Checkout repository
3333
uses: actions/checkout@v6
3434

35-
- name: Set up Python
36-
uses: actions/setup-python@v6
37-
38-
- name: Inject Version
39-
run: python scripts/inject_version.py
40-
4135
- name: Set up Node.js ${{ matrix.node-version }}
4236
uses: actions/setup-node@v6
4337
with:
@@ -48,6 +42,9 @@ jobs:
4842
- name: Install dependencies
4943
run: npm i
5044

45+
- name: Inject Version
46+
run: node --experimental-strip-types scripts/inject-version.ts
47+
5148
- name: Build (Node adapter)
5249
run: npm run build
5350
env:

.github/workflows/docker-build-frontend.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,14 @@ jobs:
4141
with:
4242
fetch-depth: 0
4343

44-
- name: Set up Python
45-
uses: actions/setup-python@v6
44+
- name: Set up Node.js
45+
uses: actions/setup-node@v6
4646
with:
47-
python-version: '3.x'
48-
47+
node-version: latest
48+
4949
- name: Inject Version
50-
run: python ./src/frontend/scripts/inject_version.py
50+
working-directory: ./src/frontend
51+
run: node --experimental-strip-types scripts/inject-version.ts
5152
env:
5253
GITHUB_REF_NAME: ${{ github.ref_name }}
5354
GITHUB_REF_TYPE: ${{ github.ref_type }}
@@ -135,4 +136,4 @@ jobs:
135136
DIGEST_ARGS=$(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *)
136137
137138
# Execute the command
138-
docker buildx imagetools create $TAG_ARGS $DIGEST_ARGS
139+
docker buildx imagetools create $TAG_ARGS $DIGEST_ARGS
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { execSync } from 'node:child_process';
2+
import { writeFileSync } from 'node:fs';
3+
import { dirname, join } from 'node:path';
4+
import { fileURLToPath } from 'node:url';
5+
6+
const __dirname = dirname(fileURLToPath(import.meta.url));
7+
const outPath = join(__dirname, '..', 'build-info.json');
8+
9+
/**
10+
* Run a git command and return its output, or null on failure
11+
*/
12+
function git(cmd: string): string | null {
13+
try {
14+
return execSync(cmd, { stdio: ['ignore', 'pipe', 'ignore'] })
15+
.toString()
16+
.trim();
17+
} catch {
18+
return null;
19+
}
20+
}
21+
22+
// Get current commit hash
23+
const commit = git('git rev-parse --short HEAD') ?? 'unknown';
24+
25+
// Determine Version Logic
26+
const ghRefName = process.env.GITHUB_REF_NAME;
27+
const ghRefType = process.env.GITHUB_REF_TYPE;
28+
29+
let version: string;
30+
31+
if (ghRefType === 'tag') {
32+
// Case: This is a formal GitHub Release/Tag
33+
version = ghRefName ?? 'unknown';
34+
} else {
35+
// Fallback: Try to find the latest tag in history (requires fetch-depth: 0)
36+
const lastTag = git('git describe --tags --abbrev=0');
37+
if (lastTag) {
38+
version = `${lastTag}-${commit}`;
39+
} else {
40+
// No tags found in history at all
41+
version = `v0.0.0-${commit}`;
42+
}
43+
}
44+
45+
// Write Output
46+
const buildData = {
47+
version,
48+
commit,
49+
is_release: ghRefType === 'tag'
50+
};
51+
52+
writeFileSync(outPath, JSON.stringify(buildData, null, 2));
53+
54+
console.log(`Build info JSON created at: ${outPath}`);
55+
console.log(`Injected version: ${version}, commit: ${commit}`);

src/frontend/scripts/inject_version.py

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)