Commit 7ab6a17b authored by Zach Pomerantz's avatar Zach Pomerantz Committed by GitHub

build: utilize the node_modules/.cache (#6364)

* build: add caching to eslint

* build: add caching to jest

* build: add caching to tsc

* build: add caching to actions

* fix: upgrade upload-artifact to v3

* build: update craco eslint cacheLocation

* fix: pr nits
parent 7ad13c96
name: Setup name: Setup
description: checkout repo, setup node, and install node_modules
runs: runs:
using: composite using: composite
steps: steps:
...@@ -10,12 +12,14 @@ runs: ...@@ -10,12 +12,14 @@ runs:
registry-url: https://registry.npmjs.org registry-url: https://registry.npmjs.org
cache: yarn cache: yarn
# node_modules/.cache is intentionally omitted, as this is used for build tool caches.
- uses: actions/cache@v3 - uses: actions/cache@v3
id: install-cache id: install-cache
with: with:
path: node_modules/ path: |
node_modules
!node_modules/.cache
key: ${{ runner.os }}-install-${{ hashFiles('**/yarn.lock') }} key: ${{ runner.os }}-install-${{ hashFiles('**/yarn.lock') }}
- if: steps.install-cache.outputs.cache-hit != 'true' - if: steps.install-cache.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile --ignore-scripts run: yarn install --frozen-lockfile --ignore-scripts
shell: bash shell: bash
name: Test name: Test
# Many build steps have their own caches, so each job has its own cache to improve subsequent build times.
# Build tools are configured to cache cache to node_modules/.cache, so this is cached independently of node_modules.
# See https://jongleberry.medium.com/speed-up-your-ci-and-dx-with-node-modules-cache-ac8df82b7bb0.
on: on:
push: push:
branches: branches:
...@@ -14,6 +18,12 @@ jobs: ...@@ -14,6 +18,12 @@ jobs:
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: ./.github/actions/setup - uses: ./.github/actions/setup
- uses: actions/cache@v3
id: eslint-cache
with:
path: node_modules/.cache
key: ${{ runner.os }}-eslint-${{ hashFiles('**/yarn.lock') }}-${{ github.run_id }}
restore-keys: ${{ runner.os }}-eslint-${{ hashFiles('**/yarn.lock') }}-
- run: yarn lint - run: yarn lint
typecheck: typecheck:
...@@ -21,6 +31,12 @@ jobs: ...@@ -21,6 +31,12 @@ jobs:
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: ./.github/actions/setup - uses: ./.github/actions/setup
- uses: actions/cache@v3
id: tsc-cache
with:
path: node_modules/.cache
key: ${{ runner.os }}-tsc-${{ hashFiles('**/yarn.lock') }}-${{ github.run_id }}
restore-keys: ${{ runner.os }}-tsc-${{ hashFiles('**/yarn.lock') }}-
- run: yarn prepare - run: yarn prepare
- run: yarn typecheck - run: yarn typecheck
...@@ -36,6 +52,12 @@ jobs: ...@@ -36,6 +52,12 @@ jobs:
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: ./.github/actions/setup - uses: ./.github/actions/setup
- uses: actions/cache@v3
id: jest-cache
with:
path: node_modules/.cache
key: ${{ runner.os }}-jest-${{ hashFiles('**/yarn.lock') }}-${{ github.run_id }}
restore-keys: ${{ runner.os }}-jest-${{ hashFiles('**/yarn.lock') }}-
- run: yarn prepare - run: yarn prepare
- run: yarn test - run: yarn test
- uses: codecov/codecov-action@v3 - uses: codecov/codecov-action@v3
...@@ -49,9 +71,15 @@ jobs: ...@@ -49,9 +71,15 @@ jobs:
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: ./.github/actions/setup - uses: ./.github/actions/setup
- uses: actions/cache@v3
id: build-cache
with:
path: node_modules/.cache
key: ${{ runner.os }}-build-${{ hashFiles('**/yarn.lock') }}-${{ github.run_id }}
restore-keys: ${{ runner.os }}-build-${{ hashFiles('**/yarn.lock') }}-
- run: yarn prepare - run: yarn prepare
- run: yarn build - run: yarn build
- uses: actions/upload-artifact@v2 - uses: actions/upload-artifact@v3
with: with:
name: build name: build
path: build path: build
...@@ -63,51 +91,38 @@ jobs: ...@@ -63,51 +91,38 @@ jobs:
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: ./.github/actions/setup - uses: ./.github/actions/setup
- uses: actions/download-artifact@v2 - uses: actions/download-artifact@v3
with: with:
name: build name: build
path: build path: build
- run: yarn test:size - run: yarn test:size
cypress-build: cypress-test-matrix:
needs: [build]
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: cypress/browsers:node-18.14.1-chrome-111.0.5563.64-1-ff-111.0-edge-111.0.1661.43-1 container: cypress/browsers:node-18.14.1-chrome-111.0.5563.64-1-ff-111.0-edge-111.0.1661.43-1
strategy:
fail-fast: false
matrix:
containers: [1, 2, 3, 4]
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: ./.github/actions/setup - uses: ./.github/actions/setup
- uses: actions/cache@v3 - uses: actions/cache@v3
id: cypress-cache id: cypress-cache
with: with:
path: /root/.cache/Cypress path: /root/.cache/Cypress
key: ${{ runner.os }}-cypress-${{ hashFiles('yarn.lock') }} key: ${{ runner.os }}-cypress
- if: steps.cypress-cache.outputs.cache-hit != 'true' - run: |
run: |
yarn cypress install yarn cypress install
yarn cypress info yarn cypress info
cypress-test-matrix: - uses: actions/download-artifact@v3
needs: [build, cypress-build]
runs-on: ubuntu-latest
container: cypress/browsers:node-18.14.1-chrome-111.0.5563.64-1-ff-111.0-edge-111.0.1661.43-1
strategy:
fail-fast: false
matrix:
containers: [1, 2, 3, 4]
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup
- uses: actions/download-artifact@v2
with: with:
name: build name: build
path: build path: build
- uses: actions/cache@v3
id: cypress-cache
with:
path: /root/.cache/Cypress
key: ${{ runner.os }}-cypress-${{ hashFiles('yarn.lock') }}
- if: steps.cypress-cache.outputs.cache-hit != 'true'
run: yarn cypress install
- uses: cypress-io/github-action@v4 - uses: cypress-io/github-action@v4
with: with:
......
/* eslint-env node */ /* eslint-env node */
const { VanillaExtractPlugin } = require('@vanilla-extract/webpack-plugin') const { VanillaExtractPlugin } = require('@vanilla-extract/webpack-plugin')
const { execSync } = require('child_process') const { execSync } = require('child_process')
const EsLintWebpackPlugin = require('eslint-webpack-plugin')
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin') const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const { DefinePlugin } = require('webpack') const { DefinePlugin } = require('webpack')
const isProduction = process.env.NODE_ENV === 'production'
const commitHash = execSync('git rev-parse HEAD').toString().trim() const commitHash = execSync('git rev-parse HEAD').toString().trim()
const isProduction = process.env.NODE_ENV === 'production'
// Linting and type checking are only necessary as part of development and testing.
// Omit them from production builds, as they slow down the feedback loop.
const shouldLintOrTypeCheck = !isProduction
module.exports = { module.exports = {
babel: { babel: {
...@@ -21,9 +23,22 @@ module.exports = { ...@@ -21,9 +23,22 @@ module.exports = {
}, },
}, },
}, },
eslint: {
enable: shouldLintOrTypeCheck,
pluginOptions(eslintConfig) {
return Object.assign(eslintConfig, {
cache: true,
cacheLocation: 'node_modules/.cache/eslint/',
})
},
},
typescript: {
enableTypeChecking: shouldLintOrTypeCheck,
},
jest: { jest: {
configure(jestConfig) { configure(jestConfig) {
return Object.assign({}, jestConfig, { return Object.assign(jestConfig, {
cacheDirectory: 'node_modules/.cache/jest',
transformIgnorePatterns: ['@uniswap/conedison/format', '@uniswap/conedison/provider'], transformIgnorePatterns: ['@uniswap/conedison/format', '@uniswap/conedison/provider'],
moduleNameMapper: { moduleNameMapper: {
'@uniswap/conedison/format': '@uniswap/conedison/dist/format', '@uniswap/conedison/format': '@uniswap/conedison/dist/format',
...@@ -35,18 +50,7 @@ module.exports = { ...@@ -35,18 +50,7 @@ module.exports = {
webpack: { webpack: {
plugins: [new VanillaExtractPlugin({ identifiers: 'short' })], plugins: [new VanillaExtractPlugin({ identifiers: 'short' })],
configure: (webpackConfig) => { configure: (webpackConfig) => {
webpackConfig.plugins = webpackConfig.plugins webpackConfig.plugins = webpackConfig.plugins.map((plugin) => {
.filter((plugin) => {
// Type checking and linting are only necessary as part of development and testing.
// Omit them from production builds, as they slow down the feedback loop.
if (isProduction) {
if (plugin instanceof ForkTsCheckerWebpackPlugin) return false
if (plugin instanceof EsLintWebpackPlugin) return false
}
return true
})
.map((plugin) => {
// Extend process.env with dynamic values (eg commit hash). // Extend process.env with dynamic values (eg commit hash).
// This will make dynamic values available to JavaScript only, not to interpolated HTML (ie index.html). // This will make dynamic values available to JavaScript only, not to interpolated HTML (ie index.html).
if (plugin instanceof DefinePlugin) { if (plugin instanceof DefinePlugin) {
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
"start": "craco start", "start": "craco start",
"build": "craco build", "build": "craco build",
"serve": "serve build -l 3000", "serve": "serve build -l 3000",
"lint": "yarn eslint --ignore-path .gitignore .", "lint": "yarn eslint --ignore-path .gitignore --cache --cache-location node_modules/.cache/eslint/ .",
"typecheck": "tsc --noEmit", "typecheck": "tsc --noEmit",
"test": "craco test --coverage", "test": "craco test --coverage",
"test:size": "node scripts/test-size.js", "test:size": "node scripts/test-size.js",
...@@ -100,7 +100,7 @@ ...@@ -100,7 +100,7 @@
"@uniswap/eslint-config": "^1.1.1", "@uniswap/eslint-config": "^1.1.1",
"@vanilla-extract/babel-plugin": "^1.1.7", "@vanilla-extract/babel-plugin": "^1.1.7",
"@vanilla-extract/webpack-plugin": "^2.1.11", "@vanilla-extract/webpack-plugin": "^2.1.11",
"cypress": "^10.3.1", "cypress": "10.3.1",
"env-cmd": "^10.1.0", "env-cmd": "^10.1.0",
"eslint": "^7.11.0", "eslint": "^7.11.0",
"jest-fetch-mock": "^3.0.3", "jest-fetch-mock": "^3.0.3",
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
"allowSyntheticDefaultImports": true, "allowSyntheticDefaultImports": true,
"alwaysStrict": true, "alwaysStrict": true,
"baseUrl": "src", "baseUrl": "src",
"composite": true,
"downlevelIteration": true, "downlevelIteration": true,
"esModuleInterop": true, "esModuleInterop": true,
"forceConsistentCasingInFileNames": true, "forceConsistentCasingInFileNames": true,
...@@ -23,9 +24,10 @@ ...@@ -23,9 +24,10 @@
"strict": true, "strict": true,
"strictNullChecks": true, "strictNullChecks": true,
"target": "es5", "target": "es5",
"tsBuildInfoFile": "node_modules/.cache/.tsbuildinfo",
"types": ["jest"], "types": ["jest"],
"useUnknownInCatchVariables": false "useUnknownInCatchVariables": false
}, },
"exclude": ["node_modules", "cypress"], "exclude": ["node_modules", "cypress"],
"include": ["src/**/*"] "include": ["src/**/*", "src/**/*.json"]
} }
...@@ -8320,7 +8320,7 @@ cyclist@^1.0.1: ...@@ -8320,7 +8320,7 @@ cyclist@^1.0.1:
resolved "https://registry.yarnpkg.com/cyclist/-/cyclist-1.0.1.tgz#596e9698fd0c80e12038c2b82d6eb1b35b6224d9" resolved "https://registry.yarnpkg.com/cyclist/-/cyclist-1.0.1.tgz#596e9698fd0c80e12038c2b82d6eb1b35b6224d9"
integrity sha1-WW6WmP0MgOEgOMK4LW6xs1tiJNk= integrity sha1-WW6WmP0MgOEgOMK4LW6xs1tiJNk=
cypress@*, cypress@^10.3.1: cypress@*, cypress@10.3.1:
version "10.3.1" version "10.3.1"
resolved "https://registry.yarnpkg.com/cypress/-/cypress-10.3.1.tgz#7fab4ef43481c05a9a17ebe9a0ec860e15b95a19" resolved "https://registry.yarnpkg.com/cypress/-/cypress-10.3.1.tgz#7fab4ef43481c05a9a17ebe9a0ec860e15b95a19"
integrity sha512-As9HrExjAgpgjCnbiQCuPdw5sWKx5HUJcK2EOKziu642akwufr/GUeqL5UnCPYXTyyibvEdWT/pSC2qnGW/e5w== integrity sha512-As9HrExjAgpgjCnbiQCuPdw5sWKx5HUJcK2EOKziu642akwufr/GUeqL5UnCPYXTyyibvEdWT/pSC2qnGW/e5w==
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment