forked from inovexcorp/mobi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
176 lines (167 loc) · 8.59 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
image: gitlab.inovexcorp.com:4567/ilab/docker-images/maven-node-jdk8
stages:
- test
- deploy
- deploy-docker
variables:
GIT_DEPTH: 10 #Sets git depth to a lower number to optimize speed
NEXUS_URL: "http://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"
before_script:
- 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
- DEPLOY_REPO=http://nexus.inovexcorp.com/nexus/content/repositories/foundry-maven-dev-hosted/
- mvn org.apache.maven.plugins:maven-help-plugin:evaluate -Dexpression=project.version -q -DforceStdout #print version
- |-
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_CLI_OPTS versions:set -DnewVersion=$VERSION -DprocessAllModules -DgenerateBackupPoms=false
MESSAGE="Building release"
DEPLOY_REPO=http://nexus.inovexcorp.com/nexus/content/repositories/public-maven-prod-hosted/
elif [[ $CI_COMMIT_REF_NAME == "master" ]]
then
POM_VERSION=$(mvn org.apache.maven.plugins:maven-help-plugin:evaluate -Dexpression=project.version -q -DforceStdout)
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_CLI_OPTS versions:set -DnewVersion=$VERSION -DprocessAllModules -DgenerateBackupPoms=false
MESSAGE="Building release candidate"
else
VERSION=$(mvn org.apache.maven.plugins:maven-help-plugin:evaluate -Dexpression=project.version -q -DforceStdout)
MESSAGE="Building snapshot"
fi
- echo "$MESSAGE - $VERSION"
# For merge requests, just do an unit tests
unit_test:
stage: test
script:
- mvn $MAVEN_CLI_OPTS -pl '!mobi-distribution,!mobi-itests,!:itests-support,!:itests-orm,!:itests-web,!:itests-platform,!:itests-etl,!:itests-rest,!:itests-vfs' test
only:
- merge_requests
# For commits to master and releases do a full test
full_test:
stage: test
only:
- master
- /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:
- apt-get update
# Redirect calls to localhost:9080 to host machines (not this container), a 2nd container running mobi will be bound to the host at port 9080 (by functional tests).
- apt-get install -y redir
- HOST_IP=$(ip route show | awk '/default/ {print $3}')
- redir :9080 $HOST_IP:9080
# Update Chrome Version
- apt-get -y install google-chrome-stable
# Run unit, integration, and functional tests
- mvn $MAVEN_CLI_OPTS clean install -DskipFunctional=false -DskipITs=false
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
# 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:
- mvn $MAVEN_CLI_OPTS deploy -DaltDeploymentRepository=central::default::$DEPLOY_REPO #TODO Skip unit tests and build - Future work to decrease duplication and increase the speed of execution
- 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 -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:
- mvn $MAVEN_CLI_OPTS deploy -DaltDeploymentRepository=central::default::$DEPLOY_REPO -P release-build -DproductId=$GA_KEY
- 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 -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:
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_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 add github https://$GITHUB_NAME:$GITHUB_TOKEN@github.com:inovexcorp/mobi.git
- git push github HEAD:master
- git push github $CI_COMMIT_REF_NAME #pushing release tag
support_branch_increment_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_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 add github https://$GITHUB_NAME:$GITHUB_TOKEN@github.com:inovexcorp/mobi.git
- git push github HEAD:$BRANCH
- git push github $CI_COMMIT_REF_NAME #pushing release tag