Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 1
name: One by One Testing
2
# Run all the individual unit tests one by one, with
3
# fully independent PHPUnit executions. Useful to
4
# detect issues with some tests that are using stuff
5
# that has been made available by others, but is not
6
# available when running individually.
7
#
8
# Note that we aren't using PHPUnit's own isolation
9
# here but completely separated runs, one for each
10
# test.
11
#
12
# The workflow will fail reporting all the tests
13
# that have failed (and will pass if no failure is
14
# detected, of course).
15
#
16
# It's only executed via workflow dispatch (automated
17
# or manual), not by push/tag. And acceptd configuration
18
# of phpunit, specially useful to run it with PHPUnit's
19
# own isolation or any other option.
20
 
21
on:
22
  workflow_dispatch:
23
    inputs:
24
      phpunit_extra_options:
25
        description: Additional options to apply to PHPUnit
26
        required: false
27
        default: ''
28
 
29
env:
30
  chunks: 7
31
 
32
jobs:
33
  collect:
34
    name: Collect individual unit tests
35
    runs-on: ubuntu-latest
36
    outputs:
37
      matrix: ${{steps.individual-tests.outputs.matrix }}
38
 
39
    steps:
40
      - name: Checking out code
41
        uses: actions/checkout@v4
42
 
43
      - name: Looking for all individual tests
44
        id: individual-tests
45
        run: |
46
          count=0  # Number of individual tests found.
47
          while read -r testfile; do # For each test file.
48
              while read -r testname; do # For each unit test in a file.
49
                  count=$((count + 1))
50
                  # Sent it to the correct chunk file.
51
                  chunk=$(((($count % $chunks)) + 1))
52
                  echo "$testname $testfile" >> ./chunk_$chunk.txt
53
              done < <(grep "function test_" "${testfile}" | sed -r "s/^.*function (test_[a-zA-Z0-9_]+).*/\1/")
54
          done < <(find . -name "*_test.php")
55
          # Generate the matrix to run tests.
56
          echo "matrix=$(ls -1 chunk_*.txt | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT
57
          echo "$count individual tests collected in $chunks files"
58
 
59
      - name: Upload individual tests files
60
        uses: actions/upload-artifact@v4
61
        with:
62
          name: individual_tests
63
          path: chunk_*.txt
64
          retention-days: 1
65
 
66
  test:
67
    name: Run tests
68
    needs: collect
69
    runs-on: ubuntu-latest
70
    services:
71
      exttests:
72
        image: moodlehq/moodle-exttests
73
        ports:
74
          - 8080:80
75
      redis:
76
        image: redis
77
        ports:
78
          - 6379:6379
79
    strategy:
80
      fail-fast: false
81
      matrix:
82
        file: ${{ fromJson(needs.collect.outputs.matrix) }}
83
 
84
    steps:
85
      - name: Setting up DB pgsql
86
        uses: m4nu56/postgresql-action@v1
87
        with:
88
          postgresql version: 14
89
          postgresql db: test
90
          postgresql user: test
91
          postgresql password: test
92
 
93
      - name: Setting up PHP
94
        uses: shivammathur/setup-php@v2
95
        with:
96
          php-version: 8.4
97
          ini-values: max_input_vars=5000
98
          coverage: none
99
 
100
      - name: Checking out code
101
        uses: actions/checkout@v4
102
 
103
      - name: Download individual test files
104
        uses: actions/download-artifact@v4
105
        with:
106
          name: individual_tests # Make all the chunk files available for the next steps.
107
 
108
      - name: Setting up PHPUnit
109
        env:
110
          dbtype: pgsql
111
        run: |
112
          echo "pathtophp=$(which php)" >> $GITHUB_ENV
113
          cp .github/workflows/config-template.php config.php
114
          mkdir ../moodledata
115
          sudo locale-gen en_AU.UTF-8
116
          php admin/tool/phpunit/cli/init.php --no-composer-self-update
117
 
118
      - name: Run PHPUnit test (one by one)
119
        env:
120
          dbtype: pgsql
121
        run: |
122
          status=0
123
          count=0
124
          while read -r line; do # For each line in the chunk file
125
              count=$((count + 1))
126
              filter="${line% *}"
127
              file="${line#* }"
128
              # Run the individual unit test and report problems if needed to.
129
              if ! php vendor/bin/phpunit \
130
                      --fail-on-empty-test-suite \
131
                      --fail-on-warning \
132
                      --fail-on-risky \
133
                      --filter "$filter" ${{ inputs.phpunit_extra_options }} \
134
                      "$file" >/dev/null 2>&1; then
135
                  if [ $status -eq 0 ]; then
136
                      echo "Problems found, list of PHPUnit commands failing:"
137
                  fi
138
                  echo "vendor/bin/phpunit --filter '${filter}' ${{ inputs.phpunit_extra_options }} $file"
139
                  status=$((status + 1))
140
              fi
141
          done < ${{ matrix.file }}
142
          echo "Finished: $count individual tests executed, $status tests failed"
143
          exit $status