Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yarn is not installed #182

Open
GoldFlsh opened this issue Aug 12, 2020 · 17 comments
Open

Yarn is not installed #182

GoldFlsh opened this issue Aug 12, 2020 · 17 comments
Labels
feature request New feature or request to improve the current logic needs eyes

Comments

@GoldFlsh
Copy link

We are using a self-hosted runner and using this action to setup-node and install yarn.

I know on github-hosted runners, yarn is already pre-installed but it would be good if yarn was installed by this action for those of us using self-hosted.

Running setup-node with the following workflow and it works

 with:
    node-version: 12.13.0
    always-auth: true
    registry-url: https://registry.npmjs.org

/usr/bin/tar xz --warning=no-unknown-keyword -C /actions-runner/_work/_temp/febce1c0-314e-4a14-9a65-5bde8a990b71 -f /actions-runner/_work/_temp/d4bf33ab-571e-458e-9495-bd6c5b994814
/actions-runner/_work/_tool/node/12.13.0/x64/bin/node --version
v12.13.0
/actions-runner/_work/_tool/node/12.13.0/x64/bin/npm --version
6.12.0

Note that node and npm are installed.

A later step in the workflow then attempts to run yarn:

Run yarn install --ignore-scripts --frozen-lockfile
/actions-runner/_work/_temp/58e53b82-f9ae-4c68-9cec-75f75831208b.sh: line 1: yarn: command not found
##[error]Process completed with exit code 127.

This of course works on github hosted runners just fine, but since I just migrated to an EC2 instance that doesn't have yarn installed, I am now having issues.

@GoldFlsh
Copy link
Author

GoldFlsh commented Aug 12, 2020

Workaround is to install yarn yourself using npm (after running this action)

- name: Install Yarn
   run: npm install -g yarn

and later can uninstall it -

- name: Uninstall Yarn
   if: always()
   run: npm uninstall -g yarn

While this works, I find it rather hacky. It would be good for this action to not need to rely on github's instances to have yarn package installed.

EDIT:
I wanted to add the documentation acts as if yarn is a given, since it has sections on usage with yarn
Publish to npmjs and GPR with yarn:. Perhaps some clarification in that section that if you're on self-hosted runners you will need to install yarn yourself via npm install -g yarn and uninstall it at the end of your job with npm uninstall -g yarn

@pperzyna
Copy link

GitHub Runners creates a file called .path in the same directory where you have config.sh. It contains the content of $PATH variable, which is further used during the execution of your workflows.

You have to add a directory with the yarn binary. In my case:

