Skip to content

Commit

Permalink
chore: add git version
Browse files Browse the repository at this point in the history
  • Loading branch information
langdal committed Nov 18, 2022
1 parent 5d4d64f commit d0df60b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion src/components/version-info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div>
{versionInfo.version}
Expand Down
6 changes: 4 additions & 2 deletions src/context/experiment/reducers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
OptimizerConfig,
ValueVariableType,
} from '@/types/common'
import { versionInfo } from '@/components/version-info'

describe('experiment reducer', () => {
const initState: State = {
Expand Down Expand Up @@ -67,7 +68,7 @@ describe('experiment reducer', () => {
id: '5678',
changedSinceLastEvaluation: false,
info: {
swVersion: '',
swVersion: versionInfo.version,
name: 'Not cake',
description: 'Not yummy',
dataFormatVersion: currentVersion,
Expand Down Expand Up @@ -115,7 +116,8 @@ describe('experiment reducer', () => {
payload,
}

expect(rootReducer(initState, action)).toEqual({
const actual = rootReducer(initState, action)
expect(actual).toEqual({
experiment: payload,
})
})
Expand Down
1 change: 1 addition & 0 deletions src/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
interface ImportMetaEnv {
readonly VITE_PUBLIC_API_SERVER: string
readonly VITE_BASE_PATH: string
readonly VITE_BRANCH: string
}

interface ImportMeta {
Expand Down
23 changes: 23 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
/* eslint-disable @typescript-eslint/no-var-requires */
/// <reference types="vitest" />

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: [
Expand Down

0 comments on commit d0df60b

Please sign in to comment.