Skip to content

Commit

Permalink
Minimum version to node 18.12 and yarn update (#64)
Browse files Browse the repository at this point in the history
* chore: node 18.12 as minimum version

* chore: node 18.12 as minimum version

* chore: node 18.12 as minimum version

* chore: update for yarn 4

* chore: update for yarn 4
  • Loading branch information
belgattitude authored Sep 16, 2023
1 parent f9eb0cc commit a1a53ae
Show file tree
Hide file tree
Showing 13 changed files with 1,022 additions and 890 deletions.
5 changes: 5 additions & 0 deletions .changeset/four-ghosts-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@nextvalid/zod-request': minor
---

Drop node 16.x / upgrade to yarn 4.0.0-rc.50
9 changes: 9 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"mode": "pre",
"tag": "canary",
"initialVersions": {
"@examples/next-classic": "0.10.1",
"@nextvalid/zod-request": "0.4.0"
},
"changesets": []
}
118 changes: 89 additions & 29 deletions .github/actions/yarn-nm-install/action.yml
Original file line number Diff line number Diff line change
@@ -1,64 +1,124 @@
########################################################################################
# "yarn install" composite action for yarn 2/3/4+ and "nodeLinker: node-modules" #
# "yarn install" composite action for yarn 3/4+ and "nodeLinker: node-modules" #
#--------------------------------------------------------------------------------------#
# Cache: #
# - Downloaded zip archive (multi-arch, preserved across yarn.lock changes) #
# - Yarn install state (discarded in yarn.lock changes) #
# References: #
# - bench: https://gist.github.com/belgattitude/0ecd26155b47e7be1be6163ecfbb0f0b #
# - vs @setup/node: https://github.com/actions/setup-node/issues/325 #
# Requirement: @setup/node should be run before #
# #
# Usage in workflows steps: #
# #
# - name: 📥 Monorepo install #
# uses: ./.github/actions/yarn-nm-install #
# with: #
# enable-corepack: false # (default = 'false') #
# cache-npm-cache: false # (default = 'true') #
# cwd: ${{ github.workspace }}/apps/my-app # (default = '.') #
# cache-prefix: add cache key prefix # (default = 'default') #
# cache-node-modules: false # (default = 'false') #
# cache-install-state: false # (default = 'false') #
# #
# Reference: #
# - latest: https://gist.github.com/belgattitude/042f9caf10d029badbde6cf9d43e400a #
# #
# Versions: #
# - 1.1.0 - 22-07-2023 - Option to enable npm global cache folder. #
# - 1.0.4 - 15-07-2023 - Fix corepack was always enabled. #
# - 1.0.3 - 05-07-2023 - YARN_ENABLE_MIRROR to false (speed up cold start) #
# - 1.0.2 - 02-06-2023 - install-state default to false #
# - 1.0.1 - 29-05-2023 - cache-prefix doc #
# - 1.0.0 - 27-05-2023 - new input: cache-prefix #
########################################################################################

name: 'Monorepo install (yarn)'
description: 'Run yarn install with node_modules linker and cache enabled'
inputs:
skip-prisma-postinstall-generate:
description: 'Avoid prisma to automatically generate schema on postinstall'
cwd:
description: "Changes node's process.cwd() if the project is not located on the root. Default to process.cwd()"
required: false
default: '.'
cache-prefix:
description: 'Add a specific cache-prefix'
required: false
default: 'default'
cache-npm-cache:
description: 'Cache npm global cache folder often used by node-gyp, prebuild binaries (invalidated on lock/os/node-version)'
required: false
default: 'true'
cache-node-modules:
description: 'Cache node_modules, might speed up link step (invalidated lock/os/node-version/branch)'
required: false
default: 'false'
cache-install-state:
description: 'Cache yarn install state, might speed up resolution step when node-modules cache is activated (invalidated lock/os/node-version/branch)'
required: false
default: 'false'
enable-corepack:
description: 'Enable corepack'
required: false
default: 'true'

runs:
using: 'composite'

steps:
- name: Expose yarn config as "$GITHUB_OUTPUT"
- name: ⚙️ Enable Corepack
if: inputs.enable-corepack == 'true'
shell: bash
working-directory: ${{ inputs.cwd }}
run: corepack enable

