Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/c-hive/gha-yarn-cache
1-liner yarn install cache for GitHub Actions
https://github.com/c-hive/gha-yarn-cache
Last synced: 6 days ago
JSON representation
1-liner yarn install cache for GitHub Actions
- Host: GitHub
- URL: https://github.com/c-hive/gha-yarn-cache
- Owner: c-hive
- License: mit
- Archived: true
- Created: 2020-05-21T19:39:06.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-08-13T11:38:58.000Z (about 2 years ago)
- Last Synced: 2024-05-23T02:41:09.890Z (6 months ago)
- Language: JavaScript
- Size: 77.1 KB
- Stars: 91
- Watchers: 4
- Forks: 15
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-actions - Cache Yarn Dependencies
- fucking-awesome-actions - Cache Yarn Dependencies
- awesome-workflows - Cache Yarn Dependencies
README
## Deprecated
This functionality is now part of [`actions/setup-node`](https://github.com/actions/setup-node):
```yml
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '16'
cache: 'yarn'
```---
# gha-yarn-cache
#### 1-liner yarn install cache for GitHub Actions
Status and support
- ✔ stable
- ✔ supported
- ✖ no ongoing development[![CI](/../../workflows/CI/badge.svg?branch=master)](/../../actions)
GitHub Action caches improve build times and reduce network dependencies. However, writing the correct cache logic is [tricky](https://github.com/actions/cache/blob/9ab95382c899bf0953a0c6c1374373fc40456ffe/examples.md#node---yarn). You need to understand how the [cache action](https://github.com/actions/cache) (keys and restore keys) work. Did you know you're not supposed to cache the `node_modules` folder? The setup is different per OS and takes a lot of space in your workflows. Not anymore!
`gha-yarn-cache` is a simple 1-liner that covers all use-cases, correctly:
- Caches the Yarn cache directory instead of `node-modules` [as recommended](https://github.com/actions/cache/blob/9ab95382c899bf0953a0c6c1374373fc40456ffe/examples.md#node---yarn)
- Works on Ubuntu, MacOS and Windows
- Restore keys take the OS into account [as recommended](https://github.com/actions/cache/blob/9ab95382c899bf0953a0c6c1374373fc40456ffe/examples.md#node---yarn)
- Builds on the [native cache functionality of GitHub Actions](https://github.com/actions/toolkit/tree/master/packages/cache), same as [v2 of the generic cache action](https://github.com/actions/cache/issues/55#issuecomment-629433225)## Usage
Add this step before `yarn install`:
```yml
uses: c-hive/gha-yarn-cache@v2
```For example:
`.github/workflows/ci.yml`
```yml
name: CIon: [push]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1- uses: c-hive/gha-yarn-cache@v2
# with:
# directory: server # Optional, speficy the folder of yarn.lock if not in the root directory- name: Install JS dependencies
run: yarn install
- name: Test
run: yarn test
```### Solution comparison
[Native](https://github.com/actions/cache/blob/9ab95382c899bf0953a0c6c1374373fc40456ffe/examples.md#node---yarn)
```yml
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"- uses: actions/cache@v1
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
````gha-yarn-cache`
```yml
- uses: c-hive/gha-yarn-cache@v2
```## Conventions
This project follows [C-Hive guides](https://github.com/c-hive/guides) for code style, way of working and other development concerns.
## License
The project is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).