diff --git a/.github/workflows/composer.yml b/.github/workflows/composer.yml new file mode 100644 index 00000000..d158f59c --- /dev/null +++ b/.github/workflows/composer.yml @@ -0,0 +1,60 @@ +name: Composer + +on: + push: + branches: + - main + pull_request: + # New advisories are published without anything changing here, so check every Monday as well. + schedule: + - cron: '20 5 * * 1' + workflow_dispatch: + +permissions: + contents: read + +# A new push to a pull request cancels the run still going for the old one. Each commit on main gets a +# group of its own, so every one of them is checked. +concurrency: + group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.ref || github.sha }} + cancel-in-progress: true + +# Both jobs read composer.json and composer.lock only. They install nothing and need no plugin licence +# credentials, so they work the same for pull requests from forks. They're separate jobs so that the +# branch ruleset can require composer-validate without also requiring composer-audit. +jobs: + composer-validate: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v7 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.4' + coverage: none + + # Fails when composer.json is invalid, or when composer.lock doesn't match it, which happens when + # composer.json is edited by hand without running composer update. Run that command locally to fix it. + - name: Validate composer.json and composer.lock + run: composer validate --strict + + composer-audit: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v7 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.4' + coverage: none + + # Fails when a locked package has a known security advisory. Abandoned packages are listed in the + # output but don't fail the check, because replacing one is rarely urgent. + - name: Check dependencies for security advisories + run: composer audit --locked --abandoned=report