Skip to content

Commit

Permalink
Fix: Add git hash to version on settings page
Browse files Browse the repository at this point in the history
  • Loading branch information
TheHolyRoger committed Sep 4, 2023
1 parent 0ef0486 commit e04ae40
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 10 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@
"lint:fix": "eslint --ext .ts,.tsx src --fix",
"mockAPI": "node mocks/mockAPI.js",
"mockWS": "node mocks/mockWS.js",
"start": "cross-env APP_VERSION=$(cat VERSION)-dev NODE_OPTIONS=--max_old_space_size=8192 webpack-dev-server --config ./webpack/development.ts",
"start": "cross-env NODE_OPTIONS=--max_old_space_size=8192 webpack-dev-server --config ./webpack/development.ts",
"start-mock": "npm-run-all -p start mockAPI",
"start-mock-ws": "npm-run-all -p start mockAPI mockWS",
"build": "cross-env APP_VERSION=$(cat VERSION) NODE_ENV=production NODE_OPTIONS=--max_old_space_size=8192 webpack --config ./webpack/production.ts",
"build": "cross-env NODE_ENV=production NODE_OPTIONS=--max_old_space_size=8192 webpack --config ./webpack/production.ts",
"build:mobile": "./scripts/build_capacitor.sh",
"build:mobile:android": "./scripts/build_capacitor_android.sh",
"build:mobile:ios": "./scripts/build_capacitor_ios.sh",
"build:mobile:android": "cross-env NODE_ENV=production NODE_OPTIONS=--max_old_space_size=8192 webpack --config ./webpack/mobile_android.ts",
"build:mobile:ios": "cross-env NODE_ENV=production NODE_OPTIONS=--max_old_space_size=8192 webpack --config ./webpack/mobile.ts",
"analyze": "cross-env ANALYZE=1 NODE_ENV=production NODE_OPTIONS=--max_old_space_size=8192 webpack --config ./webpack/production.ts --profile --json > stats.json",
"test": "jest --config jest.config.js --silent",
"test:coverage": "jest --config jest.config.js --collectCoverage=true",
Expand Down
1 change: 0 additions & 1 deletion scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/bin/sh

export REACT_APP_GIT_SHA=$(git rev-parse --short HEAD)
export BUILD_DOMAIN=${BUILD_DOMAIN:-$(cat .domains)}
[ -n "$BUILD_EXPIRE" ] && export REACT_APP_BUILD_EXPIRE=$(date -d "+${BUILD_EXPIRE}" +%s000)

Expand Down
4 changes: 3 additions & 1 deletion scripts/build_capacitor_android.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/sh

cross-env APP_VERSION=$(cat VERSION) NODE_ENV=production NODE_OPTIONS=--max_old_space_size=8192 webpack --config ./webpack/mobile_android.ts
export REACT_APP_GIT_SHA=$(git rev-parse --short HEAD)

yarn build:mobile:android

npx cap add android

Expand Down
4 changes: 3 additions & 1 deletion scripts/build_capacitor_ios.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/sh

cross-env APP_VERSION=$(cat VERSION) NODE_ENV=production NODE_OPTIONS=--max_old_space_size=8192 webpack --config ./webpack/mobile.ts
export REACT_APP_GIT_SHA=$(git rev-parse --short HEAD)

yarn build:mobile:ios

npx cap add ios

Expand Down
4 changes: 3 additions & 1 deletion src/components/Settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ const SettingsComponent: React.FC = () => {
<TableCell className={classes.descriptionCol} component="th" scope="row">
App Version
</TableCell>
<TableCell>{process.env.APP_VERSION}</TableCell>
<TableCell>
{process.env.APP_VERSION}-{process.env.REACT_APP_GIT_SHA}
</TableCell>
</TableRow>
);
}, [classes.descriptionCol]);
Expand Down
10 changes: 8 additions & 2 deletions webpack/common.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const fs = require('fs');
import { DefinePlugin } from 'webpack';
import webpack from 'webpack';
import ESLintPlugin from 'eslint-webpack-plugin';
Expand All @@ -12,6 +13,8 @@ import alias from './alias.js';
const rootDir = path.resolve(__dirname, '..');
const BUILD_DIR = path.resolve(rootDir, 'public');

const app_version = fs.readFileSync('VERSION').toString();

const config: webpack.Configuration = {
output: {
path: BUILD_DIR,
Expand All @@ -20,8 +23,11 @@ const config: webpack.Configuration = {
publicPath: '/',
},
plugins: [
new DefinePlugin({ 'process.env.BUILD_EXPIRE': JSON.stringify(process.env.BUILD_EXPIRE) }),
new DefinePlugin({ 'process.env.APP_VERSION': JSON.stringify(process.env.APP_VERSION) }),
new DefinePlugin({
'process.env.BUILD_EXPIRE': JSON.stringify(process.env.BUILD_EXPIRE),
'process.env.REACT_APP_GIT_SHA': JSON.stringify(process.env.REACT_APP_GIT_SHA || 'dev'),
'process.env.APP_VERSION': JSON.stringify(app_version),
}),
new webpack.EnvironmentPlugin({
envType: 'dev',
}),
Expand Down

0 comments on commit e04ae40

Please sign in to comment.