Skip to content

Commit

Permalink
Update PHP reusable workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
admdly committed Dec 4, 2023
1 parent cf80237 commit 0a5d7aa
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 77 deletions.
54 changes: 33 additions & 21 deletions .github/workflows/php-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,62 +3,74 @@ name: PHP Build and Archive
on:
workflow_call:
inputs:
cache-deps:
description: 'Whether to cache composer dependencies'
cache_deps:
description: 'Whether to cache composer dependencies.'
default: true
required: false
type: boolean
php-versions:
description: 'The PHP versions to create builds for (as JSON string array)'
composer_args:
description: 'The arguments to pass to composer when installing dependencies.'
default: ''
required: false
type: string
php_versions:
description: 'The PHP versions to create builds for (as JSON string array).'
default: '["latest"]'
required: false
type: string
upload-artifact:
description: 'Whether to upload the build archive for reuse (filename format e.g. build-archive-php8.1)'
upload_artifact:
description: 'Whether to upload the build archive(s) as artifact(s).'
default: true
required: false
type: boolean
upload_artifact_prefix:
description: >
'The artifact name prefix to use when uploading artifacts, if enabled (the
final artifact name(s) will be a concatenation of prefix and PHP version(s)).'
default: 'build-archive-php'
required: false
type: string

jobs:
build:
name: 'PHP ${{ matrix.php }}'
runs-on: ubuntu-latest
strategy:
matrix:
php: ${{ fromJSON(inputs.php-versions) }}

name: 'PHP ${{ matrix.php }}'
php: ${{ fromJSON(inputs.php_versions) }}
steps:
- uses: actions/checkout@v4

- name: Validate composer.json and composer.lock
- name: 'Validate composer.json and composer.lock'
uses: php-actions/composer@v6
with:
command: validate
php_version: ${{ matrix.php }}

- name: Cache Composer Dependencies
if: ${{ inputs.cache-deps }}
- name: 'Cache Composer Dependencies'
id: composer-cache
if: ${{ inputs.cache_deps }}
uses: actions/cache@v3
with:
path: ./src/vendor
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
path: './src/vendor'

- name: Install Composer Dependencies
- name: 'Install Composer Dependencies'
if: ${{ steps.composer-cache.outputs.cache-hit != 'true' }}
uses: php-actions/composer@v6
with:
args: ${{ inputs.composer_args }}
php_version: ${{ matrix.php }}

- name: Create Build Archive
- name: 'Create Build Archive'
run: |
mkdir /tmp/builds/ && tar -cvf /tmp/builds/build.tar ./
- name: Upload Build Archive
if: ${{ inputs.upload-artifact }}
- name: 'Upload Build Archive'
if: ${{ inputs.upload_artifact }}
uses: actions/upload-artifact@v3
with:
name: build-archive-php${{ matrix.php }}
path: /tmp/builds
if-no-files-found: 'error'
name: '${{ inputs.upload_artifact_prefix }}-${{ matrix.php }}'
path: '/tmp/builds'
retention-days: 1
107 changes: 51 additions & 56 deletions .github/workflows/php-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,123 +3,118 @@ name: PHP Tests
on:
workflow_call:
inputs:
php-versions:
description: 'The PHP versions to create builds for (as JSON string array)'
default: '["latest"]'
required: false
type: string
download-artifact:
description: 'Whether to download the build archive (filename format e.g. build-archive-php8.1)'
download_artifact:
description: 'Whether to download the build archive(s).'
default: true
required: false
type: boolean
download-test-files:
description: 'Whether to download files required for the test (artifact must be named test-files)'
download_artifact_prefix:
description: 'The artifact name prefix to use when downloading artifacts, if enabled.'
default: 'build-archive-php'
required: false
type: string
download_test_files:
description: 'Whether to download files required for tests (artifact must be named test-files).'
default: false
required: false
type: boolean
prepare-test-script:
description: 'The name of a bash script prepare the test environment, if needed, in test-files artifact'
default: ''
php_versions:
description: 'The PHP versions to run tests for (as JSON string array).'
default: '["latest"]'
required: false
type: string
prepare-test-env:
description: 'The name of a file containing required test environment variables, if needed, in test-files artifact'
prepare_test_script:
description: 'The name of a bash script prepare the test environment in test-files artifact.'
default: ''
required: false
type: string
type: string

