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:
Thaïs
2024-04-30 16:28:25 +02:00
committed by GitHub
parent a77cb023c0
commit c193663a71
44 changed files with 13485 additions and 13474 deletions

View File

@ -2,6 +2,7 @@
"name": "twenty-front",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"tags": ["scope:frontend"],
"targets": {
"build": {
"outputs": ["{options.outputPath}"],
@ -24,115 +25,58 @@
"open": true
}
},
"typecheck": {
"reset:env": {
"executor": "nx:run-commands",
"inputs": ["{projectRoot}/.env.example"],
"outputs": ["{projectRoot}/.env"],
"cache": true,
"options": {
"cwd": "{projectRoot}",
"command": "tsc -b tsconfig.json",
"args": ["--incremental"]
},
"configurations": {
"ci": { "args": [] },
"watch": { "watch": true }
"command": "cp .env.example .env"
}
},
"typecheck": {},
"lint": {
"executor": "@nx/eslint:lint",
"outputs": ["{options.outputFile}"],
"options": {
"eslintConfig": "{projectRoot}/.eslintrc.cjs",
"ignorePath": "{workspaceRoot}/.gitignore",
"lintFilePatterns": [
"{projectRoot}/src/**/*.{ts,tsx,json}",
"{projectRoot}/package.json"
],
"maxWarnings": 0,
"reportUnusedDisableDirectives": "error",
"cache": true
"reportUnusedDisableDirectives": "error"
},
"configurations": {
"ci": {
"eslintConfig": "{projectRoot}/.eslintrc-ci.cjs",
"cache": false
},
"fix": {
"fix": true
}
"ci": { "eslintConfig": "{projectRoot}/.eslintrc-ci.cjs" },
"fix": {}
}
},
"fmt": {
"executor": "nx:run-commands",
"inputs": ["{projectRoot}/src/**/*"],
"cache": true,
"options": {
"cwd": "{projectRoot}",
"command": "prettier src --check"
"files": "src"
},
"configurations": {
"fix": { "args": ["--write"] }
}
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{projectRoot}/coverage"],
"options": {
"jestConfig": "{projectRoot}/jest.config.ts",
"coverage": true,
"coverageReporters": ["text-summary"]
},
"configurations": {
"ci": {
"ci": true,
"maxWorkers": 3
},
"coverage": {
"coverageReporters": ["lcov", "text"]
},
"watch": { "watch": true }
}
},
"storybook:build": {
"executor": "@nx/storybook:build",
"outputs": ["{options.outputDir}"],
"options": {
"outputDir": "{projectRoot}/storybook-static",
"configDir": "{projectRoot}/.storybook"
"fix": {}
}
},
"test": {},
"storybook:build": {},
"storybook:dev": {
"executor": "@nx/storybook:storybook",
"options": {
"port": 6006,
"configDir": "{projectRoot}/.storybook"
}
"options": { "port": 6006 }
},
"storybook:static": {
"executor": "@nx/web:file-server",
"options": {
"buildTarget": "twenty-front:storybook:build",
"port": 6006,
"staticFilePath": "{projectRoot}/storybook-static",
"watch": false
"port": 6006
}
},
"storybook:test": {
"executor": "nx:run-commands",
"options": {
"cwd": "{projectRoot}",
"commands": [
"test-storybook --url http://localhost:6006 --maxWorkers=3 --coverage",
"nyc report --reporter=lcov --reporter=text-summary -t coverage/storybook --report-dir coverage/storybook --check-coverage"
],
"parallel": false
"url": "http://localhost:6006"
},
"configurations": {
"docs": {
"commands": ["STORYBOOK_SCOPE=ui-docs nx storybook:test"]
},
"modules": {
"commands": ["STORYBOOK_SCOPE=modules nx storybook:test"]
},
"pages": { "commands": ["STORYBOOK_SCOPE=pages nx storybook:test"] }
"docs": { "env": { "STORYBOOK_SCOPE": "ui-docs" } },
"modules": { "env": { "STORYBOOK_SCOPE": "modules" } },
"pages": { "env": { "STORYBOOK_SCOPE": "pages" } }
}
},
"graphql:generate": {
@ -144,24 +88,13 @@
},
"configurations": {
"data": {
"args": ["--config=codegen.cjs"]
"config": "codegen.cjs"
},
"metadata": {
"args": ["--config=codegen-metadata.cjs"]
"config": "codegen-metadata.cjs"
}
}
},
"chromatic": {
"executor": "nx:run-commands",
"options": {
"cwd": "{projectRoot}",
"command": "cross-var chromatic --project-token=$CHROMATIC_PROJECT_TOKEN --build-script-name=storybook:build"
},
"configurations": {
"ci": {
"args": ["--exit-zero-on-changes"]
}
}
}
"chromatic": {}
}
}