|
| 1 | +name: 'Setup Node with V8 Crash Retry' |
| 2 | +description: 'Setup Node.js with automatic retry on V8 bytecode deserialization errors' |
| 3 | +inputs: |
| 4 | + node-version: |
| 5 | + description: 'Version Spec of the version to use. Examples: 12.x, 10.15.1, >=10.15.0' |
| 6 | + required: true |
| 7 | + cache: |
| 8 | + description: 'Used to specify a package manager for caching in the default directory. Supported values: npm, yarn, pnpm.' |
| 9 | + required: false |
| 10 | + default: '' |
| 11 | + cache-dependency-path: |
| 12 | + description: 'Used to specify the path to a dependency file: package-lock.json, yarn.lock, etc. Supports wildcards or a list of file names for caching multiple dependencies.' |
| 13 | + required: false |
| 14 | + default: '' |
| 15 | + max-retries: |
| 16 | + description: 'Maximum number of retry attempts on V8 crash' |
| 17 | + required: false |
| 18 | + default: '3' |
| 19 | + |
| 20 | +runs: |
| 21 | + using: 'composite' |
| 22 | + steps: |
| 23 | + - name: Setup Node.js with retry |
| 24 | + shell: bash |
| 25 | + env: |
| 26 | + NODE_VERSION: ${{ inputs.node-version }} |
| 27 | + CACHE_TYPE: ${{ inputs.cache }} |
| 28 | + CACHE_PATH: ${{ inputs.cache-dependency-path }} |
| 29 | + MAX_RETRIES: ${{ inputs.max-retries }} |
| 30 | + run: | |
| 31 | + # This script wraps the setup-node action with retry logic for V8 crashes |
| 32 | + # The V8 crash manifests during 'yarn cache dir' execution in setup-node |
| 33 | +
|
| 34 | + ATTEMPT=1 |
| 35 | + SUCCESS=false |
| 36 | +
|
| 37 | + # Function to setup node |
| 38 | + setup_node_attempt() { |
| 39 | + echo "::group::Node.js setup attempt $ATTEMPT of $MAX_RETRIES" |
| 40 | +
|
| 41 | + # We need to manually do what setup-node does, since we can't retry an action from within a composite action |
| 42 | + # 1. Ensure Node.js is available (it should be pre-installed on GitHub runners) |
| 43 | + # 2. Setup the cache (this is where the V8 crash happens) |
| 44 | +
|
| 45 | + if [ -n "$CACHE_TYPE" ] && [ "$CACHE_TYPE" = "yarn" ]; then |
| 46 | + # Test if yarn cache dir works (this is where V8 crashes occur) |
| 47 | + TEMP_OUTPUT=$(mktemp) |
| 48 | +
|
| 49 | + if timeout 30 yarn cache dir > "$TEMP_OUTPUT" 2>&1; then |
| 50 | + echo "Yarn cache dir command succeeded" |
| 51 | + cat "$TEMP_OUTPUT" |
| 52 | + rm -f "$TEMP_OUTPUT" |
| 53 | + echo "::endgroup::" |
| 54 | + return 0 |
| 55 | + else |
| 56 | + EXIT_CODE=$? |
| 57 | + # Check for V8 crash in output |
| 58 | + if grep -q "Fatal error in.*Check failed: ReadSingleBytecodeData" "$TEMP_OUTPUT"; then |
| 59 | + echo "::warning::V8 bytecode deserialization error detected" |
| 60 | + cat "$TEMP_OUTPUT" |
| 61 | + rm -f "$TEMP_OUTPUT" |
| 62 | + echo "::endgroup::" |
| 63 | + return 1 |
| 64 | + else |
| 65 | + echo "::error::Different error occurred (exit code: $EXIT_CODE):" |
| 66 | + cat "$TEMP_OUTPUT" |
| 67 | + rm -f "$TEMP_OUTPUT" |
| 68 | + echo "::endgroup::" |
| 69 | + return $EXIT_CODE |
| 70 | + fi |
| 71 | + fi |
| 72 | + else |
| 73 | + # No cache or non-yarn cache, nothing to retry |
| 74 | + echo "::endgroup::" |
| 75 | + return 0 |
| 76 | + fi |
| 77 | + } |
| 78 | +
|
| 79 | + # Retry loop |
| 80 | + while [ $ATTEMPT -le $MAX_RETRIES ]; do |
| 81 | + if setup_node_attempt; then |
| 82 | + SUCCESS=true |
| 83 | + break |
| 84 | + else |
| 85 | + if [ $ATTEMPT -lt $MAX_RETRIES ]; then |
| 86 | + echo "::warning::Retry attempt $ATTEMPT failed. Waiting 5 seconds before retry..." |
| 87 | + sleep 5 |
| 88 | + ATTEMPT=$((ATTEMPT + 1)) |
| 89 | + else |
| 90 | + echo "::error::All $MAX_RETRIES retry attempts failed" |
| 91 | + exit 1 |
| 92 | + fi |
| 93 | + fi |
| 94 | + done |
| 95 | +
|
| 96 | + if [ "$SUCCESS" != true ]; then |
| 97 | + echo "::error::Failed to setup Node.js after $MAX_RETRIES attempts" |
| 98 | + exit 1 |
| 99 | + fi |
| 100 | +
|
| 101 | + - name: Setup Node.js |
| 102 | + uses: actions/setup-node@v4 |
| 103 | + with: |
| 104 | + node-version: ${{ inputs.node-version }} |
| 105 | + cache: ${{ inputs.cache }} |
| 106 | + cache-dependency-path: ${{ inputs.cache-dependency-path }} |
0 commit comments