mirror of
https://github.com/graycoreio/github-actions-magento2.git
synced 2026-06-08 19:46:41 +00:00
refactor(cache-magento): extract key computation into a script (#245)
This commit is contained in:
@@ -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
|
||||
@@ -31,11 +31,21 @@ runs:
|
||||
name: Compute 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"
|
||||
uses: actions/cache@v5
|
||||
id: cache-magento-cache
|
||||
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 }}
|
||||
|
||||
branding:
|
||||
|
||||
@@ -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}"
|
||||
@@ -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 ]
|
||||
Reference in New Issue
Block a user