|
1 | | -name: Tests |
| 1 | +name: v3 Tests |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | pull_request: |
5 | | - branches: [ "main", "v3" ] |
6 | | - types: [ opened, synchronize, reopened ] |
| 5 | + branches: [ "v3" ] |
| 6 | + types: [ opened, synchronize, reopened, labeled, unlabeled ] |
7 | 7 | paths: |
8 | 8 | - 'src/**' |
9 | 9 | - 'config/**' |
|
15 | 15 |
|
16 | 16 | permissions: read-all |
17 | 17 |
|
| 18 | +concurrency: |
| 19 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number }} |
| 20 | + cancel-in-progress: true |
| 21 | + |
18 | 22 | env: |
19 | 23 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
20 | 24 |
|
@@ -103,114 +107,171 @@ jobs: |
103 | 107 | run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist |
104 | 108 |
|
105 | 109 | - name: "Run PHPUnit Tests" |
106 | | - run: SPC_LIBC=glibc vendor/bin/phpunit tests/ --no-coverage |
| 110 | + run: vendor/bin/phpunit tests/ --no-coverage |
107 | 111 |
|
108 | | - define-matrix: |
109 | | - if: false # TODO: enable when refactoring workflows |
110 | | - name: "Define Matrix" |
| 112 | + check-gate: |
| 113 | + name: "Check: need-test label" |
111 | 114 | runs-on: ubuntu-latest |
112 | 115 | outputs: |
113 | | - php: ${{ steps.gendef.outputs.php }} |
114 | | - os: ${{ steps.gendef.outputs.os }} |
| 116 | + enabled: ${{ steps.gate.outputs.enabled }} |
115 | 117 | steps: |
116 | | - - name: "Checkout" |
117 | | - uses: actions/checkout@v4 |
| 118 | + - name: Check label |
| 119 | + id: gate |
| 120 | + run: | |
| 121 | + LABELS='${{ toJSON(github.event.pull_request.labels.*.name) }}' |
| 122 | + if echo "$LABELS" | grep -q '"need-test"'; then |
| 123 | + echo "enabled=true" >> "$GITHUB_OUTPUT" |
| 124 | + else |
| 125 | + echo "enabled=false" >> "$GITHUB_OUTPUT" |
| 126 | + fi |
| 127 | +
|
| 128 | + test-bot: |
| 129 | + name: "Test Bot: analyze PR" |
| 130 | + needs: check-gate |
| 131 | + if: needs.check-gate.outputs.enabled == 'true' |
| 132 | + runs-on: ubuntu-latest |
| 133 | + permissions: |
| 134 | + pull-requests: write |
| 135 | + contents: read |
| 136 | + outputs: |
| 137 | + need_test: ${{ steps.bot.outputs.need_test }} |
| 138 | + gen_matrix_args: ${{ steps.bot.outputs.gen_matrix_args }} |
| 139 | + gen_matrix_args_tier2: ${{ steps.bot.outputs.gen_matrix_args_tier2 }} |
| 140 | + php_versions: ${{ steps.bot.outputs.php_versions }} |
| 141 | + tier2: ${{ steps.bot.outputs.tier2 }} |
| 142 | + steps: |
| 143 | + - uses: actions/checkout@v4 |
118 | 144 |
|
119 | | - - name: "Setup PHP" |
| 145 | + - name: Setup PHP |
120 | 146 | uses: shivammathur/setup-php@v2 |
121 | 147 | with: |
122 | | - php-version: 8.4 |
| 148 | + php-version: '8.4' |
123 | 149 | extensions: curl, openssl, mbstring |
| 150 | + ini-values: memory_limit=-1 |
| 151 | + tools: composer |
| 152 | + |
| 153 | + - name: Install dependencies |
| 154 | + run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist --no-dev |
124 | 155 |
|
125 | | - - name: Define |
126 | | - id: gendef |
| 156 | + - name: Run dev:test-bot |
| 157 | + id: bot |
| 158 | + env: |
| 159 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
127 | 160 | run: | |
128 | | - PHP_VERSIONS=$(php src/globals/test-extensions.php php) |
129 | | - OS_VERSIONS=$(php src/globals/test-extensions.php os) |
130 | | - echo 'php='"$PHP_VERSIONS" >> "$GITHUB_OUTPUT" |
131 | | - echo 'os='"$OS_VERSIONS" >> "$GITHUB_OUTPUT" |
| 161 | + BOT_JSON=$(php -d opcache.enable_cli=0 bin/spc dev:test-bot \ |
| 162 | + --pr=${{ github.event.pull_request.number }} \ |
| 163 | + --repo=${{ github.repository }} 2>/dev/null) |
| 164 | +
|
| 165 | + echo "need_test=$(echo "$BOT_JSON" | jq -r '.need_test')" >> "$GITHUB_OUTPUT" |
| 166 | + echo "gen_matrix_args=$(echo "$BOT_JSON" | jq -r '.gen_matrix_args')" >> "$GITHUB_OUTPUT" |
| 167 | + echo "gen_matrix_args_tier2=$(echo "$BOT_JSON" | jq -r '.gen_matrix_args_tier2')" >> "$GITHUB_OUTPUT" |
| 168 | + echo "php_versions=$(echo "$BOT_JSON" | jq -c '.php_versions')" >> "$GITHUB_OUTPUT" |
| 169 | + echo "tier2=$(echo "$BOT_JSON" | jq -r '.tier2')" >> "$GITHUB_OUTPUT" |
| 170 | +
|
| 171 | + COMMENT_BODY=$(echo "$BOT_JSON" | jq -r '.comment_body') |
| 172 | + MARKER="<!-- spc-test-bot -->" |
| 173 | +
|
| 174 | + # Find existing bot comment id |
| 175 | + EXISTING_ID=$(gh api \ |
| 176 | + repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments \ |
| 177 | + --jq "[.[] | select(.body | startswith(\"$MARKER\")) | .id] | first // empty") |
| 178 | +
|
| 179 | + if [ -n "$EXISTING_ID" ]; then |
| 180 | + gh api --method PATCH \ |
| 181 | + repos/${{ github.repository }}/issues/comments/"$EXISTING_ID" \ |
| 182 | + -f body="$COMMENT_BODY" |
| 183 | + else |
| 184 | + gh pr comment ${{ github.event.pull_request.number }} \ |
| 185 | + --repo ${{ github.repository }} \ |
| 186 | + --body "$COMMENT_BODY" |
| 187 | + fi |
| 188 | +
|
| 189 | + gen-matrix: |
| 190 | + name: "Generate test matrix" |
| 191 | + needs: test-bot |
| 192 | + if: needs.test-bot.outputs.need_test == 'true' |
| 193 | + runs-on: ubuntu-latest |
| 194 | + outputs: |
| 195 | + matrix: ${{ steps.build.outputs.matrix }} |
| 196 | + steps: |
| 197 | + - uses: actions/checkout@v4 |
132 | 198 |
|
| 199 | + - name: Setup PHP |
| 200 | + uses: shivammathur/setup-php@v2 |
| 201 | + with: |
| 202 | + php-version: '8.4' |
| 203 | + extensions: curl, openssl, mbstring |
| 204 | + ini-values: memory_limit=-1 |
| 205 | + tools: composer |
| 206 | + |
| 207 | + - name: Install dependencies |
| 208 | + run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist --no-dev |
133 | 209 |
|
134 | | - build: |
135 | | - if: false |
136 | | - name: "Build PHP Test (PHP ${{ matrix.php }} ${{ matrix.os }})" |
137 | | - runs-on: ${{ matrix.os }} |
138 | | - needs: [define-matrix, php-cs-fixer, phpstan, phpunit] |
| 210 | + - name: Build matrix |
| 211 | + id: build |
| 212 | + env: |
| 213 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 214 | + GEN_MATRIX_ARGS: ${{ needs.test-bot.outputs.gen_matrix_args }} |
| 215 | + GEN_MATRIX_ARGS_TIER2: ${{ needs.test-bot.outputs.gen_matrix_args_tier2 }} |
| 216 | + PHP_VERSIONS: ${{ needs.test-bot.outputs.php_versions }} |
| 217 | + TIER2: ${{ needs.test-bot.outputs.tier2 }} |
| 218 | + run: | |
| 219 | + # Tier1 matrix |
| 220 | + MATRIX1=$(bin/spc dev:gen-ext-test-matrix $GEN_MATRIX_ARGS 2>/dev/null) |
| 221 | +
|
| 222 | + # Merge Tier2 if requested |
| 223 | + if [ "$TIER2" = "true" ] && [ -n "$GEN_MATRIX_ARGS_TIER2" ]; then |
| 224 | + MATRIX2=$(bin/spc dev:gen-ext-test-matrix $GEN_MATRIX_ARGS_TIER2 2>/dev/null) |
| 225 | + COMBINED=$(jq -n --argjson m1 "$MATRIX1" --argjson m2 "$MATRIX2" '$m1 + $m2') |
| 226 | + else |
| 227 | + COMBINED=$MATRIX1 |
| 228 | + fi |
| 229 | +
|
| 230 | + # Expand PHP versions: cartesian product of entries × php_versions |
| 231 | + FINAL=$(echo "$COMBINED" | jq --argjson versions "$PHP_VERSIONS" \ |
| 232 | + '[.[] | . as $entry | $versions[] | $entry + {"php-version": .}]') |
| 233 | +
|
| 234 | + echo "matrix=$(echo "$FINAL" | jq -c '{"combo": .}')" >> "$GITHUB_OUTPUT" |
| 235 | +
|
| 236 | + ext-test: |
| 237 | + name: "Ext test: ${{ matrix.combo.extension }} (PHP ${{ matrix.combo.php-version }} · ${{ matrix.combo.os }}-${{ matrix.combo.arch }})" |
| 238 | + needs: gen-matrix |
| 239 | + runs-on: ${{ matrix.combo.runner }} |
139 | 240 | timeout-minutes: 120 |
140 | 241 | strategy: |
141 | | - matrix: |
142 | | - php: ${{ fromJSON(needs.define-matrix.outputs.php) }} |
143 | | - os: ${{ fromJSON(needs.define-matrix.outputs.os) }} |
144 | 242 | fail-fast: false |
| 243 | + matrix: ${{ fromJSON(needs.gen-matrix.outputs.matrix) }} |
145 | 244 | steps: |
146 | | - - name: "Update runner packages" |
147 | | - if: ${{ startsWith(matrix.os, 'ubuntu-') }} |
148 | | - run: sudo apt-get update && sudo apt-get install -y ca-certificates |
| 245 | + - uses: actions/checkout@v4 |
149 | 246 |
|
150 | | - - name: "Checkout" |
151 | | - uses: actions/checkout@v4 |
152 | | - |
153 | | - - name: "Setup PHP" |
| 247 | + - name: Setup PHP |
154 | 248 | uses: shivammathur/setup-php@v2 |
155 | 249 | with: |
156 | 250 | php-version: 8.4 |
157 | | - tools: pecl, composer |
158 | 251 | extensions: curl, openssl, mbstring |
159 | 252 | ini-values: memory_limit=-1 |
| 253 | + tools: composer |
160 | 254 | env: |
161 | 255 | phpts: nts |
162 | 256 |
|
163 | | - - name: "Cache composer packages" |
164 | | - id: composer-cache |
165 | | - uses: actions/cache@v4 |
166 | | - with: |
167 | | - path: vendor |
168 | | - key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} |
169 | | - restore-keys: | |
170 | | - ${{ runner.os }}-php- |
171 | | -
|
172 | | - # Cache downloaded source |
173 | | - - id: cache-download |
174 | | - uses: actions/cache@v4 |
175 | | - with: |
176 | | - path: downloads |
177 | | - key: php-dependencies-${{ matrix.os }} |
178 | | - |
179 | | - - name: "Install Dependencies" |
180 | | - run: composer update -vvv --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist --no-plugins |
181 | | - |
182 | | - - name: "Run Build Tests (doctor)" |
183 | | - run: php src/globals/test-extensions.php doctor_cmd ${{ matrix.os }} ${{ matrix.php }} |
184 | | - |
185 | | - - name: "Prepare UPX for Windows" |
186 | | - if: ${{ startsWith(matrix.os, 'windows-') }} |
187 | | - run: | |
188 | | - php src/globals/test-extensions.php install_upx_cmd ${{ matrix.os }} ${{ matrix.php }} |
189 | | - echo "UPX_CMD=$(php src/globals/test-extensions.php upx)" >> $env:GITHUB_ENV |
| 257 | + - name: Install dependencies |
| 258 | + run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist --no-dev |
190 | 259 |
|
191 | | - - name: "Prepare UPX for Linux" |
192 | | - if: ${{ startsWith(matrix.os, 'ubuntu-') }} |
| 260 | + - name: Build |
| 261 | + env: |
| 262 | + SPC_USE_SUDO: "yes" |
| 263 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
193 | 264 | run: | |
194 | | - php src/globals/test-extensions.php install_upx_cmd ${{ matrix.os }} ${{ matrix.php }} |
195 | | - echo "UPX_CMD=$(php src/globals/test-extensions.php upx)" >> $GITHUB_ENV |
196 | | -
|
197 | | - - name: "Run Build Tests (download)" |
198 | | - run: php src/globals/test-extensions.php download_cmd ${{ matrix.os }} ${{ matrix.php }} |
199 | | - |
200 | | - - name: "Run Build Tests (build)" |
201 | | - run: php src/globals/test-extensions.php build_cmd ${{ matrix.os }} ${{ matrix.php }} |
| 265 | + ./bin/spc doctor --auto-fix |
| 266 | + ${{ matrix.combo.build-args }} --dl-with-php=${{ matrix.combo.php-version }} |
202 | 267 |
|
203 | | - - name: "Run Build Tests (build - embed for non-windows)" |
204 | | - if: ${{ !startsWith(matrix.os, 'windows-') }} |
205 | | - run: php src/globals/test-extensions.php build_embed_cmd ${{ matrix.os }} ${{ matrix.php }} |
| 268 | +# - name: Setup upterm session |
| 269 | +# if: ${{ failure() }} |
| 270 | +# uses: owenthereal/action-upterm@v1 |
206 | 271 |
|
207 | | - - name: "Upload logs" |
208 | | - if: ${{ always() && hashFiles('log/**') != '' }} |
209 | | - uses: actions/upload-artifact@v7 |
| 272 | + - name: Upload logs |
| 273 | + if: always() && hashFiles('log/**') != '' |
| 274 | + uses: actions/upload-artifact@v4 |
210 | 275 | with: |
211 | | - name: build-logs-${{ matrix.os }}-${{ matrix.php }} |
| 276 | + name: logs-${{ matrix.combo.os }}-${{ matrix.combo.arch }}-${{ matrix.combo.extension }}-php${{ matrix.combo.php-version }} |
212 | 277 | path: log |
213 | | - |
214 | | -# - name: Setup tmate session |
215 | | -# if: ${{ failure() }} |
216 | | -# uses: mxschmitt/action-tmate@v3 |
|
0 commit comments