Skip to content

Commit

Permalink
fix(pdk): pass files instead of pre-made hashes for caching
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Jul 25, 2024
1 parent 97e2c2e commit d180881
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 28 deletions.
57 changes: 50 additions & 7 deletions pdk-cache/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,61 @@ inputs:
required: false
default: '^0.18.0'

source-hash:
description: 'Hash of the source files'
vendor-key:
description: 'Composer key to use for caching in addition to the vendor files'
required: false

source-files:
description: 'List of files to use for source caching'
required: true

vendor-hash:
description: 'Hash of the vendor files'
vendor-files:
description: 'List of files to use for vendor caching'
required: false
default: ${{ hashFiles('**/composer.json', '**/composer.lock', '**/scoper.inc.php', '**/scoper.*.inc.php') }}
default: |
**/composer.json
**/composer.lock
**/scoper.inc.php
**/scoper.*.inc.php
runs:
using: composite
steps:
- name: 'Create variables'
id: prepare
shell: bash
env:
SOURCE_FILES: ${{ inputs.source-files }}
VENDOR_FILES: ${{ inputs.vendor-files }}
VENDOR_KEY: ${{ inputs.vendor-key }}
#language=bash
run: |
# if vendor key is not a hash, hash it now
if [[ -n "$VENDOR_KEY" && ! "$VENDOR_KEY" =~ ^[a-f0-9]{40}$ ]]; then
NEW_VENDOR_KEY=$(echo "$VENDOR_KEY" | sha1sum | cut -d ' ' -f 1)
else
NEW_VENDOR_KEY=$VENDOR_KEY
fi
# trim leading and trailing whitespaces and remove empty lines
TRIMMED_SOURCE_FILES=$(echo "$SOURCE_FILES" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' -e '/^$/d')
TRIMMED_VENDOR_FILES=$(echo "$VENDOR_FILES" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' -e '/^$/d')
NEW_SOURCE_FILES=$(echo "$TRIMMED_SOURCE_FILES" | tr '\n' ',' | sed 's/,$//')
NEW_VENDOR_FILES=$(echo "$TRIMMED_VENDOR_FILES" | tr '\n' ',' | sed 's/,$//')
echo "source-files=$NEW_SOURCE_FILES" >> $GITHUB_OUTPUT
echo "vendor-files=$NEW_VENDOR_FILES" >> $GITHUB_OUTPUT
echo "vendor-key=$NEW_VENDOR_KEY-" >> $GITHUB_OUTPUT
- name: 'Create hashes'
id: hashes
shell: bash
#language=bash
run: |
echo "source-hash=${{ hashFiles(steps.prepare.outputs.source-files) }}" >> $GITHUB_OUTPUT
echo "vendor-hash=${{ steps.prepare.outputs.vendor-key }}${{ hashFiles(steps.prepare.outputs.vendor-files) }}" >> $GITHUB_OUTPUT
- name: 'Cache php-scoper'
uses: actions/cache@v4
with:
Expand All @@ -34,10 +77,10 @@ runs:
uses: actions/cache@v4
with:
path: .tmp/scoped/source
key: scoped-php-src-${{ inputs.php-version }}-${{ inputs.source-hash }}
key: scoped-php-src-${{ inputs.php-version }}-${{ outputs.hashes.outputs.source-hash }}

- name: 'Cache scoped vendor php'
uses: actions/cache@v4
with:
path: .tmp/scoped/vendor
key: scoped-php-vendor-${{ inputs.php-version }}-${{ inputs.vendor-hash }}
key: scoped-php-vendor-${{ inputs.php-version }}-${{ steps.hashes.outputs.vendor-hash }}
13 changes: 6 additions & 7 deletions pdk-custom-build-prepare/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ inputs:
required: false
default: '^0.18.0'

source-hash:
description: 'Hash of the source files'
source-files:
description: 'List of source files to use for caching'
required: true

vendor-hash:
description: 'Hash of the vendor files'
vendor-files:
description: 'List of files to use for caching'
required: false
default: ${{ hashFiles('**/composer.json', '**/composer.lock', '**/scoper.inc.php', '**/scoper.*.inc.php') }}

outputs:
image:
Expand Down Expand Up @@ -80,8 +79,8 @@ runs:
with:
php-version: ${{ inputs.php-version }}
php-scoper-version: ${{ inputs.php-scoper-version }}
source-hash: ${{ inputs.source-hash }}
vendor-hash: ${{ inputs.vendor-hash }}
source-files: ${{ inputs.source-files }}
vendor-files: ${{ inputs.vendor-files }}

- uses: myparcelnl/actions/pdk-setup@v4
id: setup
Expand Down
13 changes: 6 additions & 7 deletions pdk-prerelease-pr/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ inputs:
description: 'PHP Docker image to use'
required: true

source-hash:
description: 'Hash of the source files'
source-files:
description: 'List of source files to use for caching'
required: true

vendor-hash:
description: 'Hash of the vendor files'
vendor-files:
description: 'List of files to use for caching'
required: false
default: ${{ hashFiles('**/composer.json', '**/composer.lock', '**/scoper.inc.php', '**/scoper.*.inc.php') }}

outputs:
version:
Expand Down Expand Up @@ -59,8 +58,8 @@ runs:
with:
php-version: ${{ inputs.php-version }}
php-scoper-version: ${{ inputs.php-scoper-version }}
source-hash: ${{ inputs.source-hash }}
vendor-hash: ${{ inputs.vendor-hash }}
source-files: ${{ inputs.source-files }}
vendor-files: ${{ inputs.vendor-files }}

- uses: myparcelnl/actions/pdk-release@v4
with:
Expand Down
13 changes: 6 additions & 7 deletions pdk-prerelease-push/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ inputs:
description: 'PHP Docker image to use'
required: true

source-hash:
description: 'Hash of the source files'
source-files:
description: 'List of source files to use for caching'
required: true

vendor-hash:
description: 'Hash of the vendor files'
vendor-files:
description: 'List of files to use for caching'
required: false
default: ${{ hashFiles('**/composer.json', '**/composer.lock', '**/scoper.inc.php', '**/scoper.*.inc.php') }}

outputs:
version:
Expand Down Expand Up @@ -54,8 +53,8 @@ runs:
with:
php-version: ${{ inputs.php-version }}
php-scoper-version: ${{ inputs.php-scoper-version }}
source-hash: ${{ inputs.source-hash }}
vendor-hash: ${{ inputs.vendor-hash }}
source-files: ${{ inputs.source-files }}
vendor-files: ${{ inputs.vendor-files }}

- uses: myparcelnl/actions/pdk-release@v4
with:
Expand Down

0 comments on commit d180881

Please sign in to comment.