-
Notifications
You must be signed in to change notification settings - Fork 3
293 lines (251 loc) · 9.6 KB
/
test-plugins-against-cockpit.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
288
289
290
291
292
293
name: Test plugins against Cockpit
on:
pull_request:
schedule:
- cron: '15 4 * * 1-5'
permissions:
contents: read
actions: write
env:
ACTIONS_STEP_DEBUG: true
jobs:
collect-shell-versions:
timeout-minutes: 30
runs-on: ubuntu-22.04
outputs:
shell_versions: ${{ steps.filter-versions.outputs.shell_versions }}
plugins_version: ${{ steps.extract-plugins-version.outputs.plugins_version }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Collect Shell Versions
id: collect-shell-versions
uses: SoftwareAG/plugins-e2e-setup/collect-shell-versions@main
with:
exact-tags: y2025-lts
- name: Extract Plugins Version
id: extract-plugins-version
run: |
plugins_version=$(jq -r '.version' package.json)
echo "plugins_version=${plugins_version}" >> $GITHUB_ENV
echo "::set-output name=plugins_version::${plugins_version}"
- name: Retrieve cached JSON previous test results files
if: ${{ github.event_name == 'schedule' }}
id: retrieve-cache
uses: actions/cache/restore@v4
with:
path: ./cache-files
key: test-plugins-against-shell-e2e-results
- name: Verify cache contents
if: ${{ github.event_name == 'schedule' }}
run: |
echo "Contents of the cache:"
mkdir -p ./cache-files
ls -l ./cache-files
for file in ./cache-files/*; do
if [[ -f "$file" ]]; then
echo "Content of $file:"
cat "$file"
fi
done
- name: Filter out already tested versions and set shell_versions output # for pull_request event cache retrieval is omitted so no versions from step collect-shell-versions are filtered out
id: filter-versions
run: |
versions=$(jq -r '.[] | @base64' <<< '${{ steps.collect-shell-versions.outputs.shell_versions }}')
filtered_versions="[]"
for version in $versions; do
_jq() {
echo ${version} | base64 --decode | jq -r ${1}
}
tag=$(_jq '.tag')
ver=$(_jq '.version')
file="./cache-files/${tag}-${{ steps.extract-plugins-version.outputs.plugins_version }}.json"
if [[ -f "$file" ]]; then
echo "Cache file exists: $file"
alreadyTestedShellVersion=$(jq -r '.shellVersion' $file)
alreadyTestedPluginsVersion=$(jq -r '.pluginsVersion' $file)
if [[ "$alreadyTestedShellVersion" == "$ver" && "$alreadyTestedPluginsVersion" == "${{ steps.extract-plugins-version.outputs.plugins_version }}" ]]; then
echo "Shell version $alreadyTestedShellVersion with plugins of version $alreadyTestedPluginsVersion already tested. Skipping..."
continue
fi
else
echo "No cache file found for $tag with plugins version ${{ steps.extract-plugins-version.outputs.plugins_version }}"
fi
filtered_versions=$(jq --argjson ver "$(echo $version | base64 --decode)" '. + [$ver]' <<< $filtered_versions)
done
# Properly escape the output for GitHub Actions
filtered_versions_escaped=$(echo "$filtered_versions" | jq -c .)
echo "Filtered shell versions: $filtered_versions_escaped"
echo "::set-output name=shell_versions::$filtered_versions_escaped"
- name: Verify shell versions output
run: echo "Shell versions to test against ${{ steps.filter-versions.outputs.shell_versions }}"
build-plugins:
if: needs.collect-shell-versions.outputs.shell_versions != '[]'
needs: collect-shell-versions
timeout-minutes: 30
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: build
if-no-files-found: error
retention-days: 5
path: |
dist/sag-pkg-community-plugins/**
run-tests-against-shell:
if: needs.collect-shell-versions.outputs.shell_versions != '[]'
needs: [collect-shell-versions, build-plugins]
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
version_data: ${{ fromJson(needs.collect-shell-versions.outputs.shell_versions) }}
env:
JSON: ${{ toJson(matrix.version_data) }}
VERSION: ${{ matrix.version_data.version }}
TAG: ${{ matrix.version_data.tag }}
PLUGINS_VERSION: ${{ needs.collect-shell-versions.outputs.plugins_version }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: build
path: dist/apps/sag-pkg-community-plugins/ # download the build artifact to "dist/apps/" as whole dist folder will be served and url will match adopted scheme like "<base url>/apps/cockpit/index.html"
- name: Get shell app of particular version
uses: SoftwareAG/plugins-e2e-setup/get-shell-app@main
with:
shell-name: cockpit
shell-version: ${{ env.VERSION }}
shell-path: dist/apps
- name: Cypress run
uses: cypress-io/github-action@v5
with:
start: npm run cypress:ctrl
install: false
wait-on: 'http://localhost:4200/apps/cockpit/index.html'
browser: chrome
record: false
config-file: cypress.config.ts
env: C8Y_CTRL_MODE=mocking,grepTags=@shell
- name: Upload cypress screenshots
if: failure()
uses: actions/upload-artifact@v4
with:
retention-days: 5
name: cypress-screenshots
path: cypress/screenshots
- name: Upload cypress videos
if: always()
uses: actions/upload-artifact@v4
with:
retention-days: 5
name: cypress-videos
path: cypress/videos
- name: Create or update JSON file
if: ${{ github.event_name == 'schedule' }}
run: |
mkdir -p ./cache-files
file="./cache-files/${{ env.TAG }}-${{ env.PLUGINS_VERSION }}.json"
now=$(date --utc +"%Y-%m-%dT%H:%M:%SZ")
jq -n --arg shellVersion "${{ env.VERSION }}" --arg pluginsVersion "${{ env.PLUGINS_VERSION }}" --arg lastSuccess "$now" '{shellVersion: $shellVersion, pluginsVersion: $pluginsVersion, lastSuccess: $lastSuccess}' > $file
cat $file
- name: Upload updated JSON file
if: ${{ github.event_name == 'schedule' }}
uses: actions/upload-artifact@v4
with:
name: updated-json-${{ matrix.version_data.tag }}-${{ matrix.version_data.version }}-${{ env.PLUGINS_VERSION }}
path: ./cache-files/${{ env.TAG }}-${{ env.PLUGINS_VERSION }}.json
cache-upload:
permissions:
actions: write
if: ${{ github.event_name == 'schedule' && needs.collect-shell-versions.outputs.shell_versions != '[]' }}
needs: [collect-shell-versions, run-tests-against-shell]
runs-on: ubuntu-22.04
steps:
- name: Setup cache directory
run: mkdir -p ./cache-files
- name: Download updated JSON files
uses: actions/download-artifact@v4
with:
path: ./cache-files
pattern: updated-json-*
merge-multiple: true
- name: Log artifacts
run: |
echo "Listing contents of ./cache-files :"
ls -la ./cache-files
- name: Retrieve cached JSON files
id: check-cache
uses: actions/cache/restore@v4
with:
path: ./cache-files
key: test-plugins-against-shell-e2e-results
- name: Log all files
run: |
echo "Listing contents of ./cache-files :"
ls -la ./cache-files
- name: Delete previous cache # cache cannot be overridden therefore it has to be deleted and saved again
if: steps.check-cache.outputs.cache-hit == 'true'
run: |
gh extension install actions/gh-actions-cache
gh actions-cache delete test-plugins-against-shell-e2e-results --confirm -R ${{github.repository}}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Save results to cache
uses: actions/cache/save@v4
with:
path: ./cache-files
key: test-plugins-against-shell-e2e-results
verify-cache:
if: ${{ github.event_name == 'schedule' && needs.collect-shell-versions.outputs.shell_versions != '[]' }}
needs:
[
collect-shell-versions,
build-plugins,
run-tests-against-shell,
cache-upload,
]
runs-on: ubuntu-22.04
steps:
- name: Retrieve cached JSON files
uses: actions/cache/restore@v4
with:
path: ./cache-files
key: test-plugins-against-shell-e2e-results
- name: Verify cache contents
run: |
echo "Contents of the cache:"
ls -l ./cache-files
for file in ./cache-files/*; do
if [[ -f "$file" ]]; then
echo "Content of $file:"
cat "$file"
fi
done