|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - 3.3.x |
| 7 | + - master |
| 8 | + - 4.0.x |
| 9 | + pull_request: |
| 10 | + |
| 11 | +jobs: |
| 12 | + lint: |
| 13 | + name: "Lint (PHP ${{ matrix.php }})" |
| 14 | + runs-on: ubuntu-22.04 |
| 15 | + strategy: |
| 16 | + fail-fast: false |
| 17 | + matrix: |
| 18 | + php: ['7.4', '8.1', '8.2', '8.3'] |
| 19 | + |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v6 |
| 22 | + |
| 23 | + - uses: shivammathur/setup-php@v2 |
| 24 | + with: |
| 25 | + php-version: ${{ matrix.php }} |
| 26 | + coverage: none |
| 27 | + |
| 28 | + - name: Syntax check |
| 29 | + run: | |
| 30 | + find . -name '*.php' \ |
| 31 | + -not -path './vendor/*' \ |
| 32 | + -not -path './includes/library/*' \ |
| 33 | + -not -path './composer_packages/*' \ |
| 34 | + -print0 | xargs -0 -n1 -P4 php -l > /dev/null |
| 35 | +
|
| 36 | + coding-standards: |
| 37 | + name: Coding standards (changed files) |
| 38 | + runs-on: ubuntu-22.04 |
| 39 | + if: github.event_name == 'pull_request' |
| 40 | + |
| 41 | + steps: |
| 42 | + - uses: actions/checkout@v6 |
| 43 | + with: |
| 44 | + fetch-depth: 0 |
| 45 | + |
| 46 | + - uses: shivammathur/setup-php@v2 |
| 47 | + with: |
| 48 | + php-version: '8.3' |
| 49 | + coverage: none |
| 50 | + tools: cs2pr |
| 51 | + |
| 52 | + - name: Fetch the phpBB coding standard |
| 53 | + run: | |
| 54 | + git clone --depth 1 --branch 3.3.x --filter=blob:none --sparse \ |
| 55 | + https://github.com/phpbb/phpbb.git "$RUNNER_TEMP/phpbb" |
| 56 | + git -C "$RUNNER_TEMP/phpbb" sparse-checkout set build/code_sniffer |
| 57 | +
|
| 58 | + - name: Install PHP_CodeSniffer and phpcs-changed |
| 59 | + run: | |
| 60 | + composer --working-dir="$RUNNER_TEMP" require --no-interaction \ |
| 61 | + squizlabs/php_codesniffer:^3.7 \ |
| 62 | + sirbrillig/phpcs-changed:^2.11 |
| 63 | +
|
| 64 | + - name: Check lines changed by this pull request |
| 65 | + run: | |
| 66 | + git fetch --no-tags origin "$GITHUB_BASE_REF" |
| 67 | + mapfile -t files < <(git diff --name-only --diff-filter=ACMR "origin/$GITHUB_BASE_REF"...HEAD -- '*.php' \ |
| 68 | + | grep -vE '^(vendor|includes/library|composer_packages)/' || true) |
| 69 | +
|
| 70 | + if [ "${#files[@]}" -eq 0 ]; then |
| 71 | + echo "No PHP files changed." |
| 72 | + exit 0 |
| 73 | + fi |
| 74 | +
|
| 75 | + printf '%s\n' "${files[@]}" |
| 76 | + # Only report violations this pull request introduces. Running the ruleset |
| 77 | + # over whole files would fail on the 175 pre-existing errors any time a |
| 78 | + # legacy file is touched, which would make the check useless. |
| 79 | + "$RUNNER_TEMP/vendor/bin/phpcs-changed" \ |
| 80 | + --git --git-base "origin/$GITHUB_BASE_REF" \ |
| 81 | + --phpcs-path "$RUNNER_TEMP/vendor/bin/phpcs" \ |
| 82 | + --standard "$RUNNER_TEMP/phpbb/build/code_sniffer/ruleset-php-extensions.xml" \ |
| 83 | + --report checkstyle "${files[@]}" | tee phpcs.xml |
| 84 | + exit "${PIPESTATUS[0]}" |
| 85 | +
|
| 86 | + - name: Annotate the pull request |
| 87 | + if: ${{ failure() }} |
| 88 | + run: cs2pr phpcs.xml |
| 89 | + |
| 90 | + composer: |
| 91 | + name: Validate composer.json |
| 92 | + runs-on: ubuntu-22.04 |
| 93 | + |
| 94 | + steps: |
| 95 | + - uses: actions/checkout@v6 |
| 96 | + |
| 97 | + - uses: shivammathur/setup-php@v2 |
| 98 | + with: |
| 99 | + php-version: '7.4' |
| 100 | + coverage: none |
| 101 | + |
| 102 | + - name: Validate |
| 103 | + run: composer validate --no-check-all --no-check-publish |
0 commit comments