diff --git a/.github/workflows/frontend_build_test_libraries.yml b/.github/workflows/frontend_build_test_libraries.yml index fba34d7920..5ddac90da7 100644 --- a/.github/workflows/frontend_build_test_libraries.yml +++ b/.github/workflows/frontend_build_test_libraries.yml @@ -5,12 +5,6 @@ permissions: on: workflow_call: - inputs: - project_version: - description: "The determined project version. Required for release-candidate and releases, not for snapshot" - required: false - type: string - default: "" outputs: build_artifact_name: description: Build artifact this workflow produces that can be retrieved with the 'download-artifact' action @@ -146,8 +140,6 @@ jobs: PROJECT_VERSION: ${{ needs.determine_project_version.outputs.project_version }} run: | npm run libs-increment-all -- ${PROJECT_VERSION} - npm run copy-frontend-version - npx ng build @valtimo/shared - name: Cache built frontend libraries uses: actions/cache/save@v4 diff --git a/.github/workflows/frontend_publish_release_candidate.yml b/.github/workflows/frontend_publish_release_candidate.yml index 7997853581..9bc35eacf1 100644 --- a/.github/workflows/frontend_publish_release_candidate.yml +++ b/.github/workflows/frontend_publish_release_candidate.yml @@ -30,8 +30,6 @@ jobs: build_and_test: needs: ["determine_version"] uses: ./.github/workflows/frontend_build_test_libraries.yml - with: - project_version: ${{ needs.determine_version.outputs.project_version }} secrets: inherit publish: diff --git a/.github/workflows/frontend_publish_to_npm.yml b/.github/workflows/frontend_publish_to_npm.yml index 970d1af306..0e8297e131 100644 --- a/.github/workflows/frontend_publish_to_npm.yml +++ b/.github/workflows/frontend_publish_to_npm.yml @@ -6,6 +6,7 @@ on: project_version: description: "The determined project version. Required for release-candidate, not for snapshot" required: false + default: "" type: string frontend_libraries_build_artifact_name: required: true @@ -31,6 +32,30 @@ jobs: name: ${{ inputs.frontend_libraries_build_artifact_name }} path: frontend/dist + - name: Determine project version + id: determine_project_version + if: inputs.project_version == '' + env: + BRANCH_NAME: ${{ github.head_ref || github.ref_name }} + BUILD_NUMBER: ${{ github.run_number }} + run: | + # replace special characters with - and make all-lowercase + SAFE_BRANCH_NAME=$(echo "$BRANCH_NAME" | sed 's/[\/+|<>,;]/-/g' | tr '[:upper:]' '[:lower:]') + + SEMVER_VERSION=$(cat gradle.properties | grep 'projectVersion=' | cut -d '=' -f 2) + PROJECT_VERSION="${SEMVER_VERSION}-${SAFE_BRANCH_NAME}.${BUILD_NUMBER}" + + echo "Version is ${PROJECT_VERSION}" + echo "project_version=${PROJECT_VERSION}" >> $GITHUB_OUTPUT + + - name: Set project version on all libraries + env: + PROJECT_VERSION: ${{ inputs.project_version || steps.determine_project_version.outputs.project_version }} + run: | + npm run libs-increment-all -- ${PROJECT_VERSION} './projects/valtimo' + frontend_libs_version_asset='frontend/dist/valtimo/shared/assets/version.json' + jq ".appVersion = \"${PROJECT_VERSION}\"" "$frontend_libs_version_asset" + - name: "Publish all libs to NPM" env: NPM_JS_REPOSITORY_AUTH_TOKEN: ${{ secrets.NPM_JS_REPOSITORY_AUTH_TOKEN }} diff --git a/frontend/package.json b/frontend/package.json index b4d78e7e1a..d6bfbc8486 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -96,7 +96,6 @@ "libs:build-6:object-management": "ng build @valtimo/object-management", "libs:build-7:zgw": "ng build @valtimo/zgw", "libs:build-7:iko": "ng build @valtimo/iko", - "libs:build-7:copy-version": "npm run copy-frontend-version", "libs:build:case-migration": "ng build @valtimo/case-migration", "libs:build:keycloak": "ng build @valtimo/keycloak", "libs:build:form-view-model": "ng build @valtimo/form-view-model", @@ -190,7 +189,6 @@ "libs:lint:access-control-management": "ng lint @valtimo/access-control-management", "libs:lint:logging": "ng lint @valtimo/logging", "libs:lint:iko": "ng lint @valtimo/iko", - "copy-frontend-version": "node scripts/copy-frontend-version.js", "libs-increment-all": "node scripts/libs.increment.all.js", "libs-publish-all": "node scripts/libs.publish.all.js" }, @@ -361,4 +359,4 @@ "@nx/nx-darwin-arm64": "20.8.1", "@nx/nx-linux-x64-gnu": "20.8.1" } -} +} \ No newline at end of file diff --git a/frontend/projects/valtimo/shared/assets/version.json b/frontend/projects/valtimo/shared/assets/version.json new file mode 100644 index 0000000000..3919e71614 --- /dev/null +++ b/frontend/projects/valtimo/shared/assets/version.json @@ -0,0 +1,3 @@ +{ + "appVersion": "13.5.0" +} \ No newline at end of file diff --git a/frontend/projects/valtimo/shared/src/lib/constants/versions.ts b/frontend/projects/valtimo/shared/src/lib/constants/versions.ts index 0b8fbf9588..9bec151dbe 100644 --- a/frontend/projects/valtimo/shared/src/lib/constants/versions.ts +++ b/frontend/projects/valtimo/shared/src/lib/constants/versions.ts @@ -16,8 +16,23 @@ import {Versions} from '../models'; +async function getLibVersion() { + let version = 'unknown'; + try { + const VERSION_ASSET_URL = '/valtimo-translation/version.json'; + const versionRes = await fetch(VERSION_ASSET_URL); + const versionJson = await versionRes.json(); + version = versionJson.appVersion; + } catch (err) { + console.error(err); + } + return version; +} + const VERSIONS: Versions = { - frontendLibraries: '13.0.1', -}; + frontendLibraries: 'unknown', +} as Versions; + +getLibVersion().then(version => (VERSIONS.frontendLibraries = version)); export {VERSIONS};