-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
194 lines (174 loc) · 5.91 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# common vars for multiple stages/jobs
variables:
MAVEN_IMAGE: maven:3.6-adoptopenjdk-11
MAVEN_OPTS: "-Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository/"
MAVEN_CLI_OPTS: "-s .m2/settings.xml --batch-mode"
PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/releases/${CI_COMMIT_TAG}"
cache:
paths:
- .m2/repository/
stages:
- setup
- build
- quality
- distribution
- upload
- release
###################### Setup ######################
setup:jdk-11:
stage: setup
image: $MAVEN_IMAGE
script:
- export ARTIFACT_ID=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.artifactId}' --non-recursive exec:exec)
- echo "ARTIFACT_ID=$ARTIFACT_ID" >> build.env
- export RD_PROJECT_LATEST_TAG=$(git describe --abbrev=0 --tags)
- echo "RD_PROJECT_LATEST_TAG=$RD_PROJECT_LATEST_TAG" >> build.env
- export JAVA_JDKVERSION_TAG="jdk-11"
- echo "JAVA_JDKVERSION_TAG=$JAVA_JDKVERSION_TAG" >> build.env
- |
if [ -z "$CI_COMMIT_TAG" ];
then
export ARTIFACT_VERSION=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec)
echo "ARTIFACT_VERSION=$ARTIFACT_VERSION" >> build.env
else
export ARTIFACT_VERSION=$CI_COMMIT_TAG+$JAVA_JDKVERSION_TAG
echo "ARTIFACT_VERSION=$ARTIFACT_VERSION" >> build.env
fi
- export ARTIFACT_FULLNAME=$ARTIFACT_ID-$ARTIFACT_VERSION+$JAVA_JDKVERSION_TAG
- echo "ARTIFACT_FULLNAME=$ARTIFACT_FULLNAME" >> build.env
- export
artifacts:
reports:
dotenv: build.env
###################### Test / Build ######################
.prepare-mvn-project: &prepare-mvn-project
image: $MAVEN_IMAGE
before_script:
- export
- mvn versions:set -DnewVersion=$ARTIFACT_VERSION
build:jdk-11:
<<: *prepare-mvn-project
needs:
- job: setup:jdk-11
artifacts: true
stage: build
artifacts:
paths:
- target/*.jar
script:
- mvn -v
- mvn $MAVEN_CLI_OPTS clean package
test:jdk-11:
stage: build
<<: *prepare-mvn-project
needs:
- job: setup:jdk-11
artifacts: true
script:
- mvn $MAVEN_CLI_OPTS clean org.jacoco:jacoco-maven-plugin:prepare-agent test jacoco:report
- awk -F"," '{ instructions += $4 + $5; covered += $5 } END { print covered, "/", instructions, " instructions covered"; print 100*covered/instructions, "% covered" }' target/site/jacoco/jacoco.csv
artifacts:
paths:
- target/site/jacoco/jacoco.xml
###################### Quality ######################
coverage:jdk-11:
# Must be in a stage later than test:jdk11:'s stage.
# The `visualize` stage does not exist by default.
# Please define it first, or chose an existing stage like `deploy`.
stage: quality
image: haynes/jacoco2cobertura:1.0.4
script:
# convert report from jacoco to cobertura
- 'python /opt/cover2cover.py target/site/jacoco/jacoco.xml src/main/java > target/site/cobertura.xml'
# read the <source></source> tag and prepend the path to every filename attribute
- 'python /opt/source2filename.py target/site/cobertura.xml'
needs:
- job: test:jdk-11
artifacts: true
artifacts:
reports:
cobertura: target/site/cobertura.xml
###################### Assembly and Deploy ######################
assembly:jdk-11:
<<: *prepare-mvn-project
needs:
- job: setup:jdk-11
artifacts: true
- job: build:jdk-11
artifacts: true
stage: distribution
artifacts:
paths:
- target/*.tar.gz
- target/*.zip
- target/site/
reports:
dotenv: build.env
script:
- mvn $MAVEN_CLI_OPTS -Dmaven.test.skip=true clean install site:site assembly:single
deploy:jdk-11:
<<: *prepare-mvn-project
needs:
- job: setup:jdk-11
artifacts: true
- job: build:jdk-11
artifacts: true
stage: distribution
script:
- mvn $MAVEN_CLI_OPTS -Dmaven.test.skip=true clean install deploy
###################### Upload Binaries ######################
upload:jdk-11:
stage: upload
image: curlimages/curl:latest
needs:
- job: setup:jdk-11
artifacts: true
- job: assembly:jdk-11
artifacts: true
artifacts:
reports:
dotenv: build.env
rules:
- if: $CI_COMMIT_TAG
when: manual
script:
- export UPLOAD_DIST_ZIP_JDK11_NAME=$ARTIFACT_FULLNAME-dist.zip
- echo "UPLOAD_DIST_ZIP_JDK11_NAME=$UPLOAD_DIST_ZIP_JDK11_NAME" >> build.env
- |
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file target/$UPLOAD_DIST_ZIP_JDK11_NAME ${PACKAGE_REGISTRY_URL}/$UPLOAD_DIST_ZIP_JDK11_NAME
- export UPLOAD_DIST_TARGZ_JDK11_NAME=$ARTIFACT_FULLNAME-dist.tar.gz
- echo "UPLOAD_DIST_TARGZ_JDK11_NAME=$UPLOAD_DIST_TARGZ_JDK11_NAME" >> build.env
- |
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file target/$UPLOAD_DIST_TARGZ_JDK11_NAME ${PACKAGE_REGISTRY_URL}/$UPLOAD_DIST_TARGZ_JDK11_NAME
###################### Release ######################
release:dist-jdk-11:
stage: release
image: registry.gitlab.com/gitlab-org/release-cli:latest
needs:
- job: setup:jdk-11
artifacts: true
- job: upload:jdk-11
artifacts: true
rules:
- if: $CI_COMMIT_TAG
when: manual
script:
- |
release-cli create --name "Release ${ARTIFACT_VERSION}" --tag-name $CI_COMMIT_TAG \
--assets-link "{\"name\":\"${UPLOAD_DIST_ZIP_JDK11_NAME}\",\"url\":\"${PACKAGE_REGISTRY_URL}/${UPLOAD_DIST_ZIP_JDK11_NAME}\"}" \
--assets-link "{\"name\":\"${UPLOAD_DIST_TARGZ_JDK11_NAME}\",\"url\":\"${PACKAGE_REGISTRY_URL}/${UPLOAD_DIST_TARGZ_JDK11_NAME}\"}"
release:mvncentral-jdk-11:
<<: *prepare-mvn-project
stage: release
needs:
- job: setup:jdk-11
artifacts: true
rules:
- if: '$CI_COMMIT_TAG && $CI_SERVER_HOST == "gitlab.com"'
when: manual
script:
- apt update && apt-get -y install gnupg
## Add gpg key to sign
- export GPG_TTY=$(tty)
- gpg --batch --import <(echo "$GPG_PRIVATE_KEY_ENCODED" | base64 -d)
- mvn $MAVEN_CLI_OPTS clean deploy -P release