/home/github/.yarn/bin`

@vicke4
Copy link

vicke4 commented Jan 12, 2021

@pperzyna thanks! I spent 30mins guessing why it was not working even after updating the path. Seems run.sh has to be restarted.

@konsalex
Copy link

npm install -g yarn

Hey @GoldFlsh , why should we uninstall yarn at the end of a job?

@GoldFlsh
Copy link
Author

@konsalex Since self-hosted runners are shared and are not a clean instance per job execution, like a github hosted runner would be, the job should do its best to clean itself up after a run so that each future workflow run is running on what amounts to a fresh instance.

If you install software during the run, such as yarn, redis, or terraform without uninstalling it, could potentially cause conflicts with other jobs running as the state of the instance moves further away from the original state.

Say then you try to upgrade versions of something in your workflow but since the old version is still installed from a previous run it may use that and create a difficult to debug situation.

As others have mentioned you can pre-install any software on a self-hosted runner so the workflow itself does not have to be responsible for installing anything, which would side-step this altogether.

Up to you, of course, how you best want to manage that 😃

https://docs.github.com/en/actions/hosting-your-own-runners/about-self-hosted-runners#differences-between-github-hosted-and-self-hosted-runners

BlakeRain added a commit to BlakeRain/blakerain.com that referenced this issue Jul 28, 2021
@davide-bertola-deltatre
Copy link

davide-bertola-deltatre commented Nov 4, 2021

Note that if you use with: cache: yarn this action will fail if you don't have yarn pre-installed... But since you need node to install yarn.. you can't get out of this without running this action twice or using other actions.

@chriskilding
Copy link

To +1 on Davide's comment, the lack of yarn install support is a significant obstacle to those of us on self-hosted runners.

The only way to break the chicken-or-egg with: cache: yarn problem, and make caching work on self-hosted runners, is to preinstall yarn on the runner base image (like GitHub does for its own runners). This is not good because then yarn is being managed both by setup-node, and out-of-band by the preinstall step.

@mila411
Copy link

mila411 commented Nov 12, 2021

Hi everyone. I faced the same problem and this may sound really stupid, but I solved it this way:
(Thanks for the tip, @davide-bertola-deltatre)

jobs:
  node-ci:
    runs-on: self-hosted
    steps:
      - uses: actions/checkout@v2

      - name: Setup Nodejs and npm
        uses: actions/setup-node@v2
        with:
          node-version: "14"

      - name: Setup yarn
        run: npm install -g yarn

      - name: Setup Nodejs with yarn caching
        uses: actions/setup-node@v2
        with:
          node-version: "14"
          cache: yarn

      - name: Install dependencies
        run: yarn

ss

NOTE: This way, if you run the yarn uninstall in the step, the Post process will not be able to find yarn and the job will fail.

Actions log shows that the cache was successful, but I am not sure if it is really cached in this case.

Cache Size: ~118 MB (124177777 B)
Cache saved successfully
Cache saved with the key: foo-bar-baz

When I connected to the runner instance that ran the job and ran the yarn command, I got not found, so everything seems to be working. However, this is not an essential solution and I also hope that yarn will be installed with it.

@jasonk
Copy link

jasonk commented Nov 24, 2021

FYI: There isn't a chicken-and-egg problem, you don't need Node to install yarn:

curl -fsSL -o ~/bin/yarn \
  https://github.com/yarnpkg/yarn/releases/download/v1.22.17/yarn-1.22.17.js
chmod +x ~/bin/yarn

@mila411
Copy link

mila411 commented Nov 27, 2021

I think the point of contention here is that we need to return the runner back clean. It's easy enough to install the binaries, but given the hassle of making sure they're purged every time, I'd prefer to see them included under Node's control

@dmitry-shibanov dmitry-shibanov added the feature request New feature or request to improve the current logic label Dec 13, 2021
ps173 added a commit to ps173/noper that referenced this issue Dec 18, 2021
ps173 added a commit to ps173/noper that referenced this issue Dec 18, 2021
@albirrkarim
Copy link

GitHub Runners creates a file called .path in the same directory where you have config.sh. It contains the content of $PATH variable, which is further used during the execution of your workflows.

You have to add a directory with the yarn binary. In my case:

/home/github/.yarn/bin`

Thanks @pperzyna

Let me share my approach, maybe it will useful.

Find out where is the yarn

First on your server run:
which yarn

then you got the yarn location, like this

/home/admin/.nvm/versions/node/v16.14.0/bin/yarn

copy the path (not including the yarn)

/home/admin/.nvm/versions/node/v16.14.0/bin

Edit path

run

nano .path

you got something like

aaaaa:bbbb:cccc

separated with :

then paste the /home/admin/.nvm/versions/node/v16.14.0/bin

so the .path become

aaaaa:bbbb:cccc:/home/admin/.nvm/versions/node/v16.14.0/bin

Don't add the enter or something. Just give the : and paste next to it

Restart runner

You need restart it. so it will load the new path

Mostly you are running with svc.sh then stop it

sudo ./svc.sh stop

Run it again

sudo ./svc.sh start

@joshmeads
Copy link

While Node 17 isn't LTS, moving forward with Node 18 LTS (or >=16.10 LTS) it would be great if corepack enable was automatically run if the cache is yarn or pnpm.

Corepack is part of the node install itself and contains both yarn and pnpm but is currently opt-in. It's also the recommended way to use/install yarn 2+.

You can enable it manually in a single step which fixed the issue for me:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - uses: actions/setup-node@v3
      with:
        node-version: '17'
        cache: 'yarn'
    - run: corepack enable
    - run: yarn install
    - run: yarn lint

@elderapo
Copy link

elderapo commented Jun 8, 2022

While Node 17 isn't LTS, moving forward with Node 18 LTS (or >=16.10 LTS) it would be great if corepack enable was automatically run if the cache is yarn or pnpm.

Corepack is part of the node install itself and contains both yarn and pnpm but is currently opt-in. It's also the recommended way to use/install yarn 2+.

You can enable it manually in a single step which fixed the issue for me:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - uses: actions/setup-node@v3
      with:
        node-version: '17'
        cache: 'yarn'
    - run: corepack enable
    - run: yarn install
    - run: yarn lint

This doesn't solve this issue. It's only working for you because you're using runs-on: ubuntu-latest which has yarn installed by default.

@Aarbel
Copy link

Aarbel commented Aug 17, 2022

I have the error yarn: command not found (just forked your repo on V3)

