fixes #16: Allow a custom set of commands to be run in validate:all. #35
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: Run validation with RoboValidate | |
on: | |
# Run on any branch so validate branch can always run. | |
push: | |
# Commit message validation requires a target branch which is only available in a PR. | |
pull_request: | |
jobs: | |
validate: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- 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: Extract branch name | |
shell: bash | |
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT | |
id: extract_branch | |
- name: Get composer cache directory | |
id: composer-cache | |
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | |
- name: Cache Composer dependencies | |
uses: actions/cache@v4 | |
with: | |
path: ${{ steps.composer-cache.outputs.dir }} | |
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} | |
restore-keys: ${{ runner.os }}-composer | |
- name: Install Composer dependencies and initialize Robo | |
run: | | |
composer install --ignore-platform-reqs --optimize-autoloader --no-progress --no-ansi | |
# If a Robo command exits with a failure and a RoboFile.php does not exist | |
# a warning about 'Robo is not initialized here. Please run `robo init` to create a new RoboFile.' | |
# will be created, which might make users think that is what the error was caused by. | |
if [ ! -f "RoboFile.php" ]; then | |
vendor/bin/robo init | |
fi | |
- name: Validate a change to any branch | |
if: github.event_name == 'push' | |
run: | | |
# Initialize status variables to 0 | |
status1=0 | |
ROBO_VALIDATE_BRANCH_NAME=${{ steps.extract_branch.outputs.branch }} vendor/bin/robo validate:all non_pr | |
# Exit with a non-zero status if the command failed | |
if [ "$status1" -ne 0 ]; then | |
exit 1 | |
fi | |
- name: Validate pull requests | |
if: github.event_name == 'pull_request' | |
run: | | |
# Initialize status variables to 0 | |
status1=0 | |
ROBO_VALIDATE_TARGET_BRANCH="${{ github.base_ref }}" ROBO_VALIDATE_CURRENT_BRANCH="${{ github.head_ref }}" ./robo.sh validate:all only_pr | |
# Exit with a non-zero status if the command failed | |
if [ "$status1" -ne 0 ]; then | |
exit 1 | |
fi |