Skip to content
This repository has been archived by the owner on Aug 13, 2022. It is now read-only.

Commit

Permalink
Add implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
thisismydesign committed May 21, 2020
1 parent 854d613 commit 046e64e
Show file tree
Hide file tree
Showing 11 changed files with 1,737 additions and 1,795 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
30 changes: 30 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Build

on:
push:
branches:
- master

env:
node_version: "12.x"

jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: ${{ env.node_version }}
# - uses: c-hive/gha-npm-cache@v1
- name: Install JS dependencies
run: yarn install
- name: Build
run: yarn run build
- name: Commit and push distified version to master
uses: stefanzweifel/git-auto-commit-action@v4.1.1
with:
commit_message: 'Update distified version'
file_pattern: 'dist/**/*.js'
33 changes: 3 additions & 30 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,8 @@ jobs:
uses: actions/setup-node@v1
with:
node-version: ${{ env.node_version }}
- name: Cache node_modules
uses: actions/cache@v1
with:
path: node_modules
key: ${{ runner.OS }}-node_modules-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node_modules-
# - uses: c-hive/gha-npm-cache@v1
- name: Install JS dependencies
run: ls package-lock.json && npm install || yarn install
run: yarn install
- name: Lint
run: ls package-lock.json && npm run lint || yarn lint

test:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v1
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: ${{ env.node_version }}
- name: Cache node_modules
uses: actions/cache@v1
with:
path: node_modules
key: ${{ runner.OS }}-node_modules-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node_modules-
- name: Install JS dependencies
run: ls package-lock.json && npm install || yarn install
- name: Test
run: ls package-lock.json && npm run test || yarn test
run: yarn lint
23 changes: 23 additions & 0 deletions .github/workflows/run.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Run

on: [push]

env:
node_version: "12.x"

jobs:
run-action:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v1
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: ${{ env.node_version }}
- name: Install JS dependencies
run: yarn install
- name: Build
run: yarn build
- name: Run action
uses: ./
63 changes: 48 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,51 @@
# JavaScript Boilerplate

#### A boilerplate that sets the grounds for any kind of JS development. More generic things, less specific things.

It has
- formatting
- linting
- editor options
- CI via native GitHub Actions
- pre-commit hook
- gitignore
- [~~npmignore~~ npm files](https://github.com/c-hive/guides/blob/2d3e41b73515a571dd78576e02d2fd15fe786d9e/js/package.md#what-to-include)
- [dependency comments](https://github.com/c-hive/guides/blob/2d3e41b73515a571dd78576e02d2fd15fe786d9e/js/best-practices.md#comment-dependencies-in-the-packagejson)
- dependency security fixes
- npm version requirement [to avoid `package-lock` ping-pong](https://github.com/c-hive/guides/blob/24ce093e59f89374ed2bf0a2e1fc5c45e5490044/js/best-practices.md#specify-npm-version-requirements-to-avoid-package-lock-ping-pong)
# gha-yarn-cache

#### 1-liner yarn install cache for GitHub Actions

Status and support

- ✔ stable
- ✔ supported
- ✔ 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@v1
```
For example:
`.github/workflows/ci.yml`
```yml
name: CI
on: [push]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: c-hive/gha-yarn-cache@v1
- name: Install JS dependencies
run: yarn install
- name: Test
run: yarn test
```

## Conventions

Expand Down
11 changes: 11 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: 'Yarn install cache'
author: 'c-hive'
description: '1-liner yarn install cache for GitHub Actions'
runs:
using: 'node12'
main: 'dist/restore/index.js'
post: 'dist/save/index.js'
post-if: 'success()'
outputs:
cache-hit:
description: 'A boolean value to indicate an exact match was found for the primary key'
Loading

0 comments on commit 046e64e

Please sign in to comment.