Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
97 changes: 97 additions & 0 deletions .github/workflows/php-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,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@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- 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@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

# Matches the PHP version used by the release changelog workflow.
- name: Set up PHP
uses: shivammathur/setup-php@0f7f1d08e3e32076e51cae65eb0b0c871405b16e # v2.34.1
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
vendor
credentials.json
.DS_Store
milestone_move_progress.json
milestone_move_progress.json
.phpunit.result.cache
6 changes: 6 additions & 0 deletions changelog/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,11 @@
"symfony/console": "^8.1",
"knplabs/github-api": "^3.16",
"guzzlehttp/guzzle": "^7.13"
},
"require-dev": {
"phpunit/phpunit": "^11.5"
},
"scripts": {
"test": "phpunit"
}
}
Loading
Loading