From 8ec98819054427ef36b53aaf394465d24cc4c176 Mon Sep 17 00:00:00 2001 From: Timo Bejan Date: Thu, 22 Jun 2023 23:04:48 +0300 Subject: [PATCH] version based on git hash --- .git-version.json | 3 +++ .gitignore | 1 + apps/red-ui/src/main.ts | 4 ++-- docker/red-ui/Dockerfile | 7 +------ grab-git-info.js | 8 ++++++++ package.json | 6 ++++-- yarn.lock | 12 +++++++++++- 7 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 .git-version.json create mode 100644 grab-git-info.js diff --git a/.git-version.json b/.git-version.json new file mode 100644 index 000000000..04d44e690 --- /dev/null +++ b/.git-version.json @@ -0,0 +1,3 @@ +{ + "hash": "development" +} diff --git a/.gitignore b/.gitignore index 235ccbb05..dfb6d83a7 100644 --- a/.gitignore +++ b/.gitignore @@ -49,3 +49,4 @@ migrations.json *.iml docker-compose.yml +.git-version.json diff --git a/apps/red-ui/src/main.ts b/apps/red-ui/src/main.ts index 9560fe8a2..fa84d6a05 100644 --- a/apps/red-ui/src/main.ts +++ b/apps/red-ui/src/main.ts @@ -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); diff --git a/docker/red-ui/Dockerfile b/docker/red-ui/Dockerfile index 59e4ca2a3..b61e71f2f 100644 --- a/docker/red-ui/Dockerfile +++ b/docker/red-ui/Dockerfile @@ -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 diff --git a/grab-git-info.js b/grab-git-info.js new file mode 100644 index 000000000..ecd85ddb8 --- /dev/null +++ b/grab-git-info.js @@ -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); diff --git a/package.json b/package.json index 54c8db333..d804642ea 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/yarn.lock b/yarn.lock index 32b342a21..adbc36530 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"