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 1, 2023
1 parent b34d8a6 commit 8d843a2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 22 deletions.
52 changes: 31 additions & 21 deletions .github/workflows/php-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,62 +3,72 @@ 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 prefix to use for uploaded artifact name(s), if enabled.'
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
7 changes: 6 additions & 1 deletion .github/workflows/php-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ on:
default: true
required: false
type: boolean
download_artifact_prefix:
description: ''
default: 'build-archive-php'
required: false
type: string
download-test-files:
description: 'Whether to download files required for the test (artifact must be named test-files)'
default: false
Expand Down Expand Up @@ -86,7 +91,7 @@ jobs:
if: ${{ inputs.download-artifact }}
uses: actions/download-artifact@v3
with:
name: build-archive-php${{ matrix.php }}
name: build-dev-php${{ matrix.php }}
path: /tmp/builds

- name: Extract Build Archive
Expand Down

0 comments on commit 8d843a2

Please sign in to comment.