- name: ⚙️ Expose yarn config as "$GITHUB_OUTPUT"
id: yarn-config
shell: bash
working-directory: ${{ inputs.cwd }}
env:
YARN_ENABLE_GLOBAL_CACHE: 'false'
run: |
echo "CACHE_FOLDER=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
echo "CURRENT_NODE_VERSION="node-$(node --version)"" >> $GITHUB_OUTPUT
echo "CURRENT_BRANCH=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's,/,-,g')" >> $GITHUB_OUTPUT
echo "NPM_GLOBAL_CACHE_FOLDER=$(npm config get cache)" >> $GITHUB_OUTPUT
#- name: Debug cache-dir
# shell: bash
# run: echo "CACHE_FOLDER = ${{ steps.yarn-config.outputs.CACHE_FOLDER }}"

# Yarn rotates the downloaded cache archives.
# @see https://github.com/actions/setup-node/issues/325
- name: Restore yarn cache
- name: ♻️ Restore yarn cache
uses: actions/cache@v3
id: yarn-download-cache
with:
path: ${{ steps.yarn-config.outputs.CACHE_FOLDER }}
key: yarn-download-cache-${{ hashFiles('yarn.lock') }}
key: yarn-download-cache-${{ inputs.cache-prefix }}-${{ hashFiles(format('{0}/yarn.lock', inputs.cwd), format('{0}/.yarnrc.yml', inputs.cwd)) }}
restore-keys: |
yarn-download-cache-
yarn-download-cache-${{ inputs.cache-prefix }}-
- name: ♻️ Restore node_modules
if: inputs.cache-node-modules == 'true'
id: yarn-nm-cache
uses: actions/cache@v3
with:
path: ${{ inputs.cwd }}/**/node_modules
key: yarn-nm-cache-${{ inputs.cache-prefix }}-${{ runner.os }}-${{ steps.yarn-config.outputs.CURRENT_NODE_VERSION }}-${{ steps.yarn-config.outputs.CURRENT_BRANCH }}-${{ hashFiles(format('{0}/yarn.lock', inputs.cwd), format('{0}/.yarnrc.yml', inputs.cwd)) }}

- name: ♻️ Restore global npm cache folder
if: inputs.cache-npm-cache == 'true'
id: npm-global-cache
uses: actions/cache@v3
with:
path: ${{ steps.yarn-config.outputs.NPM_GLOBAL_CACHE_FOLDER }}
key: npm-global-cache-${{ inputs.cache-prefix }}-${{ runner.os }}-${{ steps.yarn-config.outputs.CURRENT_NODE_VERSION }}-${{ hashFiles(format('{0}/yarn.lock', inputs.cwd), format('{0}/.yarnrc.yml', inputs.cwd)) }}

# Invalidated on yarn.lock changes
- name: Restore yarn install state
- name: ♻️ Restore yarn install state
if: inputs.cache-install-state == 'true' && inputs.cache-node-modules == 'true'
id: yarn-install-state-cache
uses: actions/cache@v3
with:
path: |
.yarn/ci-cache/
key: ${{ runner.os }}-yarn-install-state-cache-${{ hashFiles('yarn.lock', '.yarnrc.yml') }}
path: ${{ inputs.cwd }}/.yarn/ci-cache
key: yarn-install-state-cache-${{ inputs.cache-prefix }}-${{ runner.os }}-${{ steps.yarn-config.outputs.CURRENT_NODE_VERSION }}-${{ steps.yarn-config.outputs.CURRENT_BRANCH }}-${{ hashFiles(format('{0}/yarn.lock', inputs.cwd), format('{0}/.yarnrc.yml', inputs.cwd)) }}

