-
Notifications
You must be signed in to change notification settings - Fork 2
/
.gitlab-ci.yml
235 lines (220 loc) · 7.56 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
variables:
SG_JAVA_BUILD_VERSION: "8"
# Mnemonic: SF: Search Frontend; SB: Search Backend
SF_PRODUCT: kibana
SF_JSON: kibana.json
SF_REPO_URL: "https://github.com/elastic/kibana.git"
SF_REPO_DIR: $SF_PRODUCT
SB_PRODUCT: elasticsearch
SG_SB_PLUGIN_SNAPSHOT_REPO: search-guard-flx-snapshot
SG_SB_PLUGIN_STAGING_REPO: search-guard-flx-staging
SG_SB_PLUGIN_RELEASE_REPO: search-guard-flx-release
SG_SF_PLUGIN_SNAPSHOT_REPO: search-guard-flx-snapshot
SG_SF_PLUGIN_STAGING_REPO: search-guard-flx-staging
SG_SF_PLUGIN_RELEASE_REPO: search-guard-flx-release
SG_SF_PLUGIN_NAME: search-guard-flx-kibana-plugin
SG_SB_PLUGIN_NAME: search-guard-flx-elasticsearch-plugin
NODE_DOCKER: node:21.6.1
image: circleci/openjdk:${SG_JAVA_BUILD_VERSION}-jdk-browsers
workflow:
rules:
- if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS'
when: never
- when: always
before_script:
- |
source ci/utils.sh
if [ -d $SF_REPO_DIR ]; then du --summarize -h $SF_REPO_DIR; fi
if [[ $CI_COMMIT_TAG =~ ^sg-flx-([a-z0-9\.\-]+)-([oe]s)-([0-9\.]+)$ ]]; then
export SG_SF_PLUGIN_VERSION=${BASH_REMATCH[1]}
export BUILD_VERSION="${BASH_REMATCH[1]}-${BASH_REMATCH[2]}-${BASH_REMATCH[3]}"
export SF_VERSION=${BASH_REMATCH[3]}
else
export SG_SF_PLUGIN_VERSION="b-$CI_COMMIT_REF_NAME-SNAPSHOT"
export BUILD_VERSION="b-$CI_COMMIT_REF_NAME-SNAPSHOT"
export SF_VERSION=$(grep -e '\bversion\b' $SF_JSON | tr -d "[:blank:]" | sed -E 's/"version":"(.*)"(.*)/\1/')
fi
echo "================================="
echo "SG_SF_PLUGIN_VERSION: $SG_SF_PLUGIN_VERSION"
echo "BUILD_VERSION: $BUILD_VERSION"
echo "SF_VERSION: $SF_VERSION"
echo "================================="
stages:
- prepare
- build
- package
- "Frontend Int Tests Core"
- "Frontend Int Tests Features"
- "Frontend Int Tests External Features"
- release
prepare_versions:
stage: prepare
tags:
- build
script:
- |
set -e
URL="https://raw.githubusercontent.com/$SB_PRODUCT/$SF_PRODUCT/v$SF_VERSION/package.json"
curl -s $URL -o .build_versions
if [ ! -f package.json ]; then
echo "Failed to download package.json from $URL"
exit 1
fi
echo "KIBANA_BUILD_NODE_VERSION=$(jq -r '.engines.node | gsub("^\\^"; "")' .build_versions)" > versions.env
echo "KIBANA_BUILD_YARN_VERSION=$(jq -r '.engines.yarn | gsub("^\\^"; "")' .build_versions)" >> versions.env
cat versions.env
artifacts:
paths:
- versions.env
#This case is for usual commit to the branch, doing only unit testing and local build
build:
image: $NODE_DOCKER
stage: build
tags:
- build
rules:
- if: '$CI_COMMIT_TAG =~ /^sg-.*/'
when: never
- when: always
script:
- |
set -e
source versions.env
source ci/install_dependencies.sh
source ci/init_build.sh
cd $SF_REPO_DIR/plugins/search-guard
start_section tests "Unit Tests"
export JEST_JUNIT_OUTPUT_FILE=$CI_PROJECT_DIR/junit-server.xml
../../node_modules/.bin/jest --clearCache && ../../node_modules/.bin/jest --testPathIgnorePatterns=server --config ./tests/jest.config.js --reporters="default"
export JEST_JUNIT_OUTPUT_FILE=$CI_PROJECT_DIR/junit-public.xml
../../node_modules/.bin/jest --clearCache && ../../node_modules/.bin/jest --testPathIgnorePatterns=public --config ./tests/jest.config.js --reporters="default"
end_section tests
rm -rf "node_modules"
start_section build "Building Search Guard Plugin"
cp -a -f ../../../yarn.lock .
start_section yarn_install "Doing yarn install --production --frozen-lockfile"
yarn install --production --frozen-lockfile
end_section yarn_install
start_section yarn_build "Doing yarn build -v $SF_VERSION --skip-archive"
yarn build -v $SF_VERSION --skip-archive
end_section yarn_build
end_section build
# Move build result from repo dir to the build folder in the CI root dir.
cd $CI_PROJECT_DIR
rm -rf build
mv $SF_REPO_DIR/plugins/search-guard/build build
# Remove search-guard dir from repo to have a clean repo for the Gitlab CI cache
rm -rf $SF_REPO_DIR/plugins/search-guard
interruptible: true
artifacts:
when: always
reports:
junit:
- junit*.xml
paths:
- "build.log"
- "build/*"
- junit*.xml
expire_in: 24h
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- ./${SF_REPO_DIR}
#This case is for release tag commit to the branch, doing only unit testing and local build
build_release:
image: $NODE_DOCKER
stage: build
rules:
- if: '$CI_COMMIT_TAG =~ /^sg-.*/'
tags:
- build
script:
- |
set -e
sed -i -e "s#\"version\":.*\"#\"version\": \"$SF_VERSION\"#" $SF_JSON
sed -i -e "s#\"version\":.*\"#\"version\": \"$BUILD_VERSION\"#" package.json
source versions.env
source ci/install_dependencies.sh
source ci/init_build.sh
start_section tests "Unit Tests"
cd $SF_REPO_DIR/plugins/search-guard
export JEST_JUNIT_OUTPUT_FILE=$CI_PROJECT_DIR/junit-server.xml
../../node_modules/.bin/jest --clearCache && ../../node_modules/.bin/jest --testPathIgnorePatterns=server --config ./tests/jest.config.js --reporters="default"
export JEST_JUNIT_OUTPUT_FILE=$CI_PROJECT_DIR/junit-public.xml
../../node_modules/.bin/jest --clearCache && ../../node_modules/.bin/jest --testPathIgnorePatterns=public --config ./tests/jest.config.js --reporters="default"
end_section tests
rm -rf "node_modules"
start_section build "Building Search Guard Plugin"
cp -a -f ../../../yarn.lock .
start_section yarn_install "Doing yarn install --production --frozen-lockfile"
yarn install --production --frozen-lockfile
end_section yarn_install
start_section yarn_build "Doing yarn build -v $SF_VERSION --skip-archive"
yarn build -v $SF_VERSION --skip-archive
end_section yarn_build
end_section build
cd $CI_PROJECT_DIR
rm -rf build
mv $SF_REPO_DIR/plugins/search-guard/build build
rm -rf $SF_REPO_DIR/plugins/search-guard
artifacts:
when: always
paths:
- "build.log"
- "build/*"
expire_in: 24h
deploy_snapshot:
stage: package
interruptible: true
tags:
- build
needs:
- job: build
artifacts: true
rules:
- if: '$CI_COMMIT_TAG =~ /^sg-.*/'
when: never
- when: always
script:
- ci/deploy.sh
artifacts:
when: always
expire_in: 7 days
reports:
dotenv: build.env
deploy_staging:
stage: package
tags:
- build
script:
- ci/deploy.sh staging
needs:
- job: build_release
artifacts: true
rules:
- if: '$CI_COMMIT_TAG =~ /^sg-.*/'
artifacts:
when: always
expire_in: 7 days
reports:
dotenv: build.env
deploy_release:
stage: release
interruptible: true
rules:
- if: '$CI_COMMIT_TAG =~ /^sg-.*/'
tags:
- build
script:
- |
ci/setup_gpg.sh
echo "Removing current release from Staging"
curl -u "$ARTIFACTORY_USER:$ARTIFACTORY_PASSWORD" -X DELETE "https://maven.search-guard.com/artifactory/$SG_SF_PLUGIN_STAGING_REPO/com/floragunn/$SG_SF_PLUGIN_NAME/$BUILD_VERSION" || true
start_section deploy "Deploying to release repository"
mvn -B -s settings.xml -Drevision="$BUILD_VERSION" deploy
end_section deploy
include:
- local: '.gitlab-ci-branch-specific.yml'
- local: 'ci/frontend-int-tests.yml'
- local: 'ci/frontend-int-tests-features.yml'
- local: 'ci/frontend-int-tests-external-features.yml'