How to cache yarn packages in GitHub Actions

前端 未结 3 1000
忘掉有多难
忘掉有多难 2021-01-04 06:02

I am using GitHub Actions to build my TypeScript project. Everytime I run action I am waiting 3 minutes for all dependencies to get installed.

Is there way to cache

3条回答
  •  既然无缘
    2021-01-04 06:59

    As mentioned in the comment next to the id field for the caching step:

    Use this to check for cache-hit (steps.yarn-cache.outputs.cache-hit != 'true')

    You're missing a conditional if property that determines whether the step should be run:

    - name: Install yarn
      run: npm install -g yarn
    
    - name: Install project dependencies
      if: steps.yarn-cache.outputs.cache-hit != 'true' # Over here!
      run: yarn
    

    P.S. You should probably use the Setup NodeJS GitHub Action that additionally sets up Yarn for you:

    - uses: actions/setup-node@v1
      with:
        node-version: '10.x' # The version spec of the version to use.
    

    See the action.yml file for a full list of valid inputs.


    EDIT: As it turns out, Yarn is included in the list of software installed on the GitHub-hosted Ubuntu 18.04.4 LTS (ubuntu-latest/ubuntu-18.04) runner, so there's no need to include a step to globally install Yarn.

提交回复
热议问题