refactor(cache-magento): extract key computation into a script (#245)

This commit is contained in:
Damien Retzinger
2026-05-09 15:37:28 -04:00
parent c53607cca8
commit 44e7c34892
4 changed files with 80 additions and 1 deletions
@@ -0,0 +1,23 @@
name: Cache Magento Test
on:
push:
branches: [main]
paths:
- "cache-magento/**"
- ".github/workflows/_internal-cache-magento.yaml"
- "!(**/*.md)"
pull_request:
branches: [main]
paths:
- "cache-magento/**"
- ".github/workflows/_internal-cache-magento.yaml"
- "!(**/*.md)"
jobs:
unit:
if: "!startsWith(github.head_ref, 'release-please')"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- run: bash cache-magento/test.sh
+11 -1
View File
@@ -31,11 +31,21 @@ runs:
name: Compute Composer Version name: Compute Composer Version
id: cache-magento-get-composer-version id: cache-magento-get-composer-version
- name: Compute cache keys
id: cache-magento-keys
shell: bash
run: |
bash "${{ github.action_path }}/compute-cache-keys.sh" \
"${{ inputs.composer_cache_key }}" \
"${{ steps.cache-magento-get-php-version.outputs.version }}" \
"${{ steps.cache-magento-get-composer-version.outputs.version }}" \
>> $GITHUB_OUTPUT
- name: "Cache Composer Packages" - name: "Cache Composer Packages"
uses: actions/cache@v5 uses: actions/cache@v5
id: cache-magento-cache id: cache-magento-cache
with: with:
key: "composer | v5.8 | ${{ inputs.composer_cache_key }} | ${{ steps.cache-magento-get-composer-version.outputs.version }} | ${{ steps.cache-magento-get-php-version.outputs.version }}" key: ${{ steps.cache-magento-keys.outputs.download-key }}
path: ${{ steps.cache-magento-composer-cache.outputs.dir }} path: ${{ steps.cache-magento-composer-cache.outputs.dir }}
branding: branding:
+7
View File
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
# Args: composer_cache_key php_version composer_version
COMPOSER_CACHE_KEY="$1"
PHP_VERSION="$2"
COMPOSER_VERSION="$3"
echo "download-key=composer | v5.8 | ${COMPOSER_CACHE_KEY} | ${COMPOSER_VERSION} | ${PHP_VERSION}"
+39
View File
@@ -0,0 +1,39 @@
#!/usr/bin/env bash
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SCRIPT="$SCRIPT_DIR/compute-cache-keys.sh"
PASS=0
FAIL=0
assert_eq() {
local label="$1" expected="$2" actual="$3"
if [ "$expected" = "$actual" ]; then
echo "PASS: $label"
PASS=$((PASS + 1))
else
echo "FAIL: $label"
echo " expected: $expected"
echo " actual: $actual"
FAIL=$((FAIL + 1))
fi
}
field() {
echo "$1" | grep "^${2}=" | cut -d= -f2-
}
# Default cache key
OUT=$(bash "$SCRIPT" "_mageos" "8.3.0" "2.2.6")
assert_eq "default: download-key" \
"composer | v5.8 | _mageos | 2.2.6 | 8.3.0" \
"$(field "$OUT" download-key)"
# Custom composer_cache_key
OUT=$(bash "$SCRIPT" "custom-v2" "8.1.5" "2.4.2")
assert_eq "custom key: download-key" \
"composer | v5.8 | custom-v2 | 2.4.2 | 8.1.5" \
"$(field "$OUT" download-key)"
echo ""
echo "$PASS passed, $FAIL failed"
[ "$FAIL" -eq 0 ]