-
Notifications
You must be signed in to change notification settings - Fork 8
97 lines (84 loc) · 2.83 KB
/
Copy pathphp-test.yml
File metadata and controls
97 lines (84 loc) · 2.83 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
# SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
# SPDX-License-Identifier: AGPL-3.0-or-later
name: Test PHP tools
on:
push:
branches:
- master
paths:
- '**.php'
- '**/composer.json'
- '**/composer.lock'
- '.github/workflows/php-test.yml'
pull_request:
paths:
- '**.php'
- '**/composer.json'
- '**/composer.lock'
- '.github/workflows/php-test.yml'
permissions:
contents: read
concurrency:
group: php-test-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
# Discover every PHP tool (any directory with a composer.json) so new tools
# are picked up automatically without touching this workflow.
discover:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.find.outputs.matrix }}
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Find composer projects
id: find
run: |
dirs=$(find . -mindepth 2 -maxdepth 2 -name composer.json -not -path '*/vendor/*' \
-printf '%h\n' | sed 's#^\./##' | sort -u | jq -R . | jq -sc .)
echo "matrix=$dirs" >> "$GITHUB_OUTPUT"
echo "Discovered: $dirs"
test:
needs: discover
if: needs.discover.outputs.matrix != '[]'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
dir: ${{ fromJson(needs.discover.outputs.matrix) }}
defaults:
run:
working-directory: ${{ matrix.dir }}
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
# Matches the PHP version used by the release changelog workflow.
- name: Set up PHP
uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # v2.37.2
with:
php-version: '8.4'
coverage: none
- name: Install dependencies
run: composer install --no-progress
- name: Lint PHP files
run: find . -path ./vendor -prune -o -name '*.php' -print0 | xargs -0 -n1 php -l
# Runs the test suite only for tools that define a "test" composer script.
- name: Run tests
run: |
if composer run-script --list 2>/dev/null | grep -qE '^\s*test\b'; then
composer test
else
echo "No 'test' script in ${{ matrix.dir }}/composer.json, skipping."
fi
# Single fixed-name check that aggregates the dynamic matrix, so branch
# protection can require one status regardless of how many tools exist.
summary:
permissions:
contents: none
runs-on: ubuntu-latest
needs: [discover, test]
if: always()
name: php-test-summary
steps:
- name: Summary status
run: if ${{ needs.test.result != 'success' && needs.test.result != 'skipped' }}; then exit 1; fi