Files
IT1901/.gitlab-ci.yml
T

132 lines
3.8 KiB
YAML

# Based on
# https://gitlab.stud.idi.ntnu.no/oysteikt/h20-tdt4100-project/-/blob/master/pom.xml
image: maven:3-openjdk-16-slim
include:
- template: Security/SAST.gitlab-ci.yml
variables:
SECURE_LOG_LEVEL: "debug"
SAST_JAVA_VERSION: 11
# This will suppress any download for dependencies and plugins or upload messages which would clutter the console log.
# `showDateTime` will show the passed time in milliseconds. You need to specify `--batch-mode` to make this work.
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"
# As of Maven 3.3.0 instead of this you may define these options in `.mvn/maven.config` so the same config is used
# when running from the command line.
MAVEN_CLI_OPTS: " \
--batch-mode \
--errors \
--fail-at-end \
--show-version \
-Dprism.verbose=true \
-Dtestfx.robot=glass \
-Dtestfx.headless=true \
-Dglass.platform=Monocle \
-Dprism.order=sw \
-Dprism.text=t2k \
-Dtestfx.setup.timeout=60000"
# Paths relative to flashy/
SUREFIRE_REPORTS_PATH: "target/surefire-reports"
WEBSITE_PATH: "target/staging"
COBERTURA_PATH: "$WEBSITE_PATH/cobertura.xml"
RAW_JACOCO_AGGREGATE_PATH: "report/target/site/jacoco-aggregate"
JACOCO_AGGREGATE_PATH: "$WEBSITE_PATH/jacoco-aggregate"
# Cache downloaded dependencies and plugins between builds.
# To keep cache across branches add 'key: "$CI_JOB_NAME"'
cache:
paths:
- .m2/repository
stages:
- build
- test
- report
- report-data-extraction
- deploy
build:
stage: build
script:
- "cd flashy"
- "mvn clean package -Dmaven.test.skip=true $MAVEN_CLI_OPTS"
artifacts:
paths:
- flashy/target/
unittest:
stage: test
needs: [build]
script:
- "apt update"
- "apt install -y openjfx xmlstarlet"
- "cd flashy"
- "mvn test $MAVEN_CLI_OPTS"
- "modules=($(xmlstarlet sel -N my=http://maven.apache.org/POM/4.0.0 -t -m '//my:module' -v . -o ' ' pom.xml))"
- "mkdir -p $SUREFIRE_REPORTS_PATH"
- "for module in $modules; do"
- " cp $module/target/surefire-reports/TEST-*.xml $SUREFIRE_REPORTS_PATH || :"
- "done"
artifacts:
paths:
- flashy/$SUREFIRE_REPORTS_PATH
when: always
reports:
junit:
- flashy/$SUREFIRE_REPORTS_PATH/TEST-*.xml
report:
stage: report
script:
- "apt update"
- "apt install -y openjfx"
- "cd flashy"
# Replace link for jacoco to point within the staging folder
- "sed -i 's/\\.\\.\\/\\.\\.\\/report\\/target\\/site\\/jacoco-aggregate\\/index.html/jacoco-aggregate\\/index.html/' src/site/site.xml"
- 'mvn clean test $MAVEN_CLI_OPTS site site:stage'
# Move real jacoco-aggregate to site
- 'rm -r $JACOCO_AGGREGATE_PATH'
- 'mv $RAW_JACOCO_AGGREGATE_PATH $WEBSITE_PATH'
artifacts:
paths:
- "flashy/$WEBSITE_PATH"
process-coverage:
stage: report-data-extraction
image: haynes/jacoco2cobertura:1.0.7
needs: [report]
variables:
script:
- 'cd flashy'
# convert report from jacoco to cobertura
- 'python /opt/cover2cover.py $JACOCO_AGGREGATE_PATH/jacoco.xml src/main/java > $COBERTURA_PATH'
# read the <source></source> tag and prepend the path to every filename attribute
- 'python /opt/source2filename.py $COBERTURA_PATH'
- 'cat $JACOCO_AGGREGATE_PATH/index.html'
coverage: '/Total.*?([0-9]{1,3})%/'
artifacts:
reports:
cobertura: flashy/$COBERTURA_PATH
pages:
stage: deploy
needs: [build, report]
script:
- 'mkdir public'
- 'mv flashy/target/flashy.jar public/'
- 'mv flashy/$WEBSITE_PATH/* public/'
artifacts:
paths:
- public
expire_in: 6 mos
only:
- master