forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
287 lines (237 loc) · 9.86 KB
/
cypress_tests_workflow.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
285
286
287
name: Cypress 12 experimental tests
on:
push:
branches: ['**']
pull_request:
branches: ['**']
paths-ignore:
- '**/*.md'
- 'docs/**'
- '.lycheeignore'
- 'CODEOWNERS'
- 'changelogs/fragments/**'
env:
CYPRESS_BROWSER: 'chromium'
NODE_OPTIONS: '--max-old-space-size=6144 --dns-result-order=ipv4first'
COVERAGE: true
PROJECT_ARTIFACT_NAME: 'project-artifact'
COMBINATIONS: |
[
[],
["SECURITY"],
["WORKSPACE", "DATA_SOURCE", "QUERY_ENHANCEMENTS", "USE_NEW_HOME_PAGE"]
]
jobs:
build-and-validate:
name: Build and validate
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
registry-url: 'https://registry.npmjs.org'
- name: Setup Yarn
run: |
npm uninstall -g yarn
npm i -g [email protected]
yarn config set network-timeout 1000000 -g
- name: Run bootstrap
run: yarn osd bootstrap
- name: Check for yarn.lock changes
run: |
if [[ `git status --porcelain yarn.lock` ]]; then
echo -e "\033[31mThe yarn.lock file is out of sync!\033[0m"
git diff
exit 1
fi
- name: Generate dev docs
run: yarn docs:generateDevDocs
- name: Check for dev docs changes
run: |
if [[ `git status --porcelain docs/_sidebar.md` ]]; then
echo -e "\033[31mThe dev docs are out of sync; run yarn docs:generateDevDocs and amend the PR.\033[0m"
git diff
exit 1
fi
- name: Run linter
id: linter
run: yarn lint
- name: Validate NOTICE file
id: notice-validate
run: yarn notice:validate
- name: Validate licenses
id: i18n-licenses
run: yarn checkLicenses
- name: Check i18n
id: i18n-check
run: yarn i18n:check
- name: Build plugins
run: node scripts/build_opensearch_dashboards_platform_plugins --no-examples --workers 10
# upload-artifact looses permissions; we need to tar it to maintain them
- name: Archive content
run: tar -czf /tmp/osd-build.tar.gz --exclude=.git --exclude=.yarn .
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.PROJECT_ARTIFACT_NAME }}
path: /tmp/osd-build.tar.gz
retention-days: 1
prepare-cypress-matrix:
name: Prepare Cypress tests
needs: build-and-validate
runs-on: ubuntu-latest
outputs:
test-matrix: ${{ steps.create-list.outputs.list }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Trigger tests for combinations
id: create-list
run: |
declare -a inputs_array
process_spec() {
local spec_path="$1"
local spec_name="$2"
local counter=1
while IFS= read -r combo; do
echo "Preparing tests for $spec_name with combination $counter: $combo"
input_object=$(jq -n \
--arg spec_pattern "$spec_path" \
--arg run_flag "${spec_name}:${counter}" \
--argjson combo "$combo" \
'{
spec_pattern: $spec_pattern,
run_flag: $run_flag
} + ($combo | to_entries | map({key: .value, value: "true"}) | from_entries)')
echo "Generated input_object:"
echo "$input_object" | jq .
inputs_array+=("$input_object")
echo "Current size of inputs_array: ${#inputs_array[@]}"
counter=$((counter + 1))
done < <(echo "$COMBINATIONS" | jq -c '.[]')
}
# Process spec files at the root
root_specs=$(find ./cypress/integration -maxdepth 1 -name "*.spec.js")
if [ -n "$root_specs" ]; then
echo "Found root specs: $root_specs"
process_spec "cypress/integration/*.spec.js" "root"
fi
# Process spec folders
for folder in ./cypress/integration/*/; do
if [ -d "$folder" ]; then
folder_name=$(basename "$folder")
echo "Processing folder: $folder_name"
folder_specs=$(find "$folder" -name "*.spec.js")
if [ -n "$folder_specs" ]; then
echo "Found specs in $folder_name: $folder_specs"
process_spec "cypress/integration/$folder_name/**/*.spec.js" "$folder_name"
fi
fi
done
if [ ${#inputs_array[@]} -eq 0 ]; then
echo "No test configurations generated!"
json_output='{"include":[]}'
else
json_output=$(printf '%s\n' "${inputs_array[@]}" | jq -s '{"include": .}')
fi
# Escape the JSON string for GitHub Actions
escaped_json_output=$(echo "$json_output" | jq -c -r @json)
echo "list=$escaped_json_output" >> $GITHUB_OUTPUT
run-tests:
name: Run tests (cypress:${{ matrix.run_flag }})
needs: [prepare-cypress-matrix, build-and-validate]
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJson(needs.prepare-cypress-matrix.outputs.test-matrix) }}
fail-fast: false
steps:
- name: Display run details
run: |
echo "Flag: ${{ matrix.run_flag }}"
echo "Spec pattern: ${{ matrix.spec_pattern }}"
echo "Security enabled: ${{ matrix.SECURITY || 'false' }}"
echo "Workspace enabled: ${{ matrix.WORKSPACE || 'false' }}"
echo "Data Source enabled: ${{ matrix.DATA_SOURCE || 'false' }}"
echo "Query Enhancements enabled: ${{ matrix.QUERY_ENHANCEMENTS || 'false' }}"
echo "New Home enabled: ${{ matrix.USE_NEW_HOME_PAGE || 'false' }}"
- name: Checkout code
uses: actions/checkout@v4
- name: Download built artifact
uses: actions/download-artifact@v4
with:
name: ${{ env.PROJECT_ARTIFACT_NAME }}
path: .
- name: Extract archive
run: |
tar -xzf osd-build.tar.gz --overwrite --ignore-command-error
rm osd-build.tar.gz
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
registry-url: 'https://registry.npmjs.org'
- name: Setup Yarn
run: |
npm uninstall -g yarn
npm i -g [email protected]
yarn config set network-timeout 1000000 -g
- name: Security setup
if: ${{ matrix.SECURITY == 'true' }}
# ToDo: make this branch specific
run: git clone https://github.com/opensearch-project/security-dashboards-plugin.git --depth 1 -- ./plugins/security-dashboards-plugin
- name: Run bootstrap
run: yarn osd bootstrap --single-version=loose
- name: Build plugins
run: node scripts/build_opensearch_dashboards_platform_plugins --no-examples --workers 10
- name: Setup JDK
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'corretto'
- name: Get package version
run: |
echo "OSD_VERSION=$(yarn --silent pkg-version)" >> $GITHUB_ENV
- name: Run OpenSearch
run: |
npm i osd-launcher -g
if [ "${{ matrix.SECURITY }}" = "true" ]; then
osd-launcher -os ${{ env.OSD_VERSION }} -p dummy --destination ~/
else
osd-launcher -os ${{ env.OSD_VERSION }} --no-security --no-plugins -p dummy --destination ~/
fi
/bin/bash -c ~/OpenSearch-v${{ env.OSD_VERSION }}/bin/opensearch &
- name: Run OSD
run: |
SECURITY_FLAG=$([ "${{ matrix.SECURITY }}" = "true" ] && echo "--opensearch.hosts=https://localhost:9200" || echo "--opensearch.hosts=http://localhost:9200")
WORKSPACE_FLAG=$([ "${{ matrix.WORKSPACE }}" = "true" ] && echo "--workspace.enabled=true" || echo "--workspace.enabled=false")
DATA_SOURCE_FLAG=$([ "${{ matrix.DATA_SOURCE }}" = "true" ] && echo "--data_source.enabled=true" || echo "--data_source.enabled=false")
QUERY_ENHANCEMENTS_FLAG=$([ "${{ matrix.QUERY_ENHANCEMENTS }}" = "true" ] && echo "--uiSettings.overrides["query:enhancements:enabled"]=true" || echo "--uiSettings.overrides["query:enhancements:enabled"]=false")
USE_NEW_HOME_PAGE_FLAG=$([ "${{ matrix.USE_NEW_HOME_PAGE }}" = "true" ] && echo "--uiSettings.overrides["home:useNewHomePage"]=true" || echo "--uiSettings.overrides["home:useNewHomePage"]=false")
/bin/bash -c "node scripts/opensearch_dashboards --dev --no-base-path --no-watch --opensearch.ignoreVersionMismatch=true --opensearch.ssl.verificationMode=none --savedObjects.maxImportPayloadBytes=10485760 --server.maxPayloadBytes=1759977 --logging.json=false --data.search.aggs.shardDelay.enabled=true --csp.warnLegacyBrowsers=false SECURITY_FLAG $WORKSPACE_FLAG $DATA_SOURCE_FLAG $QUERY_ENHANCEMENTS_FLAG USE_NEW_HOME_PAGE_FLAG & pid=\$!; sleep 30; disown \$pid"
- name: Run tests
run: yarn test:cypress --spec "${{ matrix.spec_pattern }}"
- name: Upload coverage
id: upload-code-coverage
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
directory: ./coverage
flags: "cypress:${{ matrix.run_flag }}"
- name: Generate safe artifact name
id: safe-name
run: |
value=$(echo "${{ matrix.run_flag }}" | sed -E 's/[^a-z0-9_-]+/_/gi' | sed -E 's/^_|_$//g')
echo "value=${value}" >> $GITHUB_OUTPUT
- name: Upload test artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: cypress_artifact_${{ steps.safe-name.outputs.value }}
path: |
cypress/screenshots
cypress/videos
coverage
retention-days: 1