Merge pull request #38 from GreenMeteor/dependabot/composer/composer/… #170
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: PHP Composer | |
on: | |
push: | |
branches: ["main", "develop"] | |
pull_request: | |
branches: ["main", "develop"] | |
permissions: | |
contents: write | |
pull-requests: write | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.pull_request.head.ref }} | |
fetch-depth: 0 | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Setup PHP | |
uses: shivammathur/[email protected] | |
with: | |
php-version: '8.2' | |
- name: Validate composer files | |
id: validate | |
run: | | |
if ! composer validate --strict; then | |
echo "needs_update=true" >> $GITHUB_OUTPUT | |
else | |
echo "needs_update=false" >> $GITHUB_OUTPUT | |
fi | |
- name: Cache Composer packages | |
if: github.event_name == 'pull_request' | |
id: composer-cache | |
uses: actions/cache@v4 | |
with: | |
path: vendor | |
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} | |
restore-keys: | | |
${{ runner.os }}-php- | |
- name: Update dependencies | |
if: steps.validate.outputs.needs_update == 'true' && github.event_name == 'pull_request' | |
run: | | |
rm -f composer.lock | |
composer update --prefer-dist --no-progress | |
- name: Install dependencies | |
if: steps.validate.outputs.needs_update != 'true' | |
run: composer install --prefer-dist --no-progress | |
- name: Commit and push if lock file was updated | |
if: steps.validate.outputs.needs_update == 'true' && github.event_name == 'pull_request' | |
run: | | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
git add composer.lock vendor/ | |
git commit -m "Update composer.lock to match composer.json changes" | |
git push |