From 7fa5f12fdf2f9e3da14fad2b3be10fa15da30579 Mon Sep 17 00:00:00 2001 From: ArchBlood <35392110+ArchBlood@users.noreply.github.com> Date: Fri, 25 Oct 2024 17:04:33 -0400 Subject: [PATCH] Update php.yml Signed-off-by: ArchBlood <35392110+ArchBlood@users.noreply.github.com> --- .github/workflows/php.yml | 46 ++++++++++----------------------------- 1 file changed, 12 insertions(+), 34 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 19fa6a4..1b44d16 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -11,37 +11,8 @@ permissions: pull-requests: write jobs: - # Job for handling push events - push-build: - if: github.event_name == 'push' - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - token: ${{ secrets.GITHUB_TOKEN }} - - - name: Setup PHP - uses: shivammathur/setup-php@2.31.1 - with: - php-version: '8.2' - - - name: Cache Composer packages - id: composer-cache - uses: actions/cache@v3 - with: - path: vendor - key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-php- - - - name: Install dependencies - run: | - composer install --prefer-dist --no-progress - - # Job for handling pull request events - pr-build: - if: github.event_name == 'pull_request' + # Job to handle both push and pull request events + composer-build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -60,7 +31,9 @@ jobs: echo "Head ref: ${{ github.head_ref }}" echo "Base ref: ${{ github.base_ref }}" + # Step for fetching branch data only for pull_request events - name: Fetch branch data for pull request + if: ${{ github.event_name == 'pull_request' }} run: | git fetch origin ${{ github.event.pull_request.base.ref }} echo "Base branch for PR is: ${{ github.event.pull_request.base.ref }}" @@ -68,10 +41,12 @@ jobs: - name: Check for composer.json changes id: check-changes + if: ${{ github.event_name == 'pull_request' }} run: | git diff --name-only origin/${{ github.event.pull_request.base.ref }} HEAD | grep -q "^composer.json$" && echo "changed=true" >> $GITHUB_OUTPUT || echo "changed=false" >> $GITHUB_OUTPUT - name: Output check-changes result + if: ${{ github.event_name == 'pull_request' }} run: | echo "composer.json change detected: ${{ steps.check-changes.outputs.changed }}" @@ -84,19 +59,22 @@ jobs: restore-keys: | ${{ runner.os }}-php- + # Conditional update of dependencies if composer.json changes in PR - name: Update dependencies in PR - if: steps.check-changes.outputs.changed == 'true' + if: ${{ github.event_name == 'pull_request' && steps.check-changes.outputs.changed == 'true' }} run: | echo "Running composer update because composer.json changed" composer update --prefer-dist --no-progress + # Install dependencies for both push and pull requests if no changes to composer.json - name: Install dependencies - if: steps.check-changes.outputs.changed != 'true' + if: ${{ github.event_name == 'push' || (github.event_name == 'pull_request' && steps.check-changes.outputs.changed != 'true') }} run: | composer install --prefer-dist --no-progress + # Commit and push updated lock file if composer.json was changed in PR - name: Commit and push updated lock file - if: steps.check-changes.outputs.changed == 'true' + if: ${{ github.event_name == 'pull_request' && steps.check-changes.outputs.changed == 'true' }} run: | if git diff --exit-code composer.lock; then echo "No changes to composer.lock needed"