CircleCI-Public / node-orb

An orb for working with Node.js on CircleCI
https://circleci.com/orbs/registry/orb/circleci/node
MIT License
52 stars 80 forks source link

Yarn install fails due to gzip error #142

Closed kingjerod closed 2 years ago

kingjerod commented 2 years ago

Orb version:

4.7 and 5.01

What happened:

Tried to install Node 14.19 and Yarn, it errors with gzip: stdin: not in gzip format, tar: Child returned status 1

Additional Information:

Circle Config Command:

  - node/install:
      install-yarn: true
      node-version: '14.19'

I was getting this error on orb version 4.7, upgraded to 5.01 and still getting the error. Guessing it's an issue with the latest Yarn build? It just started happening today, was running multiple builds and then it just stopped working.

Build log:

#!/bin/bash -eo pipefail
if [[ $EUID == 0 ]]; then export SUDO=""; else export SUDO="sudo"; fi

# FUNCTIONS
get_yarn_version () {
    if [[ "$NODE_PARAM_YARN_VERSION" == "" ]]; then
    YARN_ORB_VERSION=$(curl -Ls -o /dev/null -w "%{url_effective}" \
        "https://github.com/yarnpkg/yarn/releases/latest" | sed 's:.*/::' | cut -d 'v' -f 2 | cut -d 'v' -f 2)
    echo "Latest version of Yarn is $YARN_ORB_VERSION"
    else
    YARN_ORB_VERSION="$NODE_PARAM_YARN_VERSION"

    echo "Selected version of Yarn is $YARN_ORB_VERSION"
    fi
}

installation_check () {
    echo "Checking if YARN is already installed..."
    if command -v yarn > /dev/null 2>&1; then
    if yarn --version | grep "$YARN_ORB_VERSION" > /dev/null 2>&1; then
        echo "Yarn $YARN_ORB_VERSION is already installed"
        exit 0
    else
        echo "A different version of Yarn is installed ($(yarn --version)); removing it"

        if uname -a | grep Darwin > /dev/null 2>&1; then
        brew uninstall yarn > /dev/null 2>&1
        elif grep Alpine /etc/issue > /dev/null 2>&1; then
        apk del yarn > /dev/null 2>&1
        elif grep Debian /etc/issue > /dev/null 2>&1; then
        $SUDO apt-get remove yarn > /dev/null 2>&1 && \
            $SUDO apt-get purge yarn > /dev/null 2>&1
        elif grep Ubuntu /etc/issue > /dev/null 2>&1; then
        $SUDO apt-get remove yarn > /dev/null 2>&1 && \
            $SUDO apt-get purge yarn > /dev/null 2>&1
        elif command -v yum > /dev/null 2>&1; then
        yum remove yarn > /dev/null 2>&1
        fi

        $SUDO rm -rf "$HOME/.yarn" > /dev/null 2>&1
        $SUDO rm -f /usr/local/bin/yarn /usr/local/bin/yarnpkg > /dev/null 2>&1
    fi
    fi
}

# cd to home so that yarn --version will not use relative installed yarn from .yarn/releases
cd ~ || echo "Cannot change directory to home directory, yarn version may be mismatched."

get_yarn_version
installation_check

# install yarn
echo "Installing YARN v$YARN_ORB_VERSION"
curl -L -o yarn.tar.gz --silent "https://yarnpkg.com/downloads/$YARN_ORB_VERSION/yarn-v$YARN_ORB_VERSION.tar.gz"

$SUDO tar -xzf yarn.tar.gz && rm yarn.tar.gz

$SUDO mkdir -p /opt/yarn
$SUDO mv yarn-v"${YARN_ORB_VERSION}"/* /opt/yarn

$SUDO rm -rf "yarn-v${YARN_ORB_VERSION}"

$SUDO chmod 777 "/opt/yarn"

$SUDO ln -s /opt/yarn/bin/yarn /usr/local/bin/yarn
$SUDO ln -s /opt/yarn/bin/yarnpkg /usr/local/bin/yarnpkg
$SUDO ln -s /opt/yarn/bin/yarn.js /usr/local/bin/yarn.js

$SUDO mkdir -p ~/.config

if uname -a | grep Darwin; then
    $SUDO chown -R "$USER:$GROUP" ~/.config
    $SUDO chown -R "$USER:$GROUP" /opt/yarn
else
    $SUDO chown -R "$(whoami):$(whoami)" /opt/yarn
    $SUDO chown -R "$(whoami):$(whoami)" ~/.config
fi

# test/verify version
echo "Verifying YARN install"
if yarn --version | grep "$YARN_ORB_VERSION" > /dev/null 2>&1; then
    echo "Success! Yarn $(yarn --version) has been installed to $(which yarn)"
else
    echo "Something went wrong; the specified version of Yarn could not be installed"
    exit 1
fi

Latest version of Yarn is 1.22.18
Checking if YARN is already installed...
A different version of Yarn is installed (1.22.5); removing it
Installing YARN v1.22.18

gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now
mv: cannot stat 'yarn-v1.22.18/*': No such file or directory

Exited with code exit status 1

CircleCI received exit code 1
atalwar-sephora commented 2 years ago

Facing same issue in our pipeline. Thanks for raising the issue @kingjerod

atalwar-sephora commented 2 years ago

As a workaround we installed yarn as a separate step and exported it in PATH. But a fix to this will help removing extra steps in pipeline.

egorradjuk commented 2 years ago

Same issue in our pipeline

yuokada commented 2 years ago

Specifying yarn version with yarn-version value is also helpful to avoid this issue in my environment.

yuokada commented 2 years ago

Probably, the issue below is the root cause. Error releasing v1.22.18 · Issue #8801 · yarnpkg/yarn

Daniel15 commented 2 years ago

YARN_ORB_VERSION should ideally come from https://classic.yarnpkg.com/latest-version, not the releases page, as the latest-version endpoint is only updated once all the build artifacts have been uploaded. Unfortunately all the Yarn v1 release infra was created before GitHub supported "draft versions", and it's not being actively worked on at the moment.

Daniel15 commented 2 years ago

This should be resolved as v1.22.18 is published now.

Jaryt commented 2 years ago

YARN_ORB_VERSION should ideally come from https://classic.yarnpkg.com/latest-version, not the releases page, as the latest-version endpoint is only updated once all the build artifacts have been uploaded. Unfortunately all the Yarn v1 release infra was created before GitHub supported "draft versions", and it's not being actively worked on at the moment.

Thanks for the pointer here! Will certainly update this in the orb. Also, thanks everyone for escalating this and getting it resolved 😄 Closing out

Daniel15 commented 2 years ago

Thanks for the pointer here! Will certainly update this in the orb.

You'll also avoid hitting GitHub rate limits with the /latest-version endpoint 😃