-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
213 lines (194 loc) · 7.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
stages:
- build
- test
- package
- deploy
- build-containers
.template_docker:
stage: build-containers
image: docker:latest
services:
- docker:dind
script:
- if [ "$CI_COMMIT_BRANCH" = "master" ]; then docker build -t "$DOCKER_IMAGE:latest" .; fi
- if [ "$CI_COMMIT_BRANCH" = "master" ]; then docker push "$DOCKER_IMAGE:latest"; fi
- if [ "$CI_COMMIT_BRANCH" = "develop" -o "$CI_COMMIT_BRANCH" = "master" ]; then docker build -t "$DOCKER_IMAGE:$VERSION" .; fi
# version in lower case
- if [ "$CI_COMMIT_BRANCH" = "develop" -o "$CI_COMMIT_BRANCH" = "master" -a "$VERSION" != "$LOWER_CASE_VERSION" ]; then docker build -t "$DOCKER_IMAGE:$LOWER_CASE_VERSION" .; fi
- if [ "$CI_COMMIT_BRANCH" = "develop" -o "$CI_COMMIT_BRANCH" = "master" -a "$VERSION" != "$LOWER_CASE_VERSION" ]; then docker push "$DOCKER_IMAGE:$LOWER_CASE_VERSION"; fi
- docker build -t "$DOCKER_IMAGE:$FORMATTED_COMMIT_BRANCH" .
- docker push "$DOCKER_IMAGE:$FORMATTED_COMMIT_BRANCH"
# branch in lower case
- docker build -t "$DOCKER_IMAGE:$LOWER_CASE_COMMIT_BRANCH" .
- docker push "$DOCKER_IMAGE:$LOWER_CASE_COMMIT_BRANCH"
rules:
- if: $CI_COMMIT_BRANCH == "master"
when: always
- if: $CI_COMMIT_BRANCH == "develop"
when: always
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
when: never
- if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH
when: manual
needs:
- build
- package
tags:
- stable
variables:
MAVEN_CLI_OPTS: "-s .m2/settings.xml --batch-mode"
MAVEN_OPTS: "-Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository"
cache:
paths:
- .m2/repository/
build:
image: eclipse-temurin:17.0.12_7-jdk
stage: build
before_script:
- apt-get update && apt-get install -y maven
script:
- mvn $MAVEN_OPTS compile
- TRUEVERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
- VERSION=$TRUEVERSION
- if [ "$CI_COMMIT_BRANCH" = "master" ]; then VERSION=${VERSION%"-SNAPSHOT"}; fi
- LOWER_CASE_VERSION=${VERSION,,}
# Replace / by _ in the name of the commit
- FORMATTED_COMMIT_BRANCH=${CI_COMMIT_BRANCH//\//_}
- LOWER_CASE_COMMIT_BRANCH=${FORMATTED_COMMIT_BRANCH,,}
- echo "VERSION=$VERSION" >> build.env
- echo "TRUEVERSION=$TRUEVERSION" >> build.env
- echo "FORMATTED_COMMIT_BRANCH=$FORMATTED_COMMIT_BRANCH" >> build.env
- echo "LOWER_CASE_VERSION=$LOWER_CASE_VERSION" >> build.env
- echo "LOWER_CASE_COMMIT_BRANCH=$LOWER_CASE_COMMIT_BRANCH" >> build.env
artifacts:
expire_in: 60 min
paths:
- target/
- "*/target"
reports:
dotenv: build.env
tags:
- stable
test:
image: eclipse-temurin:17.0.12_7-jdk
stage: test
before_script:
- apt-get update && apt-get install -y maven
script:
- find . -name "*.class" -exec touch {} \+
- mvn $MAVEN_OPTS clean test
- cat coverage/target/site/jacoco-aggregate/index.html | grep -o '<tfoot>.*</tfoot>'
coverage: '/Total.*?([0-9]{1,3})%/'
tags:
- stable
package:
image: eclipse-temurin:17.0.12_7-jdk
stage: package
before_script:
- apt-get update && apt-get install -y maven
script:
- mvn $MAVEN_OPTS clean install -DskipTests=true
- cd met4j-toolbox
- mvn $MAVEN_OPTS package -DskipTests=true
- cd ..
artifacts:
expire_in: 60 min
paths:
- "met4j-toolbox/target/met4j-toolbox*.jar"
tags:
- stable
deployJar:
stage: deploy
image: curlimages/curl:latest
script:
- 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file "met4j-toolbox/target/met4j-toolbox-$TRUEVERSION.jar" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/met4j-toolbox/$VERSION/met4j-toolbox.jar"'
rules:
- if: $CI_COMMIT_BRANCH == "master"
when: always
- if: $CI_COMMIT_BRANCH == "develop"
when: always
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
when: never
- if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH
when: manual
needs:
- build
- package
tags:
- stable
deploySnapshot:
image: eclipse-temurin:17.0.12_7-jdk
stage: deploy
before_script:
- apt-get update && apt-get install -y maven
script:
- mvn $MAVEN_CLI_OPTS deploy -Dmaven.test.skip=true
only:
- develop
deployCentral:
image: eclipse-temurin:17.0.12_7-jdk
stage: deploy
before_script:
- apt-get update && apt-get install -y maven git
- 'which ssh-agent || ( apt-get update -qy && apt-get install openssh-client -qqy )'
- 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- echo "${SSH_PRIVATE_KEY}" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
- 'which gpg || ( apt-get update -qy && apt-get install gnupg -qqy )'
- export GPG_TTY=$(tty)
- gpg -v --batch --import <(echo "${GPG_PRIVATE_KEY}")
script:
- git config --global user.email "$env:GITLAB_USER_EMAIL"
- git config --global user.name "$env:GITLAB_USER_NAME"
- git checkout -B "$CI_COMMIT_REF_NAME"
- mvn $MAVEN_CLI_OPTS release:prepare -DautoVersionSubmodules=true -Dmaven.test.skip=true -DscmCommentPrefix="[skip ci]" -DupdateWorkingCopyVersions=false -DpushChanges=false -DskipTests
- mvn $MAVEN_CLI_OPTS release:perform -Darguments=-Dgpg.passphrase=${GPG_PASSPHRASE} -DlocalCheckout=true -DskipTests -Dmaven.test.skip=true
only:
- master
tags:
- stable
buildSingularity:
stage: build-containers
image:
name: quay.io/singularity/singularity:v3.11.5-slim
entrypoint: [ "" ]
script:
- singularity build met4j-toolbox.sif met4j.singularity
- if [ "$CI_COMMIT_BRANCH" = "master" ]; then singularity push --docker-username "${CI_REGISTRY_USER}" --docker-password "${CI_REGISTRY_PASSWORD}" met4j-toolbox.sif oras://"$CI_REGISTRY_IMAGE"/met4j-singularity:"latest"; fi
- if [ "$CI_COMMIT_BRANCH" = "develop" -o "$CI_COMMIT_BRANCH" = "master" ]; then singularity push --docker-username "${CI_REGISTRY_USER}" --docker-password "${CI_REGISTRY_PASSWORD}" met4j-toolbox.sif oras://"$CI_REGISTRY_IMAGE"/met4j-singularity:"$VERSION"; fi
# version in lower case
- if [ "$CI_COMMIT_BRANCH" = "develop" -o "$CI_COMMIT_BRANCH" = "master" -a "$VERSION" != "$LOWER_CASE_VERSION"]; then singularity push --docker-username "${CI_REGISTRY_USER}" --docker-password "${CI_REGISTRY_PASSWORD}" met4j-toolbox.sif oras://"$CI_REGISTRY_IMAGE"/met4j-singularity:"$LOWER_CASE_VERSION"; fi
- singularity push --docker-username "${CI_REGISTRY_USER}" --docker-password "${CI_REGISTRY_PASSWORD}" met4j-toolbox.sif oras://"$CI_REGISTRY_IMAGE"/met4j-singularity:"$FORMATTED_COMMIT_BRANCH"
# branch in lower case
- singularity push --docker-username "${CI_REGISTRY_USER}" --docker-password "${CI_REGISTRY_PASSWORD}" met4j-toolbox.sif oras://"$CI_REGISTRY_IMAGE"/met4j-singularity:"$LOWER_CASE_COMMIT_BRANCH"
rules:
- if: $CI_COMMIT_BRANCH == "master"
when: always
- if: $CI_COMMIT_BRANCH == "develop"
when: always
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
when: never
- if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH
when: manual
needs:
- build
- package
tags:
- stable
buildDockerProdGitlab:
extends: .template_docker
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- DOCKER_IMAGE="$CI_REGISTRY/metexplore/met4j/met4j-docker"
tags:
- stable
buildDockerProdDockerhub:
extends: .template_docker
before_script:
- docker login -u "$DOCKERHUB_USER" -p "$DOCKERHUB_PASSWORD" $DOCKERHUB_REGISTRY
- DOCKER_IMAGE=$DOCKERHUB_IMAGE
tags:
- stable