Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 55 additions & 1 deletion .github/actions/setup-node-install-deps/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,61 @@ runs:
using: "composite"

steps:
- uses: actions/setup-node@v4
# Workaround for https://github.com/actions/setup-node/issues/1492
# Check if the current Node version matches the requested version to avoid unnecessary downloads
- id: check-node-version
run: |
REQUESTED_VERSION="${{ inputs.node-version }}"
CURRENT_VERSION=$(node -v 2>/dev/null || echo "")
CURRENT_VERSION=${CURRENT_VERSION#v}

echo "Requested version: $REQUESTED_VERSION"
echo "Current version: $CURRENT_VERSION"

# If no version is requested (empty string), skip setup
if [ -z "$REQUESTED_VERSION" ]; then
echo "skip-setup=true" >> $GITHUB_OUTPUT
echo "No specific version requested, using current Node version"
exit 0
fi

# If node is not installed, we need setup
if [ -z "$CURRENT_VERSION" ]; then
echo "skip-setup=false" >> $GITHUB_OUTPUT
echo "Node not found, will run setup-node"
exit 0
fi

# Normalize versions for comparison
# Handle patterns like "24", "24.x", "24.13.0"
REQUESTED_MAJOR=$(echo "$REQUESTED_VERSION" | cut -d. -f1)
CURRENT_MAJOR=$(echo "$CURRENT_VERSION" | cut -d. -f1)

# Check if requested version is just major version (e.g., "24") or has .x suffix (e.g., "24.x")
# Using two separate checks is more explicit and easier to understand than a combined regex
if [[ "$REQUESTED_VERSION" =~ ^[0-9]+$ ]] || [[ "$REQUESTED_VERSION" =~ ^[0-9]+\.x$ ]]; then
# Compare only major version
if [ "$CURRENT_MAJOR" = "$REQUESTED_MAJOR" ]; then
echo "skip-setup=true" >> $GITHUB_OUTPUT
echo "Current Node major version $CURRENT_MAJOR matches requested $REQUESTED_VERSION"
else
echo "skip-setup=false" >> $GITHUB_OUTPUT
echo "Current Node major version $CURRENT_MAJOR does not match requested $REQUESTED_VERSION"
fi
else
# Exact version match required
if [ "$CURRENT_VERSION" = "$REQUESTED_VERSION" ]; then
echo "skip-setup=true" >> $GITHUB_OUTPUT
echo "Current Node version $CURRENT_VERSION matches requested $REQUESTED_VERSION"
else
echo "skip-setup=false" >> $GITHUB_OUTPUT
echo "Current Node version $CURRENT_VERSION does not match requested $REQUESTED_VERSION"
fi
fi
shell: bash

- if: steps.check-node-version.outputs.skip-setup != 'true'
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}

Expand Down