diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 65435881..6e0d4d0f 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -18,6 +18,7 @@ on:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
+ BRANCH: ${{ github.ref_name }}
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
diff --git a/src/components/version-info.tsx b/src/components/version-info.tsx
index 51eb5ddd..553cc7db 100644
--- a/src/components/version-info.tsx
+++ b/src/components/version-info.tsx
@@ -12,7 +12,8 @@ export const versionInfo = {
}
export const VersionInfo = () => {
- const showBranch = !/^HEAD$|^main$/.test(versionInfo.branch)
+ const showBranch =
+ versionInfo.branch !== '' && !/^HEAD$|^main$/.test(versionInfo.branch)
return (
{versionInfo.version}
diff --git a/src/context/experiment/reducers.test.ts b/src/context/experiment/reducers.test.ts
index ad5c2918..3b412bc1 100644
--- a/src/context/experiment/reducers.test.ts
+++ b/src/context/experiment/reducers.test.ts
@@ -10,6 +10,7 @@ import {
OptimizerConfig,
ValueVariableType,
} from '@/types/common'
+import { versionInfo } from '@/components/version-info'
describe('experiment reducer', () => {
const initState: State = {
@@ -67,7 +68,7 @@ describe('experiment reducer', () => {
id: '5678',
changedSinceLastEvaluation: false,
info: {
- swVersion: '',
+ swVersion: versionInfo.version,
name: 'Not cake',
description: 'Not yummy',
dataFormatVersion: currentVersion,
@@ -115,7 +116,8 @@ describe('experiment reducer', () => {
payload,
}
- expect(rootReducer(initState, action)).toEqual({
+ const actual = rootReducer(initState, action)
+ expect(actual).toEqual({
experiment: payload,
})
})
diff --git a/src/env.d.ts b/src/env.d.ts
index 1a9562f7..7578d9ad 100644
--- a/src/env.d.ts
+++ b/src/env.d.ts
@@ -3,6 +3,7 @@
interface ImportMetaEnv {
readonly VITE_PUBLIC_API_SERVER: string
readonly VITE_BASE_PATH: string
+ readonly VITE_BRANCH: string
}
interface ImportMeta {
diff --git a/vite.config.ts b/vite.config.ts
index c7df81b8..f4d02e5e 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -1,12 +1,35 @@
+/* eslint-disable @typescript-eslint/no-var-requires */
///
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
const path = require('path')
+const child_process = require('child_process')
+
+const commitHash = child_process
+ .execSync('git rev-parse --short HEAD')
+ .toString()
+ .trim()
+
+const gitVersion = child_process
+ .execSync('git describe --tags --always --first-parent --dirty')
+ .toString()
+ .trim()
+
+const gitBranch = child_process
+ .execSync('git branch --show-current')
+ .toString()
+ .trim()
+
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
+ define: {
+ COMMITHASH: JSON.stringify(commitHash),
+ VERSION: JSON.stringify(gitVersion),
+ BRANCH: process.env.BRANCH || JSON.stringify(gitBranch),
+ },
base: '/',
resolve: {
alias: [