What is the best way to fix it ?

    # Install node.js and yarn
    - uses: Clovis-team/action-setup-node@v3
      with:
        node-version: '14'

    # Get yarn cache directory path in order to cache it
    - name: Get yarn cache directory path
      id: yarn-cache-dir-path
      run: |
        echo "::set-output name=dir::$(yarn cache dir)"
        echo "::set-output name=version::$(yarn -v)"
      shell: bash

Log in github:

Run Clovis-team/action-setup-node@v3
Attempting to download 14...
Acquiring 14.20.0 - x64 from https://github.com/actions/node-versions/releases/download/14.20.0-2633808318/node-14.20.0-linux-x64.tar.gz
Extracting ...
/usr/bin/tar xz --strip 1 --warning=no-unknown-keyword -C /home/runner/_work/_temp/7bbe90d2-dc57-4b39-b61c-14fb1db60e4f -f /home/runner/_work/_temp/b4832165-c982-406d-bb25-e1f89e2a8268
Adding to the cache ...
Done
Run echo "::set-output name=dir::$(yarn cache dir)"
/home/runner/_work/_temp/a152258c-d989-400f-a9b8-abc6252b12b7.sh: line 1: yarn: command not found
/home/runner/_work/_temp/a152258c-d989-400f-a9b8-abc6252b12b7.sh: line 2: yarn: command not found

@francis-switcho
Copy link

Hi, a lot of great answers here!
Based on @jasonk's solution, to run setup-node on a self-hosted runner we're doing this (2023 edition):

...
- name: Install yarn
        run: |-
          curl -fsSL --create-dirs -o $HOME/bin/yarn \
          https://github.com/yarnpkg/yarn/releases/download/v1.22.19/yarn-1.22.19.js
          chmod +x $HOME/bin/yarn
          echo "$HOME/bin" >> $GITHUB_PATH

- name: Setup node
   uses: actions/setup-node@v3
   with:
      node-version: 16
      cache: 'yarn'
...

Curl needs the --create-dirs option, otherwise it cannot write to a not-yet-existing directory and complains with (23) Failed writing body.
Also, you need to add whatever folder you're copying the yarn executable into to $GITHUB_PATH in order for setup-nodeto pick it up.

deining pushed a commit to deining/setup-node that referenced this issue Nov 9, 2023
* docs: update README.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
claui added a commit to claui/vscode-ifm that referenced this issue Dec 17, 2023
This is useful e.g. for act [1] if using the medium-sized image.

Taken from user @francis-switcho’s comment on actions/setup-node. [2]

[1]: https://github.com/nektos/act#default-runners-are-intentionally-incomplete

[2]: actions/setup-node#182 (comment)
@raegen
Copy link

raegen commented Dec 27, 2023

Let me get this straight, the solution is for the consumers to:

  • download an orphaned yarn bin
  • append the bin location to $GITHUB_PATH
    • which will prove an agony if you hoped to at least keep that shit out of the workflow
  • run actions/setup-node
  • so that we can then exec $ yarn
    That's quite an amusing procedure, I admit.
    So, what about those who are not using or have migrated from the legacy obsolete, unmaintained, unsupported, ancient yarn 1.* (that luckily doesn't provide proper binaries for the last release, but rather the aforementioned orphaned bin we use as a workthefaroundabout) and have pretty much no choice but to use corepack - the official tool for managing node package managers - to install yarn?
    Are we gonna have to exploit quantum state to both install it and not install it for this shit to work, or we adding support for something that node took ownership of? It is not a separate concern anymore.

tldr.
Anyways, done with the rant, debugging self-hosted runners combined with this, well, definitely doesn't qualify as fun.
I'll put up a PR proposal for fixing this later/tomorrow, depending on how much of yarn installation control I end up having to expose.

@Jackbennett
Copy link

Jackbennett commented Jan 11, 2024

Corepack & Yarn is a bad joke.

Prior to this yaml on node 20 use corepack use yarn@* to write e.. "packageManager": "yarn@4.0.2+sha256.825003a0f561ad09a3b1ac4a3b3ea6207af2796d54f62a9420520915721f5186", to package.json which is read by corepack install (it's not this on node 18.)

...
    steps:
      - name: Checkout Repo
        uses: actions/checkout@v4
      - name: Setup Node.js environment
        uses: actions/setup-node@v4
        with:
          node-version: 20
      - run: |
          corepack enable &&
          corepack install # use the in-repo yarn version
      - name: Setup Yarn in Node
        uses: actions/setup-node@v4
        with:
          cache: "yarn" # uses the system node, which was updated prior.
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request to improve the current logic needs eyes
Projects
None yet
Development

No branches or pull requests