-
Notifications
You must be signed in to change notification settings - Fork 0
235 lines (219 loc) · 8.91 KB
/
tests.yml
File metadata and controls
235 lines (219 loc) · 8.91 KB
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
name: Tests
on:
push:
paths-ignore:
- "**/README.md"
workflow_dispatch:
inputs:
modules:
description: 'Modules to test (comma-separated: user, chat, common-styling, payments-example-gateway, or "all")'
required: false
default: 'all'
type: string
jobs:
pre_job:
runs-on: ubuntu-latest
outputs:
should_skip: ${{ steps.skip_check.outputs.should_skip }}
steps:
- id: skip_check
uses: fkirc/skip-duplicate-actions@master
with:
github_token: ${{ github.token }}
paths_ignore: '["**/README.md"]'
do_not_skip: '["push", "workflow_dispatch"]'
detect-changes:
needs: pre_job
if: ${{ github.event_name == 'workflow_dispatch' || needs.pre_job.outputs.should_skip != 'true' }}
runs-on: ubuntu-latest
outputs:
changed-modules: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
if: github.event_name != 'workflow_dispatch'
with:
base: ${{ github.event.before }}
ref: ${{ github.event.after }}
filters: |
user:
- 'pos-module-user/**'
chat:
- 'pos-module-chat/**'
common-styling:
- 'pos-module-common-styling/**'
payments-stripe:
- 'pos-module-payments-stripe/**'
payments-example-gateway:
- 'pos-module-payments-example-gateway/**'
- name: Set matrix for changed modules
id: set-matrix
run: |
# Define module configurations
cat > /tmp/module-config.json << 'EOF'
{
"user": {
"module": "user",
"path": "pos-module-user",
"deploy-script": "rm app/pos-modules.* || true\nsh ./tests/data/seed/seed.sh",
"test-commands": "npm run admin-panel-pw-tests\nnpm run pw-tests"
},
"chat": {
"module": "chat",
"path": "pos-module-chat",
"deploy-script": "rm app/pos-modules.* || true\nsh ./tests/data/seed/seed.sh",
"test-commands": "npm run pw-tests"
},
"common-styling": {
"module": "common-styling",
"path": "pos-module-common-styling",
"deploy-script": "pos-cli data clean --include-schema --auto-confirm\npos-cli deploy",
"test-commands": "npm run pw-tests"
},
"payments-stripe": {
"module": "payments-stripe",
"path": "pos-module-payments-stripe",
"deploy-script": "./tests/data/seed/seed.sh",
"test-commands": "npm run api-tests"
},
"payments-example-gateway": {
"module": "payments-example-gateway",
"path": "pos-module-payments-example-gateway",
"deploy-script": "./tests/data/seed/seed.sh",
"test-commands": "npm run pw-tests"
}
}
EOF
# Check if this is a manual trigger
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "Manual trigger detected"
manual_input="${{ github.event.inputs.modules }}"
echo "Manual input: $manual_input"
if [ "$manual_input" = "all" ] || [ -z "$manual_input" ]; then
# Test all modules
modules=$(jq -c '[.user, .chat, ."common-styling", ."payments-example-gateway"]' /tmp/module-config.json)
else
# Parse comma-separated list, strip pos-module- prefix, and map to configurations
modules=$(echo "$manual_input" | \
jq -R -c 'split(",") | map(gsub("^\\s+|\\s+$"; "") | gsub("^pos-module-"; ""))' | \
jq -c --slurpfile config /tmp/module-config.json \
'map(. as $m | $config[0][$m] | select(. != null))')
fi
echo "Manual trigger modules: $modules"
else
# Automatic detection from git changes
changes='${{ steps.filter.outputs.changes }}'
echo "Detected changes: $changes"
# Extract changed modules and map to their configurations
modules=$(jq -nc --argjson changes "$changes" --slurpfile config /tmp/module-config.json \
'$changes | map(. as $m | $config[0][$m] | select(. != null))')
echo "Changed modules matrix: $modules"
fi
echo "matrix=$modules" >> $GITHUB_OUTPUT
run-tests:
needs: detect-changes
if: |
needs.detect-changes.result == 'success' &&
needs.detect-changes.outputs.changed-modules != '[]'
runs-on: ubuntu-latest
container: ${{ vars.PW_CONTAINER }}
strategy:
matrix:
include: ${{ fromJSON(needs.detect-changes.outputs.changed-modules) }}
max-parallel: 1
fail-fast: false
timeout-minutes: 60
env:
CI: true
MPKIT_EMAIL: ${{ secrets.MPKIT_EMAIL }}
NPM_CONFIG_CACHE: ${{ github.workspace }}/.npm
E2E_TEST_PASSWORD: ${{ secrets.E2E_TEST_PASSWORD }}
STRIPE_SK_KEY: ${{ secrets.STRIPE_SK_KEY }}
HTML_ATTACHMENTS_BASE_URL: ${{ vars.HTML_ATTACHMENTS_BASE_URL }}
TEST_REPORT_MPKIT_URL: ${{ vars.TEST_REPORT_MPKIT_URL }}
TEST_REPORT_MPKIT_TOKEN: ${{ secrets.TEST_REPORT_MPKIT_TOKEN }}
steps:
- name: Reserve CI instance
id: reserve
uses: Platform-OS/ci-repository-reserve-instance-url@0.1.2
with:
repository-url: ${{ vars.CI_PS_REPOSITORY_URL }}
method: reserve
pos-ci-repo-token: ${{ secrets.POS_CI_PS_REPO_ACCESS_TOKEN }}
- name: Get MPKIT token
id: get-token
uses: Platform-OS/ci-repository-reserve-instance-url@0.1.2
with:
method: get-token
repository-url: ${{ vars.CI_PS_REPOSITORY_URL }}
pos-ci-repo-token: ${{ secrets.POS_CI_PS_REPO_ACCESS_TOKEN }}
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref || github.ref_name }}
- uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Deploy module
timeout-minutes: 10
shell: sh
env:
MPKIT_URL: ${{ steps.reserve.outputs.mpkit-url }}
MPKIT_TOKEN: ${{ steps.get-token.outputs.mpkit-token }}
working-directory: ${{ matrix.path }}
run: |
set -eu
${{ matrix.deploy-script }}
- name: Run Playwright tests
shell: sh
env:
MPKIT_URL: ${{ steps.reserve.outputs.mpkit-url }}
MPKIT_TOKEN: ${{ steps.get-token.outputs.mpkit-token }}
working-directory: ${{ matrix.path }}
run: |
set -eu
${{ matrix.test-commands }}
- name: Release CI instance
if: always()
uses: Platform-OS/ci-repository-reserve-instance-url@0.1.2
with:
method: release
repository-url: ${{ vars.CI_PS_REPOSITORY_URL }}
pos-ci-repo-token: ${{ secrets.POS_CI_PS_REPO_ACCESS_TOKEN }}
conclusion:
needs: [detect-changes, run-tests]
if: always()
runs-on: ubuntu-latest
steps:
- name: Generate workflow summary
run: |
if [ "${{ needs.detect-changes.outputs.changed-modules }}" = "[]" ] || [ "${{ needs.detect-changes.result }}" = "skipped" ]; then
echo "## Tests - Skipped" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ needs.detect-changes.result }}" = "skipped" ]; then
echo "Workflow was skipped by duplicate action check." >> $GITHUB_STEP_SUMMARY
elif [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "Manual trigger with no matching modules selected." >> $GITHUB_STEP_SUMMARY
else
echo "No modules with tests were changed in this push." >> $GITHUB_STEP_SUMMARY
fi
else
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "## Tests - Completed (Manual Trigger)" >> $GITHUB_STEP_SUMMARY
else
echo "## Tests - Completed" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "Tests ran for the following modules:" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo '${{ needs.detect-changes.outputs.changed-modules }}' | jq -r '.[] | "- " + .module' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ needs.run-tests.result }}" = "success" ]; then
echo "Result: All tests passed" >> $GITHUB_STEP_SUMMARY
elif [ "${{ needs.run-tests.result }}" = "skipped" ]; then
echo "Result: Tests were skipped" >> $GITHUB_STEP_SUMMARY
else
echo "Result: Some tests failed - check job output for details" >> $GITHUB_STEP_SUMMARY
fi
fi