Skip to content

Commit

Permalink
Create reusable PHP build and PHPStan workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
admdly committed Nov 26, 2023
1 parent 1012bc7 commit 4a29f5c
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 6 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/php-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#
name: PHP Build

on:
workflow_call:
inputs:
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)'
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)'
default: true
required: false
type: boolean

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
php: ${{ fromJSON(inputs.php_versions) }}

name: 'PHP ${{ matrix.php }} - Build and Archive'
steps:
- uses: actions/checkout@v4

- name: Validate composer.json and composer.lock
uses: php-actions/composer@v6
with:
command: validate

- name: Cache Composer Dependencies
if: ${{ inputs.cache_deps == 'true' }}
id: composer-cache
uses: actions/cache@v3
with:
path: ./src/vendor
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install Composer Dependencies
if: ${{ inputs.cache_deps != 'true' || steps.composer-cache.outputs.cache-hit != 'true' }}
uses: php-actions/composer@v6
with:
php_version: ${{ matrix.php }}

- name: Create Build Archive
run: |
cp ./src/config-sample.php ./src/config.php
mkdir -p ./src/data/cache
mkdir -p ./src/data/log
echo > ./src/data/log/license.log
echo > ./src/data/log/application.log
echo > ./src/data/log/php_error.log
mkdir /tmp/builds/ && tar -cvf /tmp/builds/build.tar ./
- name: Upload Build Archive
if: ${{ inputs.upload_artifact == 'true' }}
uses: actions/upload-artifact@v3
with:
name: build-archive-php${{ matrix.php }}
path: /tmp/builds
retention-days: 1
12 changes: 6 additions & 6 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ name: PHPStan
on:
workflow_call:
inputs:
config_file:
config-file:
description: Configuration file location
default: phpstan.neon
required: false
type: string
memory_limit:
memory-limit:
description: Memory limit for analysis
required: false
type: string
php_version:
php-version:
description: Version of PHP to use
default: latest
required: false
Expand All @@ -31,7 +31,7 @@ jobs:
- uses: actions/checkout@v4
- uses: php-actions/phpstan@v3
with:
configuration: ${{ inputs.config_file }}
memory_limit: ${{ inputs.memory_limit }}
php_version: ${{ inputs.php_version }}
configuration: ${{ inputs.config-file }}
memory_limit: ${{ inputs.memory-limit }}
php_version: ${{ inputs.php-version }}
version: ${{ inputs.version }}

0 comments on commit 4a29f5c

Please sign in to comment.