Skip to content

Commit fc20998

Browse files
authored
Merge pull request #4655 from crazyserver/MOBILE-4875
MOBILE-4875 behat: Improve behat parallel run detection
2 parents 2296f7a + a30ce6c commit fc20998

File tree

160 files changed

+280
-167
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

160 files changed

+280
-167
lines changed

.github/scripts/print_behat_tags_json.sh

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,62 @@
33
# Search tags.
44
declare -A tags
55

6+
# If the first argument is -d or --debug, enable debug output.
7+
debug=$([[ "$1" == "-d" || "$1" == "--debug" ]] && echo "1" || echo "")
8+
9+
parallelrunmissing=false
610
for feature in `find ./src/ -iname *.feature`
711
do
812
if [[ "$1" == "snapshots" ]] && ! grep -q -i "the UI should match the snapshot" "$feature"; then
913
continue
1014
fi
11-
tag=`head -n 1 $feature | sed -E s/\\\\s+.*//`
12-
tags[$tag]=$tag
15+
16+
featuretags=`head -n 1 $feature`
17+
# Count non-blank lines in feature file also ignoring comments on the start of the line.
18+
lines=`grep -c -v -e '^[[:space:]]*$' -e '^[[:space:]]*#' $feature`
19+
parallelruninfile=false
20+
for tag in $featuretags; do
21+
# Only include @app_parallel_run_ tags.
22+
if [[ "$tag" =~ @app_parallel_run_ ]]; then
23+
parallelruninfile=true
24+
if [[ -n "${tags[$tag]}" ]]; then
25+
tags[$tag]=$((${tags[$tag]} + lines))
26+
else
27+
tags[$tag]="$lines"
28+
fi
29+
break
30+
fi
31+
done
32+
33+
if [ "$parallelruninfile" = false ] ; then
34+
# Invalid or missing tag in $feature
35+
parallelrunmissing=true
36+
fi
1337
done
1438

1539
# Serialize to JSON.
16-
tags_json="["
17-
18-
for tag in "${tags[@]}"
40+
tags_json=""
41+
for tag in $(printf "%s\n" "${!tags[@]}" | sort);
1942
do
43+
if [ ! -z "$debug" ]; then
44+
lines=${tags[$tag]}
45+
echo "$tag - $lines lines"
46+
fi
47+
2048
tags_json+="\"$tag\","
2149
done
2250

2351
tags_json="${tags_json%?}"
24-
tags_json+="]"
52+
53+
# If there's any invalid tags, use the negation of all other tags.
54+
negation=""
55+
if [ "$parallelrunmissing" = true ] ; then
56+
for tag in $(printf "%s\n" "${!tags[@]}" | sort);
57+
do
58+
negation+="~${tag}&&"
59+
done
60+
tags_json="${tags_json},\"${negation%??}\""
61+
fi
2562

2663
# Print to console.
27-
echo $tags_json
64+
echo "[${tags_json}]"

.github/workflows/acceptance.yml

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ jobs:
7070
run: |
7171
if [ -z $BEHAT_TAGS ]; then
7272
tags_json=`.github/scripts/print_behat_tags_json.sh`
73+
echo "Generated tags: $tags_json"
7374
echo "tags=$tags_json" >> $GITHUB_OUTPUT;
7475
else
7576
echo "tags=[\"$BEHAT_TAGS\"]" >> $GITHUB_OUTPUT;
@@ -181,24 +182,43 @@ jobs:
181182
run: moodle-plugin-ci add-config 'define("TEST_MOD_BIGBLUEBUTTONBN_MOCK_SERVER", "http://localhost:8002/hash" . sha1($CFG->wwwroot));'
182183

183184
- name: Run Behat tests
185+
id: run-behat-tests
184186
run: moodle-plugin-ci behat --auto-rerun 3 --profile chrome --tags="@app&&~@local&&$BEHAT_TAGS"
185187
env:
186188
BEHAT_TAGS: ${{ matrix.tags }}
187189
MOODLE_BEHAT_SELENIUM_IMAGE: selenium/standalone-chrome:latest
188190

