-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path.gitlab-ci.yml
284 lines (270 loc) · 13.6 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
image: gitlab.inovexcorp.com:4567/matonto/mobi-ci-container:feature-java-17
stages:
- test
- build-distribution
- test-functional
- deploy
- post-deploy
variables:
GIT_DEPTH: 10 #Sets git depth to a lower number to optimize speed
NEXUS_URL: "https://nexus.inovexcorp.com/nexus"
# 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 -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true -XX:+TieredCompilation -XX:TieredStopAtLevel=1"
MAVEN_CLI_OPTS: "--batch-mode --errors --show-version -Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository -Dsurefire.rerunFailingTestsCount=2 -Dfailsafe.rerunFailingTestsCount=2"
MAVEN_THREADED: "-T 2C"
# Cache is currently only an explicit include. We need to exclude com/mobi/* so workaround is to have extra paths
cache:
key: maven-cache
paths:
- .m2/repository/[a-b]*
- .m2/repository/[d-z]*
- .m2/repository/com/[a-l]*
- .m2/repository/com/[n-z]*
before_script:
# Copy settings.xml from runner into current docker container (/m2 is a mounted directory)
- cp /m2/settings.xml ~/.m2/settings.xml
# Sets Version variables for use in job steps and updates pom to correct version for run
- REGEX="^v([0-9]+)\.([0-9]+)\.([0-9]+)" #Uses bash regex - matches pattern vX.X.X)
- DEPLOY_REPO=https://nexus.inovexcorp.com/nexus/content/repositories/foundry-maven-dev-hosted/ # Sets default repo to deploy to dev repo
- mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec #print version for a sanity check
# Following script parses version and determines whether to build a release, RC (release candidate), or snapshot. Also updates deploy repo accordingly.
- |-
if [[ $CI_COMMIT_TAG =~ $REGEX ]]; then
VERSION=`echo $CI_COMMIT_TAG | sed -e "s/^v//"`
MAJOR=`echo $VERSION | cut -d. -f1`
MINOR=`echo $VERSION | cut -d. -f2`
MICRO=`echo $VERSION | cut -d. -f3`
mvn $MAVEN_THREADED $MAVEN_CLI_OPTS versions:set -DnewVersion=$VERSION -DprocessAllModules -DgenerateBackupPoms=false
MESSAGE="Building release"
DEPLOY_REPO=https://nexus.inovexcorp.com/nexus/content/repositories/public-maven-prod-hosted/
elif [[ $CI_COMMIT_REF_NAME == "master" ]]
then
POM_VERSION=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec)
MAJOR=$(echo $POM_VERSION | cut -d- -f1 | cut -d. -f1)
MINOR=$(echo $POM_VERSION | cut -d- -f1 | cut -d. -f2)
MICRO=$(echo $POM_VERSION | cut -d- -f1 | cut -d. -f3)
VERSION=$MAJOR.$MINOR.$MICRO-rc-$CI_PIPELINE_IID
mvn $MAVEN_THREADED $MAVEN_CLI_OPTS versions:set -DnewVersion=$VERSION -DprocessAllModules -DgenerateBackupPoms=false
MESSAGE="Building release candidate"
else
VERSION=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec)
MESSAGE="Building snapshot"
fi
# Increase node max size to ensure we have enough space to run. This is a temporary fix until the node version is updated.
- export NODE_OPTIONS=--max_old_space_size=4096
# Print version to console for logging.
- echo "$MESSAGE - $VERSION"
# For merge requests, just do unit tests
unit_test_java:
stage: test
script:
# Build and runs tests, skipping sections that are integration/functional and web
- mvn $MAVEN_THREADED $MAVEN_CLI_OPTS -pl '!:web,!mobi-karaf-feature,!mobi-distribution,!mobi-itests,!:itests-orm,!:itests-web,!:itests-platform,!:itests-etl,!:itests-rest,!:itests-vfs' install
only:
- merge_requests
- master # Any commit to master triggers this job
- /v(\d+)\.(\d+)\.(\d+)/ #Release tags are in the form "vX.X.X"
artifacts:
expire_in: 4 hrs
paths:
- .m2/repository/com/mobi
retry: 1
# For merge requests, just do unit tests
unit_test_web:
stage: test
script:
# Build and run tests for dependencies for web bundle.
- mvn $MAVEN_THREADED $MAVEN_CLI_OPTS install -P release-build -pl ':api,:persistence.api,:persistence.utils,:rdf.orm,:rdf.orm.ontologies,:rdf.orm.generate,:rdf-orm-maven-plugin,:web.security,:jaas.api,:web,:owlapi.utils'
only:
- merge_requests
- master # Any commit to master triggers this job
- /v(\d+)\.(\d+)\.(\d+)/ #Release tags are in the form "vX.X.X"
artifacts:
expire_in: 4 hrs
paths:
- .m2/repository/com/mobi/web
retry: 1
# builds a distribution to be used by integration and functional tests
build_distribution:
stage: build-distribution
only:
- merge_requests
- master # Any commit to master triggers this job
- /v(\d+)\.(\d+)\.(\d+)/ #Release tags are in the form "vX.X.X"
except:
variables:
- $CI_COMMIT_TITLE =~ /^AUTOMATED COMMIT - Update version to \d+\.\d+\.\d+$/ #Should not run on automated commits
script:
# Build distribution
- mvn $MAVEN_CLI_OPTS clean install -pl ':mobi-karaf-feature,:mobi-distribution'
dependencies:
- unit_test_java
- unit_test_web
artifacts:
expire_in: 4 hrs
paths:
# Don't pull the zip of the distribution
- .m2/repository/com/mobi/[a-l]*
- .m2/repository/com/mobi/[n-z]*
- .m2/repository/com/mobi/mobi-parent
- .m2/repository/com/mobi/mobi-karaf-feature
- .m2/repository/com/mobi/mobi-distribution/*.xml
- .m2/repository/com/mobi/mobi-distribution/*/*.tar.gz
- .m2/repository/com/mobi/mobi-distribution/*/*.tar.gz
- .m2/repository/com/mobi/mobi-distribution/*/*.xml
- .m2/repository/com/mobi/mobi-distribution/*/*.properties
- .m2/repository/com/mobi/mobi-distribution/*/*.pom
- .m2/repository/com/mobi/mobi-distribution/*/*.repositories
retry: 1
# Following is an optional manual job to allow developers to run the integration and functional tests against a MR before merging.
.integration_tests:
stage: test-functional
only:
- merge_requests
- master # Any commit to master triggers this job
- /v(\d+)\.(\d+)\.(\d+)/ #Release tags are in the form "vX.X.X"
except:
variables:
- $CI_COMMIT_TITLE =~ /^AUTOMATED COMMIT - Update version to \d+\.\d+\.\d+$/ #Should not run on automated commits
script:
# Run integration tests (skips unit tests as they are included in the automated unit_test job)
- cd mobi-itests
- mvn $MAVEN_CLI_OPTS clean install -DskipITs=false
dependencies:
- build_distribution
retry: 1
# Following is an optional manual job to allow developers to run the integration and functional tests against a MR before merging.
.functional_tests:
stage: test-functional
only:
- merge_requests
- master # Any commit to master triggers this job
- /v(\d+)\.(\d+)\.(\d+)/ #Release tags are in the form "vX.X.X"
except:
variables:
- $CI_COMMIT_TITLE =~ /^AUTOMATED COMMIT - Update version to \d+\.\d+\.\d+$/ #Should not run on automated commits
script:
# Redirect calls to localhost:10000 to host machines (not this container), a 2nd container running mobi will be bound to the host at port 9080 (by functional tests).
- HOST_IP=$(ip route show | awk '/default/ {print $3}')
- redir :10000 $HOST_IP:10000
# Run integration tests (skips unit tests as they are included in the automated unit_test job)
- cd mobi-itests/itests-web
- mvn $MAVEN_CLI_OPTS clean install -DskipFunctional=false
dependencies:
- build_distribution
artifacts:
when: on_failure
paths:
- mobi-itests/itests-web/target/nightwatch-screenshots #in the event that the functional tests fail, screenshots of failures are stored in the directory
retry: 2
# Happens after commit to master
deploy_dev:
stage: deploy
only:
- master
except:
variables:
- $CI_COMMIT_TITLE =~ /^AUTOMATED COMMIT - Update version to \d+\.\d+\.\d+$/
script:
# Deploys RC candidate artifacts and distribution to Nexus
- mvn $MAVEN_THREADED $MAVEN_CLI_OPTS -DaltDeploymentRepository=central::default::$DEPLOY_REPO -Dmaven.test.skip=true -DskipTests -P release-build deploy
- curl -u $INOVEX_USERNAME:$INOVEX_PASSWORD --upload-file mobi-distribution/target/mobi-distribution-$VERSION.tar.gz $NEXUS_URL/repository/mobicommunity-raw-dev-hosted/nix/mobi-distribution-$VERSION.tar.gz
- curl -u $INOVEX_USERNAME:$INOVEX_PASSWORD --upload-file mobi-distribution/target/mobi-distribution-$VERSION.zip $NEXUS_URL/repository/mobicommunity-raw-dev-hosted/win/mobi-distribution-$VERSION.zip
- cd rdf-orm/rdf-orm-gradle-plugin
- ./gradlew publish -PlocalMavenRepo=$CI_PROJECT_DIR/.m2/repository -Pversion=$VERSION -PnexusUsername=$INOVEX_USERNAME -PnexusPassword=$INOVEX_PASSWORD
deploy_prod:
stage: deploy
only:
- /v(\d+)\.(\d+)\.(\d+)/ #Release tags are in the form "vX.X.X"
except:
- branches
script:
# Deploys release artifacts and distribution to Nexus, releases docker image and updates dockerhub repo.
- mvn $MAVEN_THREADED $MAVEN_CLI_OPTS -DaltDeploymentRepository=central::default::$DEPLOY_REPO -Dmaven.test.skip=true -DskipTests -P release-build -DproductId=$GA_KEY deploy
- curl -u $INOVEX_USERNAME:$INOVEX_PASSWORD --upload-file mobi-distribution/target/mobi-distribution-$VERSION.tar.gz $NEXUS_URL/repository/mobicommunity-raw-prod-hosted/nix/mobi-distribution-$VERSION.tar.gz
- curl -u $INOVEX_USERNAME:$INOVEX_PASSWORD --upload-file mobi-distribution/target/mobi-distribution-$VERSION.zip $NEXUS_URL/repository/mobicommunity-raw-prod-hosted/win/mobi-distribution-$VERSION.zip
- cd rdf-orm/rdf-orm-gradle-plugin
- ./gradlew publish -PlocalMavenRepo=$CI_PROJECT_DIR/.m2/repository -Pversion=$VERSION -PnexusUsername=$INOVEX_USERNAME -PnexusPassword=$INOVEX_PASSWORD
# build and push the docker image, per instructions in mobi-distribution README
- cd ../../mobi-distribution
- mvn $MAVEN_CLI_OPTS docker:build -DpushImageTag
increment_minor_version:
# Increments minor version after a release.
stage: deploy
only:
- /v(\d+)\.(\d+)\.([0]$)/ #Applies to release tags in the form "vX.X.0"
except:
- branches
before_script: [] #Skip before script so as not to set a version before git pull (would introduce conflicts)
script:
# Configure git
- PRIVATE_URL="$(echo $CI_PROJECT_URL | sed "s|https://|https://gitlab-ci-token:$ACCESS_TOKEN@|g").git"
- git remote set-url origin $PRIVATE_URL
- git config --global user.email 'gitlab.runner@inovexcorp.com'
- git config --global user.name 'Gitlab Runner'
# Ensure working on latest commit on master
- git fetch
- git pull origin master
# Get current version
- VERSION=`echo $CI_COMMIT_TAG | sed -e "s/^v//"`
- MAJOR=`echo $VERSION | cut -d. -f1`
- MINOR=`echo $VERSION | cut -d. -f2`
- MICRO=`echo $VERSION | cut -d. -f3`
# Update minor version
- NEW_MINOR=$((MINOR + 1))
- NEW_VERSION="$MAJOR.$NEW_MINOR.0-SNAPSHOT"
- mvn $MAVEN_THREADED $MAVEN_CLI_OPTS versions:set -DnewVersion=$NEW_VERSION -DprocessAllModules -DgenerateBackupPoms=false
# Commit change to git
- git commit -am "AUTOMATED COMMIT - Update version to $NEW_VERSION"
# Push change to master (gitlab)
- git push origin HEAD:master
# Push release to github
- git remote -v | grep -w github || git remote add github https://$GITHUB_NAME:$GITHUB_TOKEN@github.com/inovexcorp/mobi.git
- git push -f github HEAD:master
- git push -f github $CI_COMMIT_REF_NAME #pushing release tag
support_branch_increment_micro_version:
# increments micro version
stage: deploy
only:
- /v(\d+)\.(\d+)\.([1-9]\d*)/ #Applies to tags where the micro version is >= 1.
except:
- branches
before_script: [] #Skip before script so as not to set a version before git pull (would introduce conflicts)
script:
# Get current version
- VERSION=`echo $CI_COMMIT_TAG | sed -e "s/^v//"`
- MAJOR=`echo $VERSION | cut -d. -f1`
- MINOR=`echo $VERSION | cut -d. -f2`
- MICRO=`echo $VERSION | cut -d. -f3`
# Configure git
- PRIVATE_URL="$(echo $CI_PROJECT_URL | sed "s|https://|https://gitlab-ci-token:$ACCESS_TOKEN@|g").git"
- git remote set-url origin $PRIVATE_URL
- git config --global user.email 'gitlab.runner@inovexcorp.com'
- git config --global user.name 'Gitlab Runner'
# Set working branch
- BRANCH="support/$MAJOR.$MINOR"
# Ensure working on latest commit on branch
- git fetch
- git pull origin $BRANCH
# Update micro version
- NEW_MICRO=$((MICRO + 1))
- NEW_VERSION="$MAJOR.$MINOR.$NEW_MICRO-SNAPSHOT"
- mvn $MAVEN_THREADED $MAVEN_CLI_OPTS versions:set -DnewVersion=$NEW_VERSION -DprocessAllModules -DgenerateBackupPoms=false
# Commit change to git
- git commit -am "AUTOMATED COMMIT - Update support branch version to $NEW_VERSION"
# Push change to master (gitlab)
- git push origin HEAD:$BRANCH
# Push release to github
- git remote -v | grep -w github || git remote add github https://$GITHUB_NAME:$GITHUB_TOKEN@github.com/inovexcorp/mobi.git
- git push -f github
- git push -f github $CI_COMMIT_REF_NAME #pushing release tag
enterprise_tests:
# Runs enterprise tests against current version of mobi (master branch). This is to give us warning if any changes to mobi community may impact master
stage: post-deploy
only:
- master
script:
- git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.inovexcorp.com/matonto/mobi-enterprise.git
- cd mobi-enterprise
- mvn install -Dmobi.version=$VERSION
allow_failure: true #Allows for failure as this should not fail the release of mobi, but warn of needed changes to mobi-enterprise