mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-30 11:11:02 +00:00
169 lines
5.9 KiB
YAML
169 lines
5.9 KiB
YAML
name: Setup pnpm + store cache
|
|
description: Prepare pnpm via corepack and restore pnpm store cache.
|
|
inputs:
|
|
pnpm-version:
|
|
description: pnpm version to activate via corepack.
|
|
required: false
|
|
default: "11.0.8"
|
|
node-version:
|
|
description: Expected Node.js version already installed by actions/setup-node.
|
|
required: false
|
|
default: "24.x"
|
|
cache-key-suffix:
|
|
description: Suffix appended to the cache key.
|
|
required: false
|
|
default: "node24-pnpm11"
|
|
use-restore-keys:
|
|
description: Whether to use restore-keys fallback for actions/cache.
|
|
required: false
|
|
default: "true"
|
|
use-actions-cache:
|
|
description: Whether to restore pnpm store with actions/cache.
|
|
required: false
|
|
default: "true"
|
|
outputs:
|
|
cache-enabled:
|
|
description: Whether actions/cache restore was enabled.
|
|
value: ${{ steps.pnpm-cache-config.outputs.enabled }}
|
|
cache-hit:
|
|
description: Whether the pnpm store cache had an exact key hit.
|
|
value: ${{ steps.pnpm-cache-restore.outputs.cache-hit }}
|
|
cache-matched-key:
|
|
description: Cache key matched by restore, if any.
|
|
value: ${{ steps.pnpm-cache-restore.outputs.cache-matched-key }}
|
|
primary-key:
|
|
description: Primary pnpm store cache key.
|
|
value: ${{ steps.pnpm-cache-config.outputs.primary-key }}
|
|
store-path:
|
|
description: Resolved pnpm store path.
|
|
value: ${{ steps.pnpm-store.outputs.path }}
|
|
runs:
|
|
using: composite
|
|
steps:
|
|
- name: Setup pnpm (corepack retry)
|
|
shell: bash
|
|
env:
|
|
COREPACK_ENABLE_DOWNLOAD_PROMPT: "0"
|
|
PNPM_VERSION: ${{ inputs.pnpm-version }}
|
|
REQUESTED_NODE_VERSION: ${{ inputs.node-version }}
|
|
run: |
|
|
set -euo pipefail
|
|
if [[ ! "$PNPM_VERSION" =~ ^[0-9]+(\.[0-9]+){1,2}([.-][0-9A-Za-z.-]+)?$ ]]; then
|
|
echo "::error::Invalid pnpm-version input: '$PNPM_VERSION'"
|
|
exit 2
|
|
fi
|
|
|
|
requested_node="${REQUESTED_NODE_VERSION:-${NODE_VERSION:-}}"
|
|
requested_node="${requested_node#v}"
|
|
|
|
node_version_matches() {
|
|
local actual="$1"
|
|
local requested="$2"
|
|
if [[ -z "$requested" ]]; then
|
|
return 0
|
|
fi
|
|
case "$requested" in
|
|
*x)
|
|
[[ "${actual%%.*}" == "${requested%%.*}" ]]
|
|
;;
|
|
*.*.*)
|
|
[[ "$actual" == "$requested" ]]
|
|
;;
|
|
*.*)
|
|
[[ "$actual" == "$requested".* ]]
|
|
;;
|
|
*)
|
|
[[ "${actual%%.*}" == "$requested" ]]
|
|
;;
|
|
esac
|
|
}
|
|
|
|
active_node_version="$(node -p 'process.versions.node' 2>/dev/null || true)"
|
|
if ! node_version_matches "$active_node_version" "$requested_node"; then
|
|
node_roots=()
|
|
for root in \
|
|
"${RUNNER_TOOL_CACHE:-}" \
|
|
"${AGENT_TOOLSDIRECTORY:-}" \
|
|
"${ACTIONS_RUNNER_TOOL_CACHE:-}" \
|
|
"/opt/hostedtoolcache" \
|
|
"/home/runner/_work/_tool" \
|
|
"/Users/runner/hostedtoolcache" \
|
|
"/c/hostedtoolcache/windows"
|
|
do
|
|
if [[ -d "$root/node" ]]; then
|
|
node_roots+=("$root/node")
|
|
elif [[ "$(basename "$root")" == "node" && -d "$root" ]]; then
|
|
node_roots+=("$root")
|
|
fi
|
|
done
|
|
|
|
node_bin=""
|
|
for node_root in "${node_roots[@]}"; do
|
|
while IFS= read -r candidate; do
|
|
candidate_version="$("$candidate" -p 'process.versions.node' 2>/dev/null || true)"
|
|
if node_version_matches "$candidate_version" "$requested_node"; then
|
|
node_bin="$candidate"
|
|
break 2
|
|
fi
|
|
done < <(find "$node_root" \( -name node -o -name node.exe \) -type f 2>/dev/null | sort -r)
|
|
done
|
|
|
|
if [[ -n "$node_bin" ]]; then
|
|
echo "Using Node $("$node_bin" -p 'process.versions.node') from $node_bin"
|
|
export PATH="$(dirname "$node_bin"):$PATH"
|
|
hash -r
|
|
fi
|
|
fi
|
|
|
|
active_node_version="$(node -p 'process.versions.node' 2>/dev/null || true)"
|
|
if ! node_version_matches "$active_node_version" "$requested_node"; then
|
|
echo "::error::Expected Node '${requested_node}', but active node is '${active_node_version:-missing}' at $(command -v node || true)"
|
|
exit 1
|
|
fi
|
|
|
|
node -v
|
|
command -v node
|
|
command -v corepack
|
|
corepack enable
|
|
for attempt in 1 2 3; do
|
|
if corepack prepare "pnpm@$PNPM_VERSION" --activate; then
|
|
pnpm -v
|
|
exit 0
|
|
fi
|
|
echo "corepack prepare failed (attempt $attempt/3). Retrying..."
|
|
sleep $((attempt * 10))
|
|
done
|
|
exit 1
|
|
|
|
- name: Resolve pnpm store path
|
|
id: pnpm-store
|
|
shell: bash
|
|
run: echo "path=$(pnpm store path --silent)" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Resolve pnpm store cache keys
|
|
id: pnpm-cache-config
|
|
shell: bash
|
|
env:
|
|
CACHE_KEY_SUFFIX: ${{ inputs.cache-key-suffix }}
|
|
LOCKFILE_HASH: ${{ hashFiles('pnpm-lock.yaml') }}
|
|
USE_ACTIONS_CACHE: ${{ inputs.use-actions-cache }}
|
|
USE_RESTORE_KEYS: ${{ inputs.use-restore-keys }}
|
|
run: |
|
|
set -euo pipefail
|
|
echo "enabled=$USE_ACTIONS_CACHE" >> "$GITHUB_OUTPUT"
|
|
echo "primary-key=${RUNNER_OS}-pnpm-store-${CACHE_KEY_SUFFIX}-${LOCKFILE_HASH}" >> "$GITHUB_OUTPUT"
|
|
if [ "$USE_RESTORE_KEYS" = "true" ]; then
|
|
echo "restore-keys=${RUNNER_OS}-pnpm-store-${CACHE_KEY_SUFFIX}-" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "restore-keys=" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
- name: Restore pnpm store cache
|
|
id: pnpm-cache-restore
|
|
if: inputs.use-actions-cache == 'true'
|
|
uses: actions/cache/restore@v5
|
|
with:
|
|
path: ${{ steps.pnpm-store.outputs.path }}
|
|
key: ${{ steps.pnpm-cache-config.outputs.primary-key }}
|
|
restore-keys: ${{ steps.pnpm-cache-config.outputs.restore-keys }}
|