- name: Install dependencies
- name: 📥 Install dependencies
shell: bash
working-directory: ${{ inputs.cwd }}
run: yarn install --immutable --inline-builds
env:
# CI optimizations. Overrides yarnrc.yml options (or their defaults) in the CI action.
# Overrides/align yarnrc.yml options (v3, v4) for a CI context
YARN_ENABLE_GLOBAL_CACHE: 'false' # Use local cache folder to keep downloaded archives
YARN_NM_MODE: 'hardlinks-local' # Hardlinks-(local|global) reduces io / node_modules size
YARN_INSTALL_STATE_PATH: .yarn/ci-cache/install-state.gz # Very small speedup when lock does not change
YARN_ENABLE_MIRROR: 'false' # Prevent populating global cache for caches misses (local cache only)
YARN_NM_MODE: 'hardlinks-local' # Reduce node_modules size
YARN_INSTALL_STATE_PATH: '.yarn/ci-cache/install-state.gz' # Might speed up resolution step when node_modules present
# Other environment variables
HUSKY: '0' # By default do not run HUSKY install
PRISMA_SKIP_POSTINSTALL_GENERATE: ${{ inputs.skip-prisma-postinstall-generate }}
12 changes: 6 additions & 6 deletions .github/workflows/ci-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x, 16.x]
node-version: [18.x]
steps:
- uses: actions/checkout@v3

Expand All @@ -44,19 +44,19 @@ jobs:
uses: ./.github/actions/yarn-nm-install

- name: Pre build packages
run: yarn workspaces foreach -v --exclude '@examples/*' --no-private run build
run: yarn workspaces foreach -W --exclude '@examples/*' --no-private run build

- name: Typecheck (path aliases)
run: yarn workspaces foreach -v --from '@examples/*' run typecheck
run: yarn workspaces foreach -W --from '@examples/*' run typecheck

- name: Typecheck (no paths aliases)
run: yarn workspaces foreach -v --from '@examples/*' run typecheck-no-paths
run: yarn workspaces foreach -W --from '@examples/*' run typecheck-no-paths

- name: Lint
run: yarn workspaces foreach -v --from '@examples/*' run lint
run: yarn workspaces foreach -W --from '@examples/*' run lint

- name: Build example apps
run: yarn workspaces foreach -v --from '@examples/*' run build
run: yarn workspaces foreach -W --from '@examples/*' run build
env:
NEXTJS_IGNORE_ESLINT: true
NEXTJS_IGNORE_TYPECHECK: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-monorepo-integrity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
node-version: [18.x]
steps:
- uses: actions/checkout@v3

Expand Down
23 changes: 8 additions & 15 deletions .github/workflows/ci-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x, 18.x]
node-version: [18.x, 20.x]
steps:
- uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -62,28 +62,22 @@ jobs:
${{ runner.os }}-packages-cache-${{ hashFiles('**/yarn.lock') }}-
- name: Typecheck
run: |
yarn workspaces foreach -tv --no-private --since=origin/main run typecheck
run: yarn workspaces foreach -W -tv --from="./packages/**" run typecheck

- name: ESLint checks
run: |
yarn workspaces foreach -tv --no-private --since=origin/main run lint
run: yarn workspaces foreach -W -tv --from="./packages/**" run lint

- name: Unit tests
run: |
yarn workspaces foreach -tv --no-private run test-unit --coverage
run: yarn workspaces foreach -W -tv --from="./packages/**" run test-unit --coverage

- name: Build packages
run: |
yarn workspaces foreach -tv --no-private --since=origin/main run build
run: yarn workspaces foreach -W -tv --from="./packages/**" run build

- name: Check build for size-limits
run: |
yarn workspaces foreach -tv --no-private --since=origin/main run check-size
run: yarn workspaces foreach -W -tv --from="./packages/**" run check-size

- name: Check build for ecmascript compliance
run: |
yarn workspaces foreach -tv --no-private --since=origin/main run check-dist
run: yarn workspaces foreach -W -tv --from="./packages/**" run check-dist

- name: Codecov upload
if: matrix.node-version == '18.x'
Expand All @@ -97,5 +91,4 @@ jobs:
working-directory: ${{ github.workspace }}

- name: Check doc can be built
run: |
yarn workspaces foreach -tv --no-private --since=origin/main run build-doc
run: yarn workspaces foreach -W -tv --from="./packages/**" run build-doc
4 changes: 2 additions & 2 deletions .github/workflows/release-or-version-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ jobs:
# @link https://github.com/actions/checkout#fetch-all-history-for-all-tags-and-branches
fetch-depth: 0

- name: Use Node.js 16.x
- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 16.x
node-version: 18.x

- name: 📥 Monorepo install
uses: ./.github/actions/yarn-nm-install
Expand Down
Loading

0 comments on commit a1a53ae

Please sign in to comment.