Skip to content

Commit

Permalink
fixes #13: Use setup-php instead of composer action so that PHP versi…
Browse files Browse the repository at this point in the history
…on can be specified. Fixed spacing / tabs issue. Make sure to set the target branch for PRs.
  • Loading branch information
mattsqd committed Jul 31, 2024
1 parent d2e2790 commit f73c1cf
Showing 1 changed file with 44 additions and 38 deletions.
82 changes: 44 additions & 38 deletions .github/workflows/validate-feature-branches.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
name: Validate Feature Branches

on:
# Run on any branch so validate branch can always run.
push:
branches:
- 'feature/*'
pull_request:
branches:
- 'feature/*'
Expand All @@ -13,41 +12,48 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }

- name: Install Composer dependencies
uses: php-actions/composer@v6
with:
php_version: "8.3"
version: "2"
args: "--ignore-platform-reqs --optimize-autoloader"

- name: Run on feature branches
if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/feature/')
run: |
# Initialize status variables to 0
status1=0
status2=0
status3=0
php --version
# Run all commands and capture their exit statuses
vendor/bin/robo validate:branch-name || status1=$? || status1=0
vendor/bin/robo validate:composer-lock || status3=$? || status3=0
vendor/bin/robo validate:coding-standards || status2=$? || status2=0
# Exit with a non-zero status if any command failed
if [ "$status1" -ne 0 ] || [ "$status2" -ne 0 ] || [ "$status3" -ne 0 ]; then
- name: Checkout code
uses: actions/checkout@v4

- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: /tmp/composer-cache
# This project doesn't commit composer.lock, use composer.lock instead if you do.
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
tools: composer:v2
# https://github.com/shivammathur/setup-php?tab=readme-ov-file#disable-coverage
coverage: none

- name: Install Composer dependencies
run: |
composer install --ignore-platform-reqs --optimize-autoloader
- name: Run on a change to any branch
if: github.event_name == 'push'
run: |
# Initialize status variables to 0
status1=0
status2=0
status3=0
php --version
# Run all commands and capture their exit statuses
vendor/bin/robo validate:branch-name || status1=$? || status1=0
vendor/bin/robo validate:composer-lock || status3=$? || status3=0
vendor/bin/robo validate:coding-standards || status2=$? || status2=0
# Exit with a non-zero status if any command failed
if [ "$status1" -ne 0 ] || [ "$status2" -ne 0 ] || [ "$status3" -ne 0 ]; then
exit 1
fi
fi
- name: Run on pull requests
if: github.event_name == 'pull_request' && startsWith(github.head_ref, 'feature/')
run: |
vendor/bin/robo validate:commit-messages
- name: Run on pull requests
if: github.event_name == 'pull_request'
run: |
vendor/bin/robo validate:commit-messages --target-branch="${{ github.base_ref }}"

0 comments on commit f73c1cf

Please sign in to comment.