From c27ceec00ab87f977bd6b62fb3aec757970a2084 Mon Sep 17 00:00:00 2001 From: Adam Daley Date: Sun, 26 Nov 2023 21:12:05 +0000 Subject: [PATCH] Create Reusable PHP build workflow --- .github/workflows/php-build.yml | 54 ++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 8 deletions(-) diff --git a/.github/workflows/php-build.yml b/.github/workflows/php-build.yml index 186a570..0681d3e 100644 --- a/.github/workflows/php-build.yml +++ b/.github/workflows/php-build.yml @@ -4,26 +4,30 @@ name: PHP Build on: workflow_call: inputs: - cache-deps: - description: '' + cache_deps: + description: 'Whether to cache composer dependencies' default: true required: false type: boolean - php-version: - description: '' - default: + php_versions: + description: 'The PHP versions to create builds for (as JSON string array)' + default: '["latest"]' required: false type: string - upload-artifact: - description: '' + 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: - name: '' runs-on: ubuntu-latest + strategy: + matrix: + php: ${{ fromJSON(inputs.php_versions) }} + + name: 'PHP ${{ matrix.php }} - Build and Archive' steps: - uses: actions/checkout@v4 @@ -31,3 +35,37 @@ jobs: 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 \ No newline at end of file