Skip to content

Commit

Permalink
ci: fix broken yarn install flow
Browse files Browse the repository at this point in the history
  • Loading branch information
secundant committed Nov 25, 2023
1 parent 7fec3e9 commit 5a69114
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 17 deletions.
56 changes: 56 additions & 0 deletions .github/actions/yarn-install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Adopted from https://github.com/belgattitude/nextjs-monorepo-example/blob/main/.github/actions/yarn-nm-install/action.yml

name: 'Monorepo install (yarn)'
description: 'Run yarn install with node_modules linker and cache enabled'
inputs:
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'

runs:
using: 'composite'

steps:
- name: ⚙️ Enable Corepack
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: ♻️ Restore yarn cache
uses: actions/cache@v3
id: yarn-download-cache
with:
path: ${{ steps.yarn-config.outputs.CACHE_FOLDER }}
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-${{ inputs.cache-prefix }}-
- name: 📥 Install dependencies
shell: bash
working-directory: ${{ inputs.cwd }}
run: yarn install --immutable --inline-builds
env:
# 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_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
19 changes: 7 additions & 12 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,22 @@ jobs:
node-version: [20.x]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: nrwl/nx-set-shas@v3

- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: yarn

- name: Install dependencies
run: |
corepack enable
yarn install --immutable
uses: ./.github/actions/yarn-install

- uses: nrwl/nx-set-shas@v3
# This line is needed for nx affected to work when CI is running on a PR
- run: git branch --track main origin/main

- name: Run NX checks
run: |
yarn nx format:check
yarn nx workspace-lint
yarn nx affected --target lint --parallel 3
yarn nx affected --target test --parallel 3
yarn nx affected --target build --parallel 3
yarn nx affected --target typecheck --parallel 3
yarn nx affected -t lint,test,build,typecheck --parallel 3
7 changes: 2 additions & 5 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
name: Changesets
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

Expand All @@ -19,12 +19,9 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: 20.x
cache: yarn

- name: Install dependencies
run: |
corepack enable
yarn install --immutable
uses: ./.github/actions/yarn-install

- name: Create Release Pull Request or Publish to npm
# https://github.com/changesets/action
Expand Down

0 comments on commit 5a69114

Please sign in to comment.