Commit be5a5a2a authored by femiadeyemi's avatar femiadeyemi Committed by femiadeyemi
Browse files

move sonar config into maven and restructure the CI/CD

Motivation:

Since maven is use by the project for the project management and
npm is used to manage javascripts related depedency, hence it is
neccessary to seperate the two workflow. So, sonar is fully
integrated inside maven and can be easily managed within maven tool.

Modification:

- create a profile inside the pom file for sonar-que and delete the
    ci-analysis.js
- changes some stages names
- use the atlassianlabs/docker-node-jdk-chrome-firefox for the whole
    ci since it comprises the needed basis infastructure. Hence, the
    ci config is streamlined.
- add a variable to that will be passed to the downstream repository.
    This variable is for setting the project version number
- remove the sonar from the package.json
- add the repository information inside the package.json
- specficy the maven build-cycle phases for npm, node and karma

Result:

Remove reductancy tests and streamline the ci/cd and able to pass the
neccessary variable downstream.

Target: master
parent d79a7996
Pipeline #42889 passed with stages
in 5 minutes and 53 seconds
stages:
- build
- test
- test_sonar
- code_quality_analysis
- deploy
- trigger
- trigger_marketplace_server
variables:
MAVEN_CLI_OPTS: "-s .m2/settings.xml --batch-mode"
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"
WEBAPP_PROJECT_VERSION: "0.0.2-SNAPSHOT"
cache:
key: "$CI_COMMIT_REF_NAME"
......@@ -16,4 +17,3 @@ cache:
include:
- local: .gitlab/ci/ci.yml
- local: .gitlab/ci/static-code-analysis.yml
ci_build_node12:
only:
- master
- merge_requests
stage: build
image: node:12-buster-slim
before_script:
- apt-get update -yqq
- apt-get install -y gnupg2 wget apt-transport-https
- wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add
- echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list
- apt-get update -yqq
- apt-get install -y google-chrome-stable
script: npm install
image: atlassianlabs/docker-node-jdk-chrome-firefox
ci_build_node14:
build:
only:
- master
- merge_requests
stage: build
image: node:14-buster-slim
before_script:
- apt-get update -yqq
- apt-get install -y gnupg2 wget apt-transport-https
- wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add
- echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list
- apt-get update -yqq
- apt-get install -y google-chrome-stable
script: npm install
script: mvn compile
test_node12:
test:
only:
- master
- merge_requests
stage: test
image: node:12-buster-slim
before_script:
- apt-get update -yqq
- apt-get install -y gnupg2 wget apt-transport-https
- wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add
- echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list
- apt-get update -yqq
- apt-get install -y google-chrome-stable
script: npm install-test
script: mvn test
test_node14:
code_anaylsis:
only:
- master
- merge_requests
stage: test
image: node:14-buster-slim
before_script:
- apt-get update -yqq
- apt-get install -y gnupg2 wget apt-transport-https
- wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add
- echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list
- apt-get update -yqq
- apt-get install -y google-chrome-stable
script: npm install-test
stage: code_quality_analysis
script: "mvn -P sonar clean verify sonar:sonar"
deploy:
only:
- master
- merge_requests
stage: deploy
image: atlassianlabs/docker-node-jdk-chrome-firefox
script: mvn $MAVEN_CLI_OPTS deploy
trigger:
only:
- master
- merge_requests
stage: trigger
trigger:
project: hifis-technical-platform/helmholtz-marketplace-server
variables:
WEBAPP_VERSION: $WEBAPP_PROJECT_VERSION
stage: trigger_marketplace_server
trigger: hifis-technical-platform/helmholtz-marketplace-server
sonarqube_node12:
stage: test_sonar
image: node:12-buster-slim
before_script:
- apt-get update -yqq
- apt-get install -y gnupg2 wget apt-transport-https
- wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add
- echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list
- apt-get update -yqq
- apt-get install -y google-chrome-stable
script:
- npm ci
- npm run build --if-present
- npm test
- npm run test:sonarqube
sonarqube_node14:
stage: test_sonar
image: node:14-buster-slim
before_script:
- apt-get update -yqq
- apt-get install -y gnupg2 wget apt-transport-https
- wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add
- echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list
- apt-get update -yqq
- apt-get install -y google-chrome-stable
script:
- npm ci
- npm run build --if-present
- npm test
- npm run test:sonarqube
const sonarqubeScanner = require('sonarqube-scanner'); // eslint-disable-line import/no-extraneous-dependencies
sonarqubeScanner(
{
serverUrl: 'https://sonar.desy.de',
token: process.env.SONAR_AUTH_TOKEN,
options: {
'sonar.projectKey':
'de.helmholtz.marketplace:helmholtz-marketplace-webapp',
'sonar.projectName': 'Helmholtz Marketplace WebApp',
'sonar.sources': 'src',
'sonar.projectVersion': '0.0.1',
'sonar.language': 'js',
'sonar.sourceEncoding': 'UTF-8',
'sonar.exclusions': 'src/**/*.spec.js',
'sonar.test.inclusions': 'src/**/*.spec.js',
'sonar.coverage.exclusions':
'src/**/*.spec.js,src/**/*.mock.js,node_modules/*,coverage/lcov-report/*',
'sonar.qualitygate.wait': 'true',
'sonar.qualitygate.timeout': '30',
'sonar.working.directory': 'target/.scannerwork',
},
},
() => process.exit()
);
This diff is collapsed.
......@@ -9,7 +9,6 @@
"test": "karma start",
"test:coverage": "karma start --coverage",
"test:watch": "karma start --auto-watch=true --single-run=false",
"test:sonarqube": "node ci-analysis.js",
"build": "rimraf target && rollup -c rollup.config.js",
"start": "es-dev-server --app-index index.html --node-resolve --open --watch",
"start:build": "npm run build && es-dev-server --root-dir target --app-index index.html --open --compatibility none"
......@@ -29,7 +28,7 @@
"rimraf": "^2.6.3",
"rollup": "^2.3.4",
"rollup-plugin-copy": "^3.3.0",
"sonarqube-scanner": "^2.6.0"
"sinon": "^9.0.3"
},
"eslintConfig": {
"extends": [
......@@ -63,5 +62,9 @@
"@material/mwc-top-app-bar-fixed": "0.14.1",
"lit-element": "2.3.1",
"lit-html": "1.2.1"
},
"repository": {
"type": "git",
"url": "git@gitlab.hzdr.de:hifis-technical-platform/helmholtz-marketplace-webapp.git"
}
}
......@@ -69,6 +69,10 @@
<version.npm>6.14.2</version.npm>
<version.maven-install-plugin>2.5.2</version.maven-install-plugin>
<version.maven-release-plugin>2.5.3</version.maven-release-plugin>
<version.jacoco-maven-plugin>0.8.5</version.jacoco-maven-plugin>
<version.sonar-maven-plugin>3.7.0.1746</version.sonar-maven-plugin>
<!--suppress UnresolvedMavenProperty -->
<sonar.token>${env.SONAR_AUTH_TOKEN}</sonar.token>
</properties>
<build>
......@@ -88,6 +92,7 @@
<nodeVersion>${version.node}</nodeVersion>
<npmVersion>${version.npm}</npmVersion>
</configuration>
<phase>generate-resources</phase>
</execution>
<execution>
......@@ -109,6 +114,7 @@
<configuration>
<arguments>run build</arguments>
</configuration>
<phase>process-resources</phase>
</execution>
<execution>
......@@ -173,5 +179,64 @@
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>${version.sonar-maven-plugin}</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${version.jacoco-maven-plugin}</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<profiles>
<profile>
<id>sonar</id>
<properties>
<sonar.login>${sonar.token}</sonar.login>
<sonar.host.url>https://sonar.desy.de</sonar.host.url>
<sonar.projectKey>${project.groupId}:${project.artifactId}</sonar.projectKey>
<sonar.projectName>${project.name}</sonar.projectName>
<sonar.sources>src</sonar.sources>
<sonar.exclusions>src/**/*.spec.js</sonar.exclusions>
<sonar.test.inclusions>src/**/*.spec.js</sonar.test.inclusions>
<sonar.coverage.exclusions>src/**/*.spec.js,src/**/*.mock.js,node_modules/*,coverage/lcov-report/*</sonar.coverage.exclusions>
<sonar.working.directory>${project.build.directory}/.scannerwork</sonar.working.directory>
<sonar.projectVersion>${project.version}</sonar.projectVersion>
<sonar.language>js</sonar.language>
<sonar.sourceEncoding>UTF-8</sonar.sourceEncoding>
<sonar.qualitygate.wait>true</sonar.qualitygate.wait>
<sonar.qualitygate.timeout>30</sonar.qualitygate.timeout>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment