Skip to content

Latest commit

 

History

History
45 lines (26 loc) · 2.26 KB

yarn-test-lint.md

File metadata and controls

45 lines (26 loc) · 2.26 KB

Yarn (Test & Lint)

Most Javascript/Typescript packages or applications will use Npm or Yarn as their package manager. I have chosen to standardize my own repositories on Yarn.

Generally, repositories will want to run their specified test and lint scripts through the package manager to verify the correctness of new changes. This workflow makes it simple to run these commands in a GitHub Actions Workflow.

Features

Pull Requests Triggering

By using the following trigger syntax:

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

The workflow will only trigger on new commits to main and Pull Requests opened against main. This will apply to both PRs created from the repo origin, and any PRs created from forks.

The one downside is the workflow will not be run on new commits to any other remote branch on origin unless a PR is opened. If a second develop branch needs to be maintained it will need to be added to these triggers.

Link

Matrix Strategy

The workflow uses a Matrix Strategy declaration which makes it simple to run multiple workflows in parallel for different Node.js versions.

Dependency Caching

The workflow uses GitHub's standard actions/cache action to cache the downloaded yarn dependencies.

It is no longer based on their standard example config. Caching the .yarn/cache directory was still taking nearly the full time to run a yarn install.

Based on this article I've switch to caching the node_modules directory itself instead of the cache. This reduces the install time to 1-2 seconds if a cache hit occurred.

The cache key is generated by hashing the yarn.lock file. You will get a cache miss (and re-install) if you update the yarn dependencies.

Improvements

I would like to improve this workflow into more modular jobs. That way you get more easily distinguished output in the Actions Tab.

Standard Workflow