include:
  - project: 'fit-connect/pipeline'
    ref: main
    file: 'reuse.gitlab-ci.yml'
  - project: 'fit-connect/pipeline'
    ref: main
    file: 'trivy.gitlab-ci.yml'

variables:
  MAVEN_CLI_OPTS: "-s .m2/release.xml --batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true -Dlocal-version-suffix="
  MAVEN_OPTS: "-Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true"
  ENCRYPTED_GPG_SECRET_KEY: "U2FsdGVkX19sgs5SAergNISd1D5CfXljYKPtPM7kAaAOXyC3oXjZy2igEGavVGW0fCi9IG+g8bvejWWkM7YIm+d6n+yS8TGhBuYnMforExJ56h3zODligGSHa4k85BwHwliT+j2pSKnWZ7M1tAKRmF6foftAZMHOCtfRUxc7n4EJEaZtq3pnPnthe9NxvaEqjd72iEXbdwFjhI1NnjvRlbBF+luUbHGfjHfwyyMTtNNN79wcmDSU7pIbEnvmikuETdYKDi9pT2137s3f58UcdTnD8zjmT5F0UkLXXTvtrroDGVB/xHKG7ttsj4/uvhCOTxkA5vKUDz6QgaGXjmIEwhlu68reodliDWlz7L4nlAS2dIDevFNbzgFG2m5ebYCd2TpjvXF0irgS1ENpCScAFX63SlFPl6/KKyp/sCVi34xDunSClzEBX9Hebv/ACyuKjz4owZKr8YhzDOzJTSphoj+1Xb678GFnfY6T5amaBTrGSR6U2YbOKWp5/fO/GIoercRxywF17DoGF+AZs1bmptVpltcr/4XWQDTW+c9Nmg+6h/2WJ396Hbj+DmpekYuDNCE6sDosANwTyXWSVM/N96MG+WlomRpvDd+A7KuRZ0INGnctx4r2isn0mr9dH7VVAQ9PIafKLiXH4Ynzjn7iBQtapIA0da13qy31vOWqG1wb41v97So+zi7/xEa3W9tHzOGjRjdoMNWej2tC0Qq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DxWdzlfM+Q6FVCOdbv+PjpPralmKv2e+z76H9GFXQ6NqyL6cLHNoGLO/YQ4nvbZfrkjuH24pTafND4QREqWaagdAje7oPjfrYeWzbUEh7gfqVo//BvCNXzaj24MpaWZH6opm66WhikXfPTqI4j4x03GO4b6WqG2LFuwg8tf9ABZLJAYq8qFbDMm1wxMrA/sYpmfYGul3pSQ+tlUzVfHB/ubCbGeFTeRarmqWtbqIInGMOpGxUyBeuEu8k1Ehu4v869NdPYcgL0LrliW1y9Dav/asqegKLiA2Vuw4qlyfSBFG6nqDShfjeSKm9trFXf/EzkpL/OQyiwbJooKYrJnFPvFFq5/o/uvvMHj/Kbvjuq9i7tfyGixQDiDbb0is8bSgD4+rok5pxuGESE+kMMep5lUzypDWTDvZWlbi1bj9CaGC2z8uY2eC5RTEGth9L7wyfLMls/hNZZ/qCQUpD8+fCQ88jd+ZWq/Au528+Wpje9AcgieNE0cYFSXtK7r1VIW6nt50EaHHpafJTJut8tGTepVaERPg9Kt625J0cZjo3BgEaPdcTh5gPGW+0RzfZa4+x3N+78R8qKpKCSMyk45FJbeiu+R0TujpdCUqmQVTIWhj2XeV0s2nu8uS8k7/fzDV+k12o4La0A2xxx+GQR8TnCznoQadZ6IX/IZGvnsdUfsIgEwLxB/TtFcR8mL1IdYk="

stages:
  - lint
  - build
  - test
  - coverage
  - upload
  - package
  - deploy

cache:
  paths:
    - .m2/repository/

reuse:
  extends: .reuse
  stage: lint

trivy-filesystem:
  extends: .trivy-filesystem

build:
  image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/eclipse-temurin:11.0.23_9-jdk
  stage: build
  script:
    - ./mvnw $MAVEN_CLI_OPTS clean install -DskipTests --no-transfer-progress -T2

test:
  image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/eclipse-temurin:11.0.23_9-jdk
  stage: test
  script:
    - ./mvnw $MAVEN_CLI_OPTS verify org.jacoco:jacoco-maven-plugin:prepare-agent test jacoco:report --no-transfer-progress -T2
  artifacts:
    paths:
      - client/target/site/jacoco/jacoco.xml
      - core/target/site/jacoco/jacoco.xml
      - integration-tests/target/site/jacoco/jacoco.xml
    reports:
      junit:
        - client/target/surefire-reports/TEST-*.xml
        - core/target/surefire-reports/TEST-*.xml
        - integration-tests/target/surefire-reports/TEST-*.xml
    expire_in: 7 days

coverage:
  stage: coverage
  image: registry.gitlab.com/haynes/jacoco2cobertura:1.0.10
  script:
    - python /opt/cover2cover.py core/target/site/jacoco/jacoco.xml $CI_PROJECT_DIR/src/main/java/ > core/target/cobertura.xml
    - python /opt/cover2cover.py client/target/site/jacoco/jacoco.xml $CI_PROJECT_DIR/src/main/java/ > client/target/cobertura.xml
    - python /opt/cover2cover.py integration-tests/target/site/jacoco/jacoco.xml $CI_PROJECT_DIR/src/main/java/ > integration-tests/target/cobertura.xml
  needs: ["test"]
  artifacts:
    reports:
      coverage_report:
        coverage_format: cobertura
        path: core/target/cobertura.xml
  coverage: '/All files[^|]*\|[^|]*\s+([\d\.]+)/'

package:
  image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/eclipse-temurin:11.0.23_9-jdk
  stage: package
  before_script: &gpg-setup
    - apt-get update
    - apt-get -y install gpg
    - gpg --version
    - echo -n $ENCRYPTED_GPG_SECRET_KEY | base64 --decode | openssl aes-256-cbc -pbkdf2 -d -pass pass:$GPG_ENCRYPTION_KEY | gpg --import --batch --yes
    - gpg --list-secret-keys
  script:
    - ./mvnw $MAVEN_CLI_OPTS package -DskipTests
  artifacts:
    paths:
      - api/target/*.jar
      - core/target/*.jar
      - examples/target/*.jar
      - client/target/*.jar
      - integration-tests/target/*.jar
    expire_in: 1 day
  when: manual

deploy:
  image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/eclipse-temurin:11.0.23_9-jdk
  stage: deploy
  before_script: *gpg-setup
  script:
    - ./mvnw $MAVEN_CLI_OPTS deploy -DskipTests -P '!integration-tests' -P '!examples' -Pgpg-sign
  needs:
    - package

dtrack-sbom-fs-main:
  extends: .dtrack-sbom-fs-main

dtrack-sbom-fs-tag:
  extends: .dtrack-sbom-fs-tag
