Skip to content

Commit 7d3d46d

Browse files
Fix bug with incorrect version number & add git hash to overview (#1791)
* Fix bug with incorrect version number & add git hash to overview * Inject instead of fetching
1 parent bce3065 commit 7d3d46d

File tree

5 files changed

+42
-69
lines changed

5 files changed

+42
-69
lines changed

build_scripts/generate-manifest-helpers.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,8 @@ function buildTargetObject(data, dataProp) {
4444
return out
4545
}
4646

47-
function mergeObjects(source, target) {
48-
return { ...target, ...source }
49-
}
50-
5147
module.exports = {
5248
loadDataFromFile,
5349
writeDataToFile,
54-
buildTargetObject,
55-
mergeObjects
50+
buildTargetObject
5651
}

build_scripts/webpack-plugins.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin')
3333
const manifestGeneration = require('./generate-manifest-helpers')
3434
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin')
3535

36+
const builtAt = new Date().toISOString()
37+
const buildNumber = process.env.BUILD_NUMBER
38+
const gitHash = process.env.GIT_HASH
39+
3640
module.exports = () => {
3741
const plugins = [
3842
new webpack.DefinePlugin({
@@ -62,11 +66,11 @@ module.exports = () => {
6266
)
6367

6468
const mergedData = {
65-
...wantedData,
6669
...JSON.parse(content),
67-
// This is so we can give better build info in the sidebar
68-
builtAt: new Date().toISOString(),
69-
buildNumber: process.env.BUILD_NUMBER
70+
...wantedData,
71+
builtAt,
72+
buildNumber,
73+
gitHash
7074
}
7175
return JSON.stringify(mergedData, null, 2)
7276
}
@@ -77,6 +81,11 @@ module.exports = () => {
7781
}
7882
]
7983
}),
84+
new webpack.DefinePlugin({
85+
__BUILT_AT__: JSON.stringify(builtAt),
86+
__BUILD_NUMBER__: JSON.stringify(buildNumber),
87+
__GIT_HASH__: JSON.stringify(gitHash)
88+
}),
8089
new MiniCssExtractPlugin({
8190
// Options similar to the same options in webpackOptions.output
8291
// both options are optional

src/browser/AppInit.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import { version } from 'project-root/package.json'
5151
import { applyKeys, createReduxMiddleware, getAll } from 'services/localstorage'
5252
import { detectRuntimeEnv, isRunningE2ETest } from 'services/utils'
5353
import { GlobalState } from 'shared/globalState'
54-
import { APP_START, updateBuildInfo } from 'shared/modules/app/appDuck'
54+
import { APP_START } from 'shared/modules/app/appDuck'
5555
import { NEO4J_CLOUD_DOMAINS } from 'shared/modules/settings/settingsDuck'
5656
import { getUuid, updateUdcData } from 'shared/modules/udc/udcDuck'
5757
import epics from 'shared/rootEpic'
@@ -241,15 +241,6 @@ if (auraNtId) {
241241
}
242242
store.dispatch(updateUdcData({ auraNtId }))
243243

244-
fetch('./manifest.json')
245-
.then(res => res.json())
246-
.then(json => {
247-
if (json.buildNumber || json.builtAt) {
248-
store.dispatch(updateBuildInfo(json))
249-
}
250-
})
251-
.catch(() => undefined)
252-
253244
// typePolicies allow apollo cache to use these fields as 'id'
254245
// for automated cache updates when updating a single existing entity
255246
// https://www.apollographql.com/docs/react/caching/cache-configuration/#customizing-identifier-generation-by-type

src/browser/modules/Sidebar/About.tsx

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ import {
3131
} from 'browser-components/drawer/drawer-styled'
3232
import { version as browserVersion } from 'project-root/package.json'
3333
import { getEdition, getRawVersion } from 'shared/modules/dbMeta/dbMetaDuck'
34-
import { getBuiltAt, getBuildNumber } from 'shared/modules/app/appDuck'
3534
import { copyToClipboard } from 'neo4j-arc/common'
35+
import { GlobalState } from 'shared/globalState'
3636

3737
function asChangeLogUrl(serverVersion: string): string | undefined {
3838
if (!serverVersion) {
@@ -48,16 +48,14 @@ function asChangeLogUrl(serverVersion: string): string | undefined {
4848
interface AboutProps {
4949
serverVersion: string | null
5050
serverEdition: string | null
51-
builtAt: string | null
52-
buildNumber: string | null
5351
}
5452

55-
const About = ({
56-
serverVersion,
57-
serverEdition,
58-
builtAt,
59-
buildNumber
60-
}: AboutProps) => (
53+
// Injected by webpack
54+
declare const __GIT_HASH__: string | undefined
55+
declare const __BUILD_NUMBER__: string | undefined
56+
declare const __BUILT_AT__: string | undefined
57+
58+
const About = ({ serverVersion, serverEdition }: AboutProps) => (
6159
<Drawer id="db-about">
6260
<DrawerHeader>About Neo4j</DrawerHeader>
6361
<DrawerBody>
@@ -87,16 +85,6 @@ const About = ({
8785
{browserVersion}
8886
</a>
8987
</p>
90-
{buildNumber && (
91-
<div onClick={() => copyToClipboard(buildNumber)}>
92-
Build number: {buildNumber}
93-
</div>
94-
)}
95-
{builtAt && (
96-
<div onClick={() => copyToClipboard(builtAt)}>
97-
Build date: {new Date(builtAt).toLocaleDateString('se')}
98-
</div>
99-
)}
10088
{serverVersion && serverEdition && (
10189
<p>
10290
Neo4j Server version:{' '}
@@ -119,6 +107,21 @@ const About = ({
119107
Neo4j Browser Changelog
120108
</a>
121109
</p>
110+
{__BUILD_NUMBER__ && (
111+
<div onClick={() => copyToClipboard(__BUILD_NUMBER__)}>
112+
Build number: {__BUILD_NUMBER__}
113+
</div>
114+
)}
115+
{__GIT_HASH__ && (
116+
<div onClick={() => copyToClipboard(__GIT_HASH__)}>
117+
Build hash: {__GIT_HASH__.slice(0, 18)}
118+
</div>
119+
)}
120+
{__BUILT_AT__ && (
121+
<div onClick={() => copyToClipboard(__BUILT_AT__)}>
122+
Build date: {new Date(__BUILT_AT__).toLocaleDateString('se')}
123+
</div>
124+
)}
122125
</DrawerSectionBody>
123126
</DrawerSection>
124127
<DrawerSection>
@@ -205,13 +208,10 @@ const About = ({
205208
<DrawerFooter>With &#9829; from Sweden.</DrawerFooter>
206209
</Drawer>
207210
)
208-
const mapStateToProps = (state: any) => {
209-
return {
210-
serverVersion: getRawVersion(state),
211-
serverEdition: getEdition(state),
212-
builtAt: getBuiltAt(state),
213-
buildNumber: getBuildNumber(state)
214-
}
215-
}
211+
212+
const mapStateToProps = (state: GlobalState) => ({
213+
serverVersion: getRawVersion(state),
214+
serverEdition: getEdition(state)
215+
})
216216

217217
export default connect(mapStateToProps)(About)

src/shared/modules/app/appDuck.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ export const inWebBrowser = (state: GlobalState): boolean =>
5454
[WEB, CLOUD].includes(getEnv(state))
5555
export const inDesktop = (state: GlobalState): boolean =>
5656
getEnv(state) === DESKTOP
57-
export const getBuildNumber = (state: GlobalState): string | null =>
58-
state[NAME].buildNumber ?? null
59-
export const getBuiltAt = (state: GlobalState): string | null =>
60-
state[NAME].builtAt ?? null
6157

6258
export const getAllowedBoltSchemes = (
6359
state: GlobalState,
@@ -83,25 +79,13 @@ export const isRelateAvailable = (state: GlobalState): boolean =>
8379
export const getProjectId = (state: GlobalState): string | undefined =>
8480
state[NAME].relateProjectId
8581

86-
// action creators
87-
export const updateBuildInfo = (action: {
88-
buildNumber?: string
89-
builtAt?: string
90-
}) => ({
91-
type: UPDATE_BUILD_INFO,
92-
buildNumber: action.buildNumber,
93-
builtAt: action.builtAt
94-
})
95-
9682
export type AppState = {
9783
hostedUrl?: string | null
9884
env?: Environment
9985
relateUrl?: string
10086
relateApiToken?: string
10187
relateProjectId?: string
10288
neo4jDesktopGraphAppId?: string
103-
builtAt?: string | null
104-
buildNumber?: string | null
10589
}
10690

10791
// Reducer
@@ -120,12 +104,6 @@ export default function reducer(
120104
relateProjectId: action.relateProjectId,
121105
neo4jDesktopGraphAppId: action.neo4jDesktopGraphAppId
122106
}
123-
case UPDATE_BUILD_INFO:
124-
return {
125-
...state,
126-
builtAt: action.builtAt,
127-
buildNumber: action.buildNumber
128-
}
129107
default:
130108
return state
131109
}

0 commit comments

Comments
 (0)