191+
- name: Rename snapshot failure files
192+
id: filename
193+
if: ${{ failure() && steps.run-behat-tests.conclusion == 'failure' }}
194+
run: |
195+
PARALLEL_NAME=$(echo "${{ matrix.tags }}" | sed 's/^@app_parallel_run_//')
196+
echo "PARALLEL_NAME=$PARALLEL_NAME" >> $GITHUB_OUTPUT
197+
echo "❌ $PARALLEL_NAME failed" >> $GITHUB_STEP_SUMMARY
198+
189199
- name: Upload Snapshot failures
190200
uses: actions/upload-artifact@v4
191-
if: ${{ failure() }}
201+
if: ${{ failure() && steps.run-behat-tests.conclusion == 'failure' }}
202+
env:
203+
PARALLEL_NAME: ${{ steps.filename.outputs.PARALLEL_NAME }}
192204
with:
193-
name: snapshot_failures-${{ matrix.tags }}
205+
name: snapshot_failures-${{ env.PARALLEL_NAME }}
194206
path: moodle/public/local/moodleappbehat/tests/behat/snapshots/failures/*
207+
if-no-files-found: ignore
195208

196209
- name: Upload Behat failures
197210
uses: actions/upload-artifact@v4
198-
if: ${{ failure() }}
211+
if: ${{ failure() && steps.run-behat-tests.conclusion == 'failure' }}
212+
env:
213+
PARALLEL_NAME: ${{ steps.filename.outputs.PARALLEL_NAME }}
199214
with:
200-
name: behat_failures-${{ matrix.tags }}
215+
name: behat_failures-${{ env.PARALLEL_NAME }}
201216
path: moodledata/behat_dump/*
217+
if-no-files-found: ignore
218+
219+
- name: Mark cancelled jobs as failed.
220+
if: ${{ cancelled() }}
221+
run: exit 1
202222

203223
complete:
204224
runs-on: ubuntu-latest
@@ -214,5 +234,6 @@ jobs:
214234
rm ./artifacts/build -rf
215235
if [ -n "$(ls -A ./artifacts)" ]; then
216236
echo "There were some failures in the previous jobs"
237+
echo "### ❌ There were some failures in the previous jobs" >> $GITHUB_STEP_SUMMARY
217238
exit 1
218239
fi

.github/workflows/testing.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ jobs:
2424
result=$(cat scripts/langindex.json | grep \"TBD\" | wc -l); test $result -eq 0
2525
if [ $result -ne 0 ]; then
2626
echo "::error::There are lang strings to be decided on langindex.json"
27+
echo "❌ There are lang strings to be decided on langindex.json" >> $GITHUB_STEP_SUMMARY
2728
exit 1
2829
fi
2930
gulp
3031
langcount=`jq -r '. | length' src/assets/lang/en.json`
3132
langindexcount=`jq -r '. | length' scripts/langindex.json`
3233
if [ $langcount -ne $langindexcount ]; then
3334
echo "::error::Lang file has $langcount while langindex $langindexcount"
35+
echo "❌ Lang file has $langcount while langindex $langindexcount" >> $GITHUB_STEP_SUMMARY
3436
exit 1
3537
fi
3638
@@ -49,6 +51,7 @@ jobs:
4951
done
5052
if [ $found -ne 0 ]; then
5153
echo "::error::Found $found missing langkeys"
54+
echo "❌ Found $found missing langkeys" >> $GITHUB_STEP_SUMMARY
5255
exit 1
5356
fi
5457
- name: Run Linters (ignore warnings)
@@ -68,6 +71,7 @@ jobs:
6871
cat circular-dependencies
6972
lines=$(cat circular-dependencies | wc -l)
7073
echo "Total circular dependencies: $lines"
74+
echo "⚠️ Total circular dependencies: $lines" >> $GITHUB_STEP_SUMMARY
7175
test $lines -eq 80
7276
- name: JavaScript code compatibility
7377
run: |
@@ -80,5 +84,6 @@ jobs:
8084
# acorn is used by es-check but cannot check for this feature only, so we need to check it manually.
8185
if grep -qE '(^|[^-])\bstatic[ ]*\{' www/*.js cordova-plugin-moodleapp/www/*.js; then
8286
echo "::error::Static initialization blocks are not supported in Chrome 93 and iOS 15."
87+
echo "❌ Static initialization blocks are not supported in Chrome 93 and iOS 15." >> $GITHUB_STEP_SUMMARY
8388
exit 1
8489
fi

src/addons/block/activitymodules/tests/behat/block_activitymodules.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@addon_block_activity_modules @app @block @block_activity_modules @javascript @lms_upto5.0
1+
@app_parallel_run_blocks @addon_block_activity_modules @app @block @block_activity_modules @javascript @lms_upto5.0
22
Feature: Basic tests of activity modules block
33

44
Background:

src/addons/block/activityresults/tests/behat/block_activityresults.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@addon_block_activity_results @app @block @block_activity_results @javascript
1+
@app_parallel_run_blocks @addon_block_activity_results @app @block @block_activity_results @javascript
22
Feature: Basic tests of activity results block
33

44
Background:

src/addons/block/badges/tests/behat/block_badges.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@addon_block_badges @app @block @block_badges @javascript
1+
@app_parallel_run_badges @addon_block_badges @app @block @block_badges @javascript
22
Feature: Basic tests of badges block
33

44
Background:

src/addons/block/blogmenu/tests/behat/block_blogmenu.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@addon_block_blog_menu @app @block @block_blog_menu @javascript
1+
@app_parallel_run_blog @addon_block_blog_menu @app @block @block_blog_menu @javascript
22
Feature: Basic tests of blog menu block
33

44
Background:

src/addons/block/blogrecent/tests/behat/block_blogrecent.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@addon_block_blog_recent @app @block @block_blog_recent @javascript
1+
@app_parallel_run_blog @addon_block_blog_recent @app @block @block_blog_recent @javascript
22
Feature: Basic tests of blog recent block
33

44
Background:

src/addons/block/blogtags/tests/behat/block_blogtags.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@addon_block_blog_tags @app @block @block_blog_tags @javascript
1+
@app_parallel_run_blog @addon_block_blog_tags @app @block @block_blog_tags @javascript
22
Feature: Basic tests of blog tags block
33

44
Background:

src/addons/block/calendarmonth/tests/behat/block_calendar_month.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@addon_block_calendar_month @app @block @block_calendar_month @javascript
1+
@app_parallel_run_calendar @addon_block_calendar_month @app @block @block_calendar_month @javascript
22
Feature: View the calendar block and check it links to the calendar page
33

44
Background:

0 commit comments

Comments
 (0)