From 3f99f8305b3e681e6e855fb67195e5b46cf9618c Mon Sep 17 00:00:00 2001
From: Olivier Maury <Olivier.Maury@inrae.fr>
Date: Tue, 25 Feb 2025 14:02:06 +0100
Subject: [PATCH] build(ci): .gitlab-ci.yml pour Java

---
 .gitlab-ci.yml | 134 ++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 122 insertions(+), 12 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 591e188..9c4216f 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,14 +1,124 @@
-# You can override the included template(s) by including variable overrides
-# SAST customization: https://docs.gitlab.com/ee/user/application_security/sast/#customizing-the-sast-settings
-# Secret Detection customization: https://docs.gitlab.com/ee/user/application_security/secret_detection/#customizing-settings
-# Dependency Scanning customization: https://docs.gitlab.com/ee/user/application_security/dependency_scanning/#customizing-the-dependency-scanning-settings
-# Container Scanning customization: https://docs.gitlab.com/ee/user/application_security/container_scanning/#customizing-the-container-scanning-settings
-# Note that environment variables can be set in several places
-# See https://docs.gitlab.com/ee/ci/variables/#cicd-variable-precedence
-include:
-- template: Security/Secret-Detection.gitlab-ci.yml
-- template: Security/SAST.gitlab-ci.yml
+# To use the registry, DOCKER_AUTH_CONFIG must be set
+image: $CI_REGISTRY/agroclim/common/docker-projets-java:latest
+
+variables:
+  MAVEN_OPTS: "-Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository"
+  MAVEN_CLI_OPTS: "-s $CI_PROJECT_DIR/ci_settings.xml"
+
+default:
+  # Cache downloaded dependencies and plugins between builds.
+  cache:
+    key: maven-repository
+    paths:
+      - $CI_PROJECT_DIR/.m2/repository
+  tags:
+    - agroclim
+
 stages:
-- test
-sast:
+    - build
+    - test
+    - install
+    - code-check
+    - deploy
+
+.settingsxml:
+  before_script:
+    - echo "Maven settings.xml"
+    - echo "$M2_SETTINGS_XML" > $CI_PROJECT_DIR/ci_settings.xml
+
+dependencies_job:
+  stage: build
+  extends: .settingsxml
+  script:
+    - echo "Download all dependencies (dependencies, plugins, reports)"
+    - mvn -s $CI_PROJECT_DIR/ci_settings.xml dependency:go-offline
+
+build_job:
+  stage: build
+  extends: .settingsxml
+  needs: ["dependencies_job"]
+  script:
+    - echo "Maven compile started"
+    - mvn $MAVEN_CLI_OPTS clean compile test-compile
+    - /usr/bin/tokei --version
+  artifacts:
+    expire_in: 1 week
+    when: always
+    paths:
+      - target
+
+test_job:
   stage: test
+  extends: .settingsxml
+  needs: ["build_job"]
+  script:
+    - echo "Maven test started"
+    - mvn $MAVEN_CLI_OPTS test org.jacoco:jacoco-maven-plugin:report-aggregate
+  artifacts:
+    expire_in: 1 week
+    when: always
+    paths:
+      - target
+    reports:
+      junit:
+        - target/surefire-reports/TEST-*.xml
+        - target/failsafe-reports/TEST-*.xml
+
+install_job:
+  stage: install
+  extends: .settingsxml
+  needs: ["test_job"]
+  script:
+    - echo "Maven packaging started"
+    - mvn $MAVEN_CLI_OPTS install -Dcheckstyle.skip=true -Dcpd.skip=true -Dpmd.skip=true -DskipTests
+  artifacts:
+    expire_in: 1 week
+    when: always
+    paths:
+      - .m2/repository
+      - target
+
+checkstyle_job:
+  stage: code-check
+  extends: .settingsxml
+  needs: ["install_job"]
+  script:
+    - mvn $MAVEN_CLI_OPTS checkstyle:checkstyle
+
+pmd_job:
+  stage: code-check
+  extends: .settingsxml
+  needs: ["install_job"]
+  script:
+    - mvn $MAVEN_CLI_OPTS pmd:pmd
+
+cpd_job:
+  stage: code-check
+  extends: .settingsxml
+  needs: ["install_job"]
+  script:
+    - mvn $MAVEN_CLI_OPTS pmd:cpd
+
+cobertura_job:
+  stage: deploy
+  needs: ["test_job"]
+  script:
+    # convert report from jacoco to cobertura, using relative project path
+    - python /opt/cover2cover.py
+      target/site/jacoco-aggregate/jacoco.xml
+      $CI_PROJECT_DIR/src/main/java/
+      > target/cobertura.xml
+
+# https://tempo.pages.mia.inra.fr/visualisation/
+pages:
+  stage: deploy
+  extends: .settingsxml
+  needs: ["checkstyle_job", "pmd_job", "cpd_job"]
+  script:
+    - mvn $MAVEN_CLI_OPTS site -DskipTests
+  artifacts:
+    expire_in: 1 week
+    when: always
+    paths:
+      - target
+  publish: target/site
-- 
GitLab