Files
github-actions-magento2/cache-magento/test.sh
T
Damien Retzinger 2d7238de14 feat(cache-magento): include runner.os in the cache key (#245)
Composer's download cache contains platform-specific binaries and
extracted archives that aren't safe to share across operating
systems. Add the runner OS as a key segment so a Linux job won't
restore a macOS-built cache (or vice versa).
2026-05-09 15:47:51 -04:00

46 lines
1.1 KiB
Bash

#!/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 (Linux)
OUT=$(bash "$SCRIPT" "_mageos" "Linux" "8.3.0" "2.2.6")
assert_eq "linux: download-key" \
"composer | v5.8 | Linux | _mageos | 2.2.6 | 8.3.0" \
"$(field "$OUT" download-key)"
# OS segment differentiates macOS from Linux
OUT=$(bash "$SCRIPT" "_mageos" "macOS" "8.3.0" "2.2.6")
assert_eq "macos: download-key" \
"composer | v5.8 | macOS | _mageos | 2.2.6 | 8.3.0" \
"$(field "$OUT" download-key)"
# Custom composer_cache_key
OUT=$(bash "$SCRIPT" "custom-v2" "Linux" "8.1.5" "2.4.2")
assert_eq "custom key: download-key" \
"composer | v5.8 | Linux | custom-v2 | 2.4.2 | 8.1.5" \
"$(field "$OUT" download-key)"
echo ""
echo "$PASS passed, $FAIL failed"
[ "$FAIL" -eq 0 ]