Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 37 additions & 11 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@ name: "CI"

on:
pull_request:
paths:
- "**.php"
- "bin/posthog"
- "composer.json"
- "composer.lock"
- "phpcs.xml"
- "phpunit.xml"
- "api/public-api.json"
- "scripts/**"
- ".github/workflows/php.yml"
push:
branches:
- main
Expand All @@ -26,26 +16,43 @@ on:
- "scripts/**"
- ".github/workflows/php.yml"

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
detect-markdown-only:
uses: PostHog/.github/.github/workflows/detect-markdown-only.yml@ec25337d9fae0100622cbfea1bd5bd88284ac10b
permissions:
pull-requests: read

composer-validate:
needs: detect-markdown-only
runs-on: ubuntu-latest
steps:
- name: Complete markdown-only PR check
if: needs.detect-markdown-only.outputs.markdown_only == 'true'
run: echo "Only Markdown files changed; no additional work is required for this check."
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
if: needs.detect-markdown-only.outputs.markdown_only != 'true'

- name: Set up PHP
if: needs.detect-markdown-only.outputs.markdown_only != 'true'
uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # v2.37.0
with:
php-version: 8.4
tools: composer

- name: Validate composer files
if: needs.detect-markdown-only.outputs.markdown_only != 'true'
run: composer validate --no-check-lock --no-check-version --strict

public-api:
needs: detect-markdown-only
if: needs.detect-markdown-only.outputs.markdown_only != 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
Expand All @@ -63,29 +70,40 @@ jobs:
run: composer api:check

phpunit:
needs: detect-markdown-only
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-version: [8.2, 8.3, 8.4, 8.5]
steps:
- name: Complete markdown-only PR check
if: needs.detect-markdown-only.outputs.markdown_only == 'true'
run: echo "Only Markdown files changed; no additional work is required for this check."
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
if: needs.detect-markdown-only.outputs.markdown_only != 'true'

- name: Set up PHP ${{ matrix.php-version }}
if: needs.detect-markdown-only.outputs.markdown_only != 'true'
uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # v2.37.0
with:
php-version: ${{ matrix.php-version }}
tools: composer, phpunit

- name: Install Dependencies
if: needs.detect-markdown-only.outputs.markdown_only != 'true'
run: composer install --prefer-dist --no-progress

- name: Run PHPUnit Tests
if: needs.detect-markdown-only.outputs.markdown_only != 'true'
run: ./vendor/bin/phpunit --bootstrap vendor/autoload.php --configuration phpunit.xml

coverage:
runs-on: ubuntu-latest
needs: phpunit
needs:
- detect-markdown-only
- phpunit
if: needs.detect-markdown-only.outputs.markdown_only != 'true'
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

Expand All @@ -103,22 +121,29 @@ jobs:
run: XDEBUG_MODE=coverage ./vendor/bin/phpunit --bootstrap vendor/autoload.php --configuration phpunit.xml --coverage-text

phpcs:
needs: detect-markdown-only
runs-on: ubuntu-latest
steps:
- name: Complete markdown-only PR check
if: needs.detect-markdown-only.outputs.markdown_only == 'true'
run: echo "Only Markdown files changed; no additional work is required for this check."
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
if: needs.detect-markdown-only.outputs.markdown_only != 'true'
with:
fetch-depth: 0 # important!

# we may use whatever way to install phpcs, just specify the path on the next step
# however, curl seems to be the fastest
- name: Install PHP_CodeSniffer
if: needs.detect-markdown-only.outputs.markdown_only != 'true'
run: |
curl -OL https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar
curl -OL https://squizlabs.github.io/PHP_CodeSniffer/phpcbf.phar
php phpcs.phar --version
php phpcbf.phar --version

- name: Check PHP formatting
if: needs.detect-markdown-only.outputs.markdown_only != 'true'
run: |
php phpcbf.phar --standard=phpcs.xml --no-colors || phpcbf_status=$?
if [ "${phpcbf_status:-0}" -gt 1 ]; then
Expand All @@ -127,6 +152,7 @@ jobs:
git diff --exit-code -- lib test

- uses: tinovyatkin/action-php-codesniffer@0043b33b3629611c37e8bc7ee8a4e061dc9a7ea2 # v1
if: needs.detect-markdown-only.outputs.markdown_only != 'true'
with:
files: "**.php" # you may customize glob as needed
phpcs_path: php phpcs.phar
Expand Down
Loading