chore: use Nx affected tasks in CI (#5110)
Closes #5097 - Uses "nx affected" to detect what projects need to be checked in the current PR (for now, `ci-front` and `ci-server` workflows only). - Caches results of certain tasks (`lint`, `typecheck`, `test`, `storybook:build`) when a PR pipeline runs. The next runs of the same PR's pipeline will then be able to reuse the PR's task cache to execute tasks faster. - Caches Yarn's cache folder to install dependencies faster in CI jobs. - Rewrites the node modules cache/install steps as a custom, reusable Github action. - Distributes `ci-front` jobs with a "matrix" strategy. - Sets common tasks config at the root `nx.json`. For instance, to activate the `typecheck` task in a project, add `typecheck: {}` to its `project.json` and it'll use the default config set in `nx.json` for the `typecheck` task. Options can be overridden in each individual `project.json` if needed. - Adds "scope" tags to some projects: `scope:frontend`, `scope:backend`, `scope:shared`. An eslint rule ensures that `scope:frontend` only depends on `scope:frontent` or `scope:shared` projects, same for `scope:backend`. These tags are used by `nx affected` to filter projects by scope and generates different task cache keys according to the requested scope. - Enables checks for twenty-emails in the `ci-server` workflow.
This commit is contained in:
21
.github/workflows/actions/nx-affected/action.yaml
vendored
Normal file
21
.github/workflows/actions/nx-affected/action.yaml
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
name: Nx Affected CI
|
||||
inputs:
|
||||
parallel:
|
||||
required: false
|
||||
types: [number]
|
||||
default: 3
|
||||
tag:
|
||||
required: false
|
||||
types: [string]
|
||||
tasks:
|
||||
required: true
|
||||
types: [string]
|
||||
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- name: Get last successful commit
|
||||
uses: nrwl/nx-set-shas@v4
|
||||
- name: Run affected command
|
||||
shell: bash
|
||||
run: npx nx affected --nxBail --configuration=ci -t=${{ inputs.tasks }} --parallel=${{ inputs.parallel }} --exclude='*,!tag:${{ inputs.tag }}'
|
||||
29
.github/workflows/actions/task-cache/action.yaml
vendored
Normal file
29
.github/workflows/actions/task-cache/action.yaml
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
name: Restore Tasks Cache CI
|
||||
inputs:
|
||||
tag:
|
||||
required: false
|
||||
types: [string]
|
||||
tasks:
|
||||
required: false
|
||||
types: [string]
|
||||
default: all
|
||||
suffix:
|
||||
required: false
|
||||
types: [string]
|
||||
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- name: Compute tasks key
|
||||
id: tasks-key
|
||||
shell: bash
|
||||
run: echo "key=${{ inputs.tasks }}" | tr , - >> $GITHUB_OUTPUT
|
||||
- name: Restore tasks cache
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: |
|
||||
.cache
|
||||
.nx/cache
|
||||
key: tasks-cache-${{ inputs.tag }}-${{ steps.tasks-key.outputs.key }}${{ inputs.suffix }}-${{ github.sha }}
|
||||
restore-keys: |
|
||||
tasks-cache-${{ inputs.tag }}-${{ steps.tasks-key.outputs.key }}${{ inputs.suffix }}-
|
||||
23
.github/workflows/actions/yarn-install/action.yaml
vendored
Normal file
23
.github/workflows/actions/yarn-install/action.yaml
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
name: Yarn Install
|
||||
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- name: Setup Node.js and get yarn cache
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: "18"
|
||||
cache: yarn
|
||||
- name: Cache node modules
|
||||
id: node-modules-cache
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: |
|
||||
node_modules
|
||||
packages/*/node_modules
|
||||
key: root-node_modules-${{ hashFiles('yarn.lock') }}
|
||||
restore-keys: root-node_modules-
|
||||
- name: Install Dependencies
|
||||
shell: bash
|
||||
run: yarn --immutable --check-cache
|
||||
if: steps.node-modules-cache.outputs.cache-hit != 'true'
|
||||
Reference in New Issue
Block a user