Skip to content

Commit

Permalink
fix(setup-node): add retries to getting node version
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Jul 31, 2024
1 parent 1fb7f2d commit fa39225
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions setup-node/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,28 @@ runs:
with:
node-version: ${{ steps.prepare.outputs.node-version }}

# Tries getting the node version 3 times. When using volta you can sometimes get an error while downloading node,
# causing this command to fail.
- name: 'Get node version'
id: node-version
shell: bash
#language=bash
run: |
VERSION="$(node --version)"
TRIMMED="${VERSION:1}"
MAX_RETRIES=3
RETRY_COUNT=0
SUCCESS=false
echo "version=$TRIMMED" >> $GITHUB_OUTPUT
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
VERSION=$(node --version) && SUCCESS=true && break
RETRY_COUNT=$((RETRY_COUNT+1))
echo "Attempt $RETRY_COUNT failed. Retrying..."
sleep 2
done
if [ "$SUCCESS" = true ]; then
TRIMMED="${VERSION:1}"
echo "version=$TRIMMED" >> $GITHUB_OUTPUT
else
echo "Failed to get Node.js version after $MAX_RETRIES attempts."
exit 1
fi

0 comments on commit fa39225

Please sign in to comment.