# PHPStan options
enable-phpstan:
description: 'Whether to enable PHPStan tests'
phpstan_enable:
description: 'Whether to enable PHPStan.'
default: true
required: false
type: boolean
phpstan-config-file:
description: 'The location of the PHPStan configuration file (phpstan.neon)'
phpstan_config_file:
description: 'The location of the PHPStan configuration file (phpstan.neon).'
default: 'phpstan.neon'
required: false
type: string
phpstan-memory-limit:
description: 'The memory limit for PHPStan'
phpstan_memory_limit:
description: 'The memory limit for PHPStan.'
default: '512M'
required: false
type: string
phpstan-php-version:
description: 'The PHP version to use with PHPStan (if enabled)'
phpstan_php_version:
description: 'The PHP version to use with PHPStan.'
default: 'latest'
required: false
type: string
phpstan-version:
description: 'The version of PHPStan to use'
phpstan_version:
description: 'The version of PHPStan to use.'
default: 'latest'
required: false
type: string

# PHPUnit options
enable-phpunit:
description: 'Whether to enable PHPUnit tests'
phpunit_enable:
description: 'Whether to enable PHPUnit.'
default: true
required: false
type: boolean
phpunit-config-file:
description: 'The location of the PHPUnit configuration file (phpunit.xml.dist)'
phpunit_config_file:
description: 'The location of the PHPUnit configuration file (phpunit.xml.dist).'
default: 'phpunit.xml.dist'
required: false
type: string
phpunit-version:
description: 'The version of PHPUnit to use'
phpunit_version:
description: 'The version of PHPUnit to use.'
default: 'latest'
required: false
type: string

jobs:
php-test:
name: 'PHP ${{ matrix.php }}'
runs-on: ubuntu-latest
strategy:
matrix:
php: ${{ fromJSON(inputs.php-versions) }}

name: 'PHP ${{ matrix.php }}'
php: ${{ fromJSON(inputs.php_versions) }}
steps:
- name: Download PHP Build Archive
if: ${{ inputs.download-artifact }}
- name: 'Download PHP Build Archive'
if: ${{ inputs.download_artifact }}
uses: actions/download-artifact@v3
with:
name: build-archive-php${{ matrix.php }}
name: '${{ inputs.download_artifact_prefix }}-${{ matrix.php }}'
path: /tmp/builds

- name: Extract Build Archive
- name: 'Extract Build Archive'
run: tar -xvf /tmp/builds/build.tar ./

- name: Download Files Required for Tests
if: ${{ inputs.download-test-files }}
- name: 'Download Required Test Files'
if: ${{ inputs.download_test_files }}
uses: actions/download-artifact@v3
with:
name: test-files
path: ./

- name: 'Run Script to Prepare Test Environment'
if: ${{ inputs.prepare-test-script != '' }}
run: bash ./${{ inputs.prepare-test-script }}

- name: 'Set Required Environment Variables'
if: ${{ inputs.prepare-test-env != '' }}
run: sed "/#/d" ${{ inputs.prepare-test-env }} >> $GITHUB_ENV
if: ${{ inputs.prepare_test_script != '' }}
run: bash ./${{ inputs.prepare_test_script }}

- name: PHPStan
if: ${{ inputs.enable-phpstan && matrix.php == inputs.phpstan-php-version }}
- name: 'PHPStan'
if: ${{ inputs.phpstan_enable && matrix.php == inputs.phpstan_php_version }}
uses: php-actions/phpstan@v3
with:
configuration: ${{inputs.phpstan-config-file }}
memory_limit: ${{ inputs.phpstan-memory-limit }}
php_version: ${{ inputs.phpstan-php-version }}
version: ${{ inputs.phpstan-version }}
configuration: ${{ inputs.phpstan_config_file }}
memory_limit: ${{ inputs.phpstan_memory_limit }}
php_version: ${{ inputs.phpstan_php_version }}
version: ${{ inputs.phpstan_version }}

- name: PHPUnit
if: ${{ inputs.enable-phpunit }}
- name: 'PHPUnit'
if: ${{ inputs.phpunit_enable }}
uses: php-actions/phpunit@v3
with:
version: ${{ inputs.phpunit-version }}
configuration: ${{ inputs.phpunit_config_file }}
php_version: ${{ matrix.php }}
configuration: ${{ inputs.phpunit-config-file }}
version: ${{ inputs.phpunit_version }}

0 comments on commit 0a5d7aa

Please sign in to comment.