version based on git hash

This commit is contained in:
Timo Bejan 2023-06-22 23:04:48 +03:00
parent c598b8e572
commit 8ec9881905
7 changed files with 30 additions and 11 deletions

3
.git-version.json Normal file
View File

@ -0,0 +1,3 @@
{
"hash": "development"
}

1
.gitignore vendored
View File

@ -49,3 +49,4 @@ migrations.json
*.iml
docker-compose.yml
.git-version.json

View File

@ -11,8 +11,8 @@ if (environment.production) {
// https://github.com/angular/angular/issues/11195#issuecomment-248020928
async function bootstrap(appConfig: AppConfig) {
const packageJson = await import('package.json');
const config = { ...appConfig, FRONTEND_APP_VERSION: packageJson.version };
const packageJson = await import('.git-version.json');
const config = { ...appConfig, FRONTEND_APP_VERSION: packageJson.hash };
console.log('Started with local config: ', config);
const appModule = appModuleFactory(config);

View File

@ -27,18 +27,13 @@ COPY libs libs
COPY tools tools
COPY package.json package.json
COPY version.json version.json
RUN cat version.json
RUN version=$(jq .FRONTEND_APP_VERSION version.json -r | cat) && \
jq --arg version "$version" '.version = $version' package.json > tmp.json && \
mv tmp.json package.json
RUN cat package.json
COPY yarn.lock yarn.lock
COPY nx.json nx.json
COPY .eslintrc.json .eslintrc.json
COPY tsconfig.json tsconfig.json
COPY paligo-styles paligo-styles
COPY sonar.js sonar.js
COPY grab-git-info.js grab-git-info.js
## Build the angular app in production mode and store the artifacts in dist folder

8
grab-git-info.js Normal file
View File

@ -0,0 +1,8 @@
const { gitDescribeSync } = require('git-describe');
const { writeFileSync } = require('fs');
const path = require('path');
const info = gitDescribeSync();
const infoJson = JSON.stringify(info, null, 2);
writeFileSync(path.join(__dirname, '/.git-version.json'), infoJson);

View File

@ -5,7 +5,8 @@
"license": "MIT",
"scripts": {
"build": "nx build",
"build-lint-all": "nx build --project=red-ui --configuration production --base-href /ui/",
"set-git-version": "node grab-git-info.js",
"build-lint-all": "node grab-git-info.js && nx build --project=red-ui --configuration production --base-href /ui/",
"build-paligo-styles": "mkdir -p dist/paligo-styles && sass --load-path=. paligo-styles/style.scss > dist/paligo-styles/redacto-theme.css",
"i18n:extract": "ngx-translate-extract --input ./apps/red-ui/src ./libs/common-ui/src --output apps/red-ui/src/assets/i18n/{redact,scm}/{en,de}.json --clean --sort --format namespaced-json && prettier apps/red-ui/src/assets/i18n/*/*.json --write",
"nx": "nx",
@ -110,6 +111,7 @@
"typescript": "5.1.3",
"webpack": "5.87.0",
"webpack-bundle-analyzer": "^4.8.0",
"xliff": "^6.1.0"
"xliff": "^6.1.0",
"git-describe": "^4.1.1"
}
}

View File

@ -3847,7 +3847,7 @@
resolved "https://registry.yarnpkg.com/@types/retry/-/retry-0.12.0.tgz#2b35eccfcee7d38cd72ad99232fbd58bffb3c84d"
integrity sha512-wWKOClTTiizcZhXnPY4wikVAwmdYHp8q6DmC+EJUzAMsycb7HB32Kh9RN4+0gExjmPmZSAQjgURXIGATPegAvA==
"@types/semver@^7.3.12":
"@types/semver@^7.3.12", "@types/semver@^7.3.8":
version "7.5.0"
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.5.0.tgz#591c1ce3a702c45ee15f47a42ade72c2fd78978a"
integrity sha512-G8hZ6XJiHnuhQKR7ZmysCeJWE08o8T0AXtk5darsCaTVsYZhhgUrq53jizaR2FvsoeCwJhlmwTjkXBY5Pn/ZHw==
@ -6990,6 +6990,16 @@ gettext-parser@^4.2.0:
readable-stream "^3.6.0"
safe-buffer "^5.2.1"
git-describe@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/git-describe/-/git-describe-4.1.1.tgz#a2a2882e442aa68abd0b3cb467459c83ed2f96ef"
integrity sha512-JC8ganO5kO80G8+XE98TDDjnMXQN3Estk3qdJuG2EGRF/l6zuMTMcN+8OSfQZ5FWpqIRLB015anWX4aSRgnxAQ==
dependencies:
"@types/semver" "^7.3.8"
lodash "^4.17.21"
optionalDependencies:
semver "^5.6.0"
glob-parent@^5.1.2, glob-parent@~5.1.2:
version "5.1.2"
resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-5.1.2.tgz#869832c58034fe68a4093c17dc15e8340d8401c4"