facebook / jscodeshift

A JavaScript codemod toolkit.
https://jscodeshift.com
MIT License
9.11k stars 468 forks source link

chore(github-actions): Use setup-node action to cache dependencies #542

Closed jongwooo closed 1 year ago

jongwooo commented 1 year ago

Description

Updated workflows to cache dependencies using actions/setup-node. setup-node@v3 or newer has caching built-in.

About caching workflow dependencies

Jobs on GitHub-hosted runners start in a clean virtual environment and must download dependencies each time, causing increased network utilization, longer runtime, and increased cost. To help speed up the time it takes to recreate files like dependencies, GitHub can cache files that frequently use in workflows.

Solutions

Node.js projects can run faster on GitHub Actions by enabling dependency caching on the setup-node action.

AS-IS

- name: Use Node.js ${{ matrix.node-version }}
  uses: actions/setup-node@v2
  with:
    node-version: ${{ matrix.node-version }}

TO-BE

- name: Use Node.js ${{ matrix.node-version }}
  uses: actions/setup-node@v3
  with:
    node-version: ${{ matrix.node-version }}
    cache: yarn

It’s literally a one line change to pass the cache: yarn input parameter.

References

Daniel15 commented 1 year ago

Thanks! I imagine there's many projects that need this same change. A large number of builds don't properly cache their dependencies.