Skip to content

Commit

Permalink
Merge pull request #88 from wp-cli/matrix-file-exists
Browse files Browse the repository at this point in the history
Do not run matrix if required files do not exist
  • Loading branch information
swissspidy authored Nov 4, 2023
2 parents 5e9bfbb + 94d2ed6 commit 55610bd
Showing 1 changed file with 37 additions and 28 deletions.
65 changes: 37 additions & 28 deletions .github/workflows/reusable-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,26 @@ jobs:
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Check out source code
uses: actions/checkout@v4

- name: Check existence of composer.json & phpunit.xml.dist files
id: check_files
uses: andstor/file-existence-action@v2
with:
files: "composer.json, phpunit.xml.dist"

- name: Set matrix
id: set-matrix
run: echo "matrix=$(jq -c '.include |= map(with_entries(select(.key == "php"))) | .include |= map(select(.php >= "${{ inputs.minimum-php }}"))' <<< $BASE_MATRIX)" >> $GITHUB_OUTPUT
run: |
if [[ $FILE_EXISTS == 'true' ]]; then
echo "matrix=$(jq -c '.include |= map(with_entries(select(.key == "php"))) | .include |= map(select(.php >= "${{ inputs.minimum-php }}"))' <<< $BASE_MATRIX)" >> $GITHUB_OUTPUT
else
echo "matrix={}" >> $GITHUB_OUTPUT
fi
env:
BASE_MATRIX: ${{ needs.get-matrix.outputs.matrix }}
FILE_EXISTS: ${{ steps.check_files.outputs.files_exists == 'true' }}

unit: #-----------------------------------------------------------------------
name: Unit test / PHP ${{ matrix.php }}
Expand All @@ -211,14 +226,8 @@ jobs:
- name: Check out source code
uses: actions/checkout@v4

- name: Check existence of composer.json file
id: check_files
uses: andstor/file-existence-action@v2
with:
files: "composer.json, phpunit.xml.dist"

- name: Set up PHP environment (PHP 5.6 - 7.1)
if: ${{ matrix.php < '7.2' && steps.check_files.outputs.files_exists == 'true'}}
if: ${{ matrix.php < '7.2' }}
uses: shivammathur/setup-php@v2
with:
php-version: '${{ matrix.php }}'
Expand All @@ -229,7 +238,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Set up PHP environment (PHP 7.2+)
if: ${{ matrix.php >= '7.2' && steps.check_files.outputs.files_exists == 'true'}}
if: ${{ matrix.php >= '7.2' }}
uses: shivammathur/setup-php@v2
with:
php-version: '${{ matrix.php }}'
Expand All @@ -239,7 +248,6 @@ jobs:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install Composer dependencies & cache dependencies
if: ${{ steps.check_files.outputs.files_exists == 'true' }}
uses: "ramsey/composer-install@v2"
env:
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
Expand All @@ -248,11 +256,9 @@ jobs:
custom-cache-suffix: $(date -u "+%Y-%m")

- name: Setup problem matcher to provide annotations for PHPUnit
if: ${{ steps.check_files.outputs.files_exists == 'true' }}
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Run PHPUnit
if: ${{ steps.check_files.outputs.files_exists == 'true' }}
run: composer phpunit

prepare-functional: #---------------------------------------------------------
Expand All @@ -262,11 +268,26 @@ jobs:
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Check out source code
uses: actions/checkout@v4

- name: Check existence of composer.json & behat.yml files
id: check_files
uses: andstor/file-existence-action@v2
with:
files: "composer.json, behat.yml"

- name: Set matrix
id: set-matrix
run: echo "matrix=$(jq -c '.include |= map(select(.php >= "${{ inputs.minimum-php }}"))' <<< $BASE_MATRIX)" >> $GITHUB_OUTPUT
run: |
if [[ $FILE_EXISTS == 'true' ]]; then
echo "matrix=$(jq -c '.include |= map(select(.php >= "${{ inputs.minimum-php }}"))' <<< $BASE_MATRIX)" >> $GITHUB_OUTPUT
else
echo "matrix={}" >> $GITHUB_OUTPUT
fi
env:
BASE_MATRIX: ${{ needs.get-matrix.outputs.matrix }}
FILE_EXISTS: ${{ steps.check_files.outputs.files_exists == 'true' }}

functional: #-----------------------------------------------------------------
name: Functional - WP ${{ matrix.wp }} on PHP ${{ matrix.php }} with ${{ matrix.dbtype != 'sqlite' && format('MySQL {0}', matrix.mysql) || 'SQLite' }}
Expand All @@ -290,20 +311,12 @@ jobs:
- name: Check out source code
uses: actions/checkout@v4

- name: Check existence of composer.json & behat.yml files
id: check_files
uses: andstor/file-existence-action@v2
with:
files: "composer.json, behat.yml"

- name: Install Ghostscript
if: ${{ steps.check_files.outputs.files_exists == 'true' }}
run: |
sudo apt-get update
sudo apt-get install ghostscript -y
- name: Set up PHP environment
if: ${{ steps.check_files.outputs.files_exists == 'true' }}
uses: shivammathur/setup-php@v2
with:
php-version: '${{ matrix.php }}'
Expand All @@ -314,12 +327,10 @@ jobs:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Change ImageMagick policy to allow pdf->png conversion.
if: ${{ steps.check_files.outputs.files_exists == 'true' }}
run: |
sudo sed -i 's/^.*policy.*coder.*none.*PDF.*//' /etc/ImageMagick-6/policy.xml
- name: Install Composer dependencies & cache dependencies
if: ${{ steps.check_files.outputs.files_exists == 'true' }}
uses: "ramsey/composer-install@v2"
env:
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
Expand All @@ -328,11 +339,11 @@ jobs:
custom-cache-suffix: $(date -u "+%Y-%m")

- name: Start MySQL server
if: ${{ matrix.dbtype != 'sqlite' && steps.check_files.outputs.files_exists == 'true' }}
if: ${{ matrix.dbtype != 'sqlite' }}
run: sudo systemctl start mysql

- name: Configure DB environment
if: ${{ matrix.dbtype != 'sqlite' && steps.check_files.outputs.files_exists == 'true' }}
if: ${{ matrix.dbtype != 'sqlite' }}
run: |
echo "MYSQL_HOST=127.0.0.1" >> $GITHUB_ENV
echo "MYSQL_TCP_PORT=${{ job.services.mysql.ports['3306'] }}" >> $GITHUB_ENV
Expand All @@ -344,18 +355,16 @@ jobs:
echo "WP_CLI_TEST_DBHOST=127.0.0.1:${{ job.services.mysql.ports['3306'] }}" >> $GITHUB_ENV
- name: Prepare test database
if: ${{ matrix.dbtype != 'sqlite' && steps.check_files.outputs.files_exists == 'true' }}
if: ${{ matrix.dbtype != 'sqlite' }}
run: composer prepare-tests

- name: Check Behat environment
if: ${{ steps.check_files.outputs.files_exists == 'true' }}
env:
WP_VERSION: '${{ matrix.wp }}'
WP_CLI_TEST_DBTYPE: ${{ matrix.dbtype || 'mysql' }}
run: WP_CLI_TEST_DEBUG_BEHAT_ENV=1 composer behat

- name: Run Behat
if: ${{ steps.check_files.outputs.files_exists == 'true' }}
env:
WP_VERSION: '${{ matrix.wp }}'
WP_CLI_TEST_DBTYPE: ${{ matrix.dbtype || 'mysql' }}
Expand Down

0 comments on commit 55610bd

Please sign in to comment.