AutorÃa | Ultima modificación | Ver Log |
name: One by One Testing# Run all the individual unit tests one by one, with# fully independent PHPUnit executions. Useful to# detect issues with some tests that are using stuff# that has been made available by others, but is not# available when running individually.## Note that we aren't using PHPUnit's own isolation# here but completely separated runs, one for each# test.## The workflow will fail reporting all the tests# that have failed (and will pass if no failure is# detected, of course).## It's only executed via workflow dispatch (automated# or manual), not by push/tag. And acceptd configuration# of phpunit, specially useful to run it with PHPUnit's# own isolation or any other option.on:workflow_dispatch:inputs:phpunit_extra_options:description: Additional options to apply to PHPUnitrequired: falsedefault: ''env:chunks: 7jobs:collect:name: Collect individual unit testsruns-on: ubuntu-latestoutputs:matrix: ${{steps.individual-tests.outputs.matrix }}steps:- name: Checking out codeuses: actions/checkout@v4- name: Looking for all individual testsid: individual-testsrun: |count=0 # Number of individual tests found.while read -r testfile; do # For each test file.while read -r testname; do # For each unit test in a file.count=$((count + 1))# Sent it to the correct chunk file.chunk=$(((($count % $chunks)) + 1))echo "$testname $testfile" >> ./chunk_$chunk.txtdone < <(grep "function test_" "${testfile}" | sed -r "s/^.*function (test_[a-zA-Z0-9_]+).*/\1/")done < <(find . -name "*_test.php")# Generate the matrix to run tests.echo "matrix=$(ls -1 chunk_*.txt | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUTecho "$count individual tests collected in $chunks files"- name: Upload individual tests filesuses: actions/upload-artifact@v4with:name: individual_testspath: chunk_*.txtretention-days: 1test:name: Run testsneeds: collectruns-on: ubuntu-latestservices:exttests:image: moodlehq/moodle-exttestsports:- 8080:80redis:image: redisports:- 6379:6379strategy:fail-fast: falsematrix:file: ${{ fromJson(needs.collect.outputs.matrix) }}steps:- name: Setting up DB pgsqluses: m4nu56/postgresql-action@v1with:postgresql version: 14postgresql db: testpostgresql user: testpostgresql password: test- name: Setting up PHPuses: shivammathur/setup-php@v2with:php-version: 8.4ini-values: max_input_vars=5000coverage: none- name: Checking out codeuses: actions/checkout@v4- name: Download individual test filesuses: actions/download-artifact@v4with:name: individual_tests # Make all the chunk files available for the next steps.- name: Setting up PHPUnitenv:dbtype: pgsqlrun: |echo "pathtophp=$(which php)" >> $GITHUB_ENVcp .github/workflows/config-template.php config.phpmkdir ../moodledatasudo locale-gen en_AU.UTF-8php admin/tool/phpunit/cli/init.php --no-composer-self-update- name: Run PHPUnit test (one by one)env:dbtype: pgsqlrun: |status=0count=0while read -r line; do # For each line in the chunk filecount=$((count + 1))filter="${line% *}"file="${line#* }"# Run the individual unit test and report problems if needed to.if ! php vendor/bin/phpunit \--fail-on-empty-test-suite \--fail-on-warning \--fail-on-risky \--filter "$filter" ${{ inputs.phpunit_extra_options }} \"$file" >/dev/null 2>&1; thenif [ $status -eq 0 ]; thenecho "Problems found, list of PHPUnit commands failing:"fiecho "vendor/bin/phpunit --filter '${filter}' ${{ inputs.phpunit_extra_options }} $file"status=$((status + 1))fidone < ${{ matrix.file }}echo "Finished: $count individual tests executed, $status tests failed"exit $status