diff --git a/alfa-client/.prettierrc b/alfa-client/.prettierrc index a938a8601da77934caa995a32d3fb5916f7c473e..db361c13809eb7a7b514451f1b87543eb9280a0c 100644 --- a/alfa-client/.prettierrc +++ b/alfa-client/.prettierrc @@ -20,6 +20,7 @@ "embeddedLanguageFormatting": "auto", "plugins": [ "prettier-plugin-organize-imports", + "prettier-plugin-groovy", "prettier-plugin-tailwindcss" ], "tailwindConfig": "./libs/design-system/src/lib/tailwind-preset/tailwind.config.js" diff --git a/alfa-client/apps/info/Jenkinsfile b/alfa-client/apps/info/Jenkinsfile index 3d9b625cffe7e2f022a8759f384a593a04cf76a3..4fdc9be20bbe8b03d14d37a2b367687ef89d2e1d 100644 --- a/alfa-client/apps/info/Jenkinsfile +++ b/alfa-client/apps/info/Jenkinsfile @@ -4,67 +4,56 @@ pipeline { label 'ozgcloud-jenkins-build-agent-jdk21-node20' } } - environment { - BLUE_OCEAN_URL = "https://jenkins.infra.ozg-cloud.systems/job/info/job/${env.BRANCH_NAME}/${env.BUILD_NUMBER}/" - RELEASE_REGEX = /\d+.\d+.\d+/ - SNAPSHOT_REGEX = /\d+.\d+.\d+-SNAPSHOT/ - FAILED_STAGE = "" - SH_SUCCESS_STATUS_CODE = 0 - } - - options { - timeout(time: 1, unit: 'HOURS') - disableConcurrentBuilds() - buildDiscarder(logRotator(numToKeepStr: '5')) - } - - stages { - stage('Check Version') { - steps { - script { - FAILED_STAGE = env.STAGE_NAME - dir('alfa-client') { - VERSION = getPackagejsonVersion() - } - } - } + BLUE_OCEAN_URL = "https://jenkins.infra.ozg-cloud.systems/job/info/job/${env.BRANCH_NAME}/${env.BUILD_NUMBER}/" + RELEASE_REGEX = /\d+.\d+.\d+/ + SNAPSHOT_REGEX = /\d+.\d+.\d+-SNAPSHOT/ + FAILED_STAGE = "" + SH_SUCCESS_STATUS_CODE = 0 + } + options { + timeout(time: 1, unit: 'HOURS') + disableConcurrentBuilds() + buildDiscarder(logRotator(numToKeepStr: '5')) + } + stages { + stage('Check Version') { + steps { + script { + FAILED_STAGE = env.STAGE_NAME + dir('alfa-client') { + VERSION = getPackagejsonVersion() + } } - - stage('build info client and its docker image') { - steps { - script { - FAILED_STAGE=env.STAGE_NAME - - dir('alfa-client') { - sh 'echo "registry=https://nexus.ozg-sh.de/repository/npm-proxy" >> ~/.npmrc' - sh 'echo "//nexus.ozg-sh.de/:_auth=amVua2luczprTSFnNVUhMVQzNDZxWQ==" >> ~/.npmrc' - - sh 'npm cache verify' - sh 'npm install' - - sh 'npm run ci-build-info-by' - - // if (isMasterBranch()) { - // withSonarQubeEnv('sonarqube-ozg-sh'){ - // sh 'npm run ci-sonar' - // } - // } else { - // sh 'npm run ci-test' - // } - } - } + } + } + stage('build info client and its docker image') { + steps { + script { + FAILED_STAGE = env.STAGE_NAME + dir('alfa-client') { + sh 'echo "registry=https://nexus.ozg-sh.de/repository/npm-proxy" >> ~/.npmrc' + sh 'echo "//nexus.ozg-sh.de/:_auth=amVua2luczprTSFnNVUhMVQzNDZxWQ==" >> ~/.npmrc' + sh 'npm cache verify' + sh 'npm install' + sh 'npm run ci-build-info-by' + if (isMasterBranch()) { + withSonarQubeEnv('sonarqube-ozg-sh') { + sh 'npm run ci-sonar' + } + } else { + sh 'npm run ci-test' } + } } - + } + } // stage('Tag and Push Docker image') { // steps { // script { // FAILED_STAGE=env.STAGE_NAME // IMAGE_TAG = generateImageTag() - // tagAndPushDockerImage(IMAGE_TAG) - // if (isMasterBranch()) { // tagAndPushDockerImage('snapshot-latest') // } @@ -74,27 +63,21 @@ pipeline { // } // } // } - // stage('Test, build and deploy Helm Chart') { // steps { // script { // FAILED_STAGE=env.STAGE_NAME // HELM_CHART_VERSION = generateHelmChartVersion() - // dir('alfa-client/apps/admin') { // sh "./run_helm_test.sh" // } - // dir('alfa-client/apps/admin/src/main/helm') { - // sh "helm package --version=${HELM_CHART_VERSION} ." - // deployHelmChart(HELM_CHART_VERSION) // } // } // } // } - // stage('Trigger Dev rollout') { // when { // branch 'master' @@ -102,15 +85,12 @@ pipeline { // steps { // script { // FAILED_STAGE = env.STAGE_NAME - // cloneGitopsRepo() - // setNewDevVersion() // pushGitopsRepo() // } // } // } - // stage('Trigger Test rollout') { // when { // branch 'release-admin' @@ -118,169 +98,138 @@ pipeline { // steps { // script { // FAILED_STAGE = env.STAGE_NAME - // cloneGitopsRepo() - // setNewTestVersion() // pushGitopsRepo() // } // } // } // } - post { - failure { - script { - if (isMasterBranch() || isReleaseBranch()) { - sendFailureMessage() - } - } + failure { + script { + if (isMasterBranch() || isReleaseBranch()) { + sendFailureMessage() + } } + } } -} - - -Boolean isReleaseBranch() { + } + Boolean isReleaseBranch() { return env.BRANCH_NAME == 'release-admin' -} - -String generateImageTag() { + } + String generateImageTag() { def imageTag = "${env.BRANCH_NAME}-${VERSION}" - if (isMasterBranch()) { - imageTag += "-${env.GIT_COMMIT.take(7)}" + imageTag += "-${env.GIT_COMMIT.take(7)}" } - return imageTag -} - -Void cloneGitopsRepo() { + } + Void cloneGitopsRepo() { withCredentials([usernamePassword(credentialsId: 'jenkins-gitea-access-token', passwordVariable: 'TOKEN', usernameVariable: 'USER')]) { - sh 'git clone https://${USER}:${TOKEN}@git.ozg-sh.de/ozgcloud-devops/gitops.git' + sh 'git clone https://${USER}:${TOKEN}@git.ozg-sh.de/ozgcloud-devops/gitops.git' } configureGit() -} - -Void configureGit() { + } + Void configureGit() { final email = "jenkins@ozg-sh.de" final name = "jenkins" - dir("gitops") { - sh "git config user.email '${email}'" - sh "git config user.name '${name}'" + sh "git config user.email '${email}'" + sh "git config user.name '${name}'" } -} - -Void setNewDevVersion() { + } + Void setNewDevVersion() { setNewGitopsVersion("dev") -} - -Void setNewTestVersion() { + } + Void setNewTestVersion() { setNewGitopsVersion("test") -} - -Void setNewGitopsVersion(String environment) { + } + Void setNewGitopsVersion(String environment) { dir("gitops") { - def envFile = "${environment}/application/values/admin-client-values.yaml" - - def envVersions = readYaml file: envFile - - envVersions.admin_client.image.tag = IMAGE_TAG - envVersions.admin_client.helm.version = HELM_CHART_VERSION - - writeYaml file: envFile, data: envVersions, overwrite: true - - if (hasValuesFileChanged(environment)) { - sh "git add ${envFile}" - sh "git commit -m 'jenkins rollout ${environment} admin_client version ${IMAGE_TAG}'" - } + def envFile = "${environment}/application/values/admin-client-values.yaml" + def envVersions = readYaml file: envFile + envVersions.admin_client.image.tag = IMAGE_TAG + envVersions.admin_client.helm.version = HELM_CHART_VERSION + writeYaml file: envFile, data: envVersions, overwrite: true + if (hasValuesFileChanged(environment)) { + sh "git add ${envFile}" + sh "git commit -m 'jenkins rollout ${environment} admin_client version ${IMAGE_TAG}'" + } } -} - -Boolean hasValuesFileChanged(String environment) { + } + Boolean hasValuesFileChanged(String environment) { return sh (script: "git status | grep '${environment}/application/values/admin-client-values.yaml'", returnStatus: true) == env.SH_SUCCESS_STATUS_CODE as Integer -} - - -Void pushGitopsRepo() { + } + Void pushGitopsRepo() { withCredentials([usernamePassword(credentialsId: 'jenkins-gitea-access-token', passwordVariable: 'TOKEN', usernameVariable: 'USER')]) { - dir("gitops") { - if (hasUnpushedCommits()) { - sh 'git push https://${USER}:${TOKEN}@git.ozg-sh.de/ozgcloud-devops/gitops.git' - } + dir("gitops") { + if (hasUnpushedCommits()) { + sh 'git push https://${USER}:${TOKEN}@git.ozg-sh.de/ozgcloud-devops/gitops.git' } + } } -} - -Boolean hasUnpushedCommits() { + } + Boolean hasUnpushedCommits() { return sh (script: "git cherry -v | grep .", returnStatus: true) == env.SH_SUCCESS_STATUS_CODE as Integer -} - -Void tagAndPushDockerImage(String newTag){ + } + Void tagAndPushDockerImage(String newTag) { withCredentials([usernamePassword(credentialsId: 'jenkins-nexus-login', usernameVariable: 'USER', passwordVariable: 'PASSWORD')]) { - sh 'docker login docker.ozg-sh.de -u ${USER} -p ${PASSWORD}' - - sh "docker tag docker.ozg-sh.de/admin-client:build-latest docker.ozg-sh.de/admin-client:${newTag}" - sh "docker push docker.ozg-sh.de/admin-client:${newTag}" + sh 'docker login docker.ozg-sh.de -u ${USER} -p ${PASSWORD}' + sh "docker tag docker.ozg-sh.de/admin-client:build-latest docker.ozg-sh.de/admin-client:${newTag}" + sh "docker push docker.ozg-sh.de/admin-client:${newTag}" } -} -String getPackagejsonVersion() { + } + String getPackagejsonVersion() { def packageJSON = readJSON file: 'package.json' def packageJSONVersion = packageJSON.version echo packageJSONVersion return packageJSONVersion -} - -Void deployHelmChart(String helmChartVersion) { - withCredentials([usernamePassword(credentialsId: 'jenkins-nexus-login', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]){ - if (isReleaseBranch()) { - result = sh script: '''curl -u $USERNAME:$PASSWORD https://nexus.ozg-sh.de/service/rest/v1/components?repository=ozg-base-apps -F file=@admin-client-'''+helmChartVersion+'''.tgz''', returnStdout: true - } - else { - result = sh script: '''curl -u $USERNAME:$PASSWORD https://nexus.ozg-sh.de/service/rest/v1/components?repository=ozg-base-apps-snapshot -F file=@admin-client-'''+helmChartVersion+'''.tgz''', returnStdout: true - } - - if (result != '') { - error(result) - } + } + Void deployHelmChart(String helmChartVersion) { + withCredentials([usernamePassword(credentialsId: 'jenkins-nexus-login', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) { + if (isReleaseBranch()) { + result = sh script: '''curl -u $USERNAME:$PASSWORD https://nexus.ozg-sh.de/service/rest/v1/components?repository=ozg-base-apps -F file=@admin-client-''' + + helmChartVersion + '''.tgz''', returnStdout: true + } + else { + result = sh script: '''curl -u $USERNAME:$PASSWORD https://nexus.ozg-sh.de/service/rest/v1/components?repository=ozg-base-apps-snapshot -F file=@admin-client-''' + + helmChartVersion + '''.tgz''', returnStdout: true + } + if (result != '') { + error(result) + } } -} -String generateHelmChartVersion() { + } + String generateHelmChartVersion() { def chartVersion = "${VERSION}" - if (isMasterBranch()) { - chartVersion += "-${env.GIT_COMMIT.take(7)}" + chartVersion += "-${env.GIT_COMMIT.take(7)}" } else if (!isReleaseBranch()) { - chartVersion += "-${env.BRANCH_NAME}" + chartVersion += "-${env.BRANCH_NAME}" } - return chartVersion.replaceAll("_", "-") -} - -Boolean isMasterBranch() { + } + Boolean isMasterBranch() { return env.BRANCH_NAME == 'master' -} - -Void sendFailureMessage() { + } + Void sendFailureMessage() { def room = '' def data = """{"msgtype":"m.text", \ "body":"Admin-Client: Build Failed. Stage: ${FAILED_STAGE} Build-ID: ${env.BUILD_NUMBER} Link: ${BLUE_OCEAN_URL}", \ "format": "org.matrix.custom.html", \ "formatted_body":"Admin-Client: Build Failed. Stage: ${FAILED_STAGE} Build-ID: <a href='${BLUE_OCEAN_URL}'>${env.BUILD_NUMBER}</a>"}""" - if (isMasterBranch()) { - room = "!iQPAvQIiRwRpNOszjw:matrix.ozg-sh.de" + room = "!iQPAvQIiRwRpNOszjw:matrix.ozg-sh.de" } else if (isReleaseBranch()) { - room = "!oWZpUGTFsxkJIYNfYg:matrix.ozg-sh.de" + room = "!oWZpUGTFsxkJIYNfYg:matrix.ozg-sh.de" } - sh "curl -XPOST -H 'authorization: Bearer ${getElementAccessToken()}' -d '${data}' https://matrix.ozg-sh.de/_matrix/client/v3/rooms/$room/send/m.room.message" -} - -String getElementAccessToken() { + } + String getElementAccessToken() { withCredentials([string(credentialsId: 'element-login-json', variable: 'LOGIN_JSON')]) { - return readJSON ( text: sh (script: '''curl -XPOST -d \"$LOGIN_JSON\" https://matrix.ozg-sh.de/_matrix/client/v3/login''', returnStdout: true)).access_token + return readJSON (text: sh (script: '''curl -XPOST -d \"$LOGIN_JSON\" https://matrix.ozg-sh.de/_matrix/client/v3/login''', returnStdout: true)).access_token } -} \ No newline at end of file + } \ No newline at end of file diff --git a/alfa-client/package-lock.json b/alfa-client/package-lock.json index 4c36f9bdee0424b96750a36dcbe40181b55bb79a..28896c4b603b8c8d97258d2b69bd857733323bee 100644 --- a/alfa-client/package-lock.json +++ b/alfa-client/package-lock.json @@ -109,6 +109,7 @@ "ng-packagr": "18.2.1", "nx": "19.8.8", "prettier": "^3.2.5", + "prettier-plugin-groovy": "^0.2.1", "prettier-plugin-organize-imports": "^4.1.0", "prettier-plugin-tailwindcss": "^0.6.8", "sonarqube-scanner": "^4.2.5", @@ -28750,6 +28751,19 @@ "url": "https://github.com/prettier/prettier?sponsor=1" } }, + "node_modules/prettier-plugin-groovy": { + "version": "0.2.1", + "resolved": "http://nexus.ozg-sh.de/repository/npm-proxy/prettier-plugin-groovy/-/prettier-plugin-groovy-0.2.1.tgz", + "integrity": "sha512-89i4b9nxnQ+KKjl/rSktUA0u1HFCK3HeoqXAaHNpQC8wKjnL/FJ87pRQlDi0nrmGsWRcvGqbD1FaTgSS0EZ44Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=20.0.0 || ^18.12.0" + }, + "peerDependencies": { + "prettier": "^3.3.3" + } + }, "node_modules/prettier-plugin-organize-imports": { "version": "4.1.0", "resolved": "http://nexus.ozg-sh.de/repository/npm-proxy/prettier-plugin-organize-imports/-/prettier-plugin-organize-imports-4.1.0.tgz", diff --git a/alfa-client/package.json b/alfa-client/package.json index 8e5d6588c29c07e6e3cfc09edbf6207aa94b4ec7..0192bda7b4e6754c15dd445b9d42e398ec3feb4d 100644 --- a/alfa-client/package.json +++ b/alfa-client/package.json @@ -156,6 +156,7 @@ "ng-packagr": "18.2.1", "nx": "19.8.8", "prettier": "^3.2.5", + "prettier-plugin-groovy": "^0.2.1", "prettier-plugin-organize-imports": "^4.1.0", "prettier-plugin-tailwindcss": "^0.6.8", "sonarqube-scanner": "^4.2.5", @@ -166,4 +167,4 @@ "ts-node": "10.9.1", "typescript": "5.5.4" } -} \ No newline at end of file +}