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

@ -6,9 +6,9 @@
"type": "module",
"scripts": {
"nx": "NX_DEFAULT_PROJECT=twenty-chrome-extension node ../../node_modules/nx/bin/nx.js",
"clean": "rimraf ./dist",
"clean": "npx rimraf ./dist",
"start": "yarn clean && VITE_MODE=development vite",
"build": "yarn clean && tsc && vite build",
"build": "yarn clean && npx tsc && npx vite build",
"lint": "eslint . --report-unused-disable-directives --max-warnings 0 --config .eslintrc.cjs",
"graphql:generate": "graphql-codegen",
"fmt": "prettier --check \"src/**/*.ts\" \"src/**/*.tsx\"",

View File

@ -1,7 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc"
"outDir": "../../.cache/tsc"
},
"exclude": [
"**/*.spec.ts",

View File

@ -1,7 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"outDir": "../../.cache/tsc",
"types": ["jest", "node"]
},
"include": [

View File

@ -7,9 +7,7 @@
"license": "AGPL-3.0",
"main": "./dist/index.js",
"scripts": {
"nx": "NX_DEFAULT_PROJECT=twenty-emails node ../../node_modules/nx/bin/nx.js",
"build": "npx vite build",
"lint": "eslint"
"build": "npx vite build"
},
"exports": {
".": {
@ -21,8 +19,5 @@
"node": "^18.17.1",
"npm": "please-use-yarn",
"yarn": "^4.0.2"
},
"nx": {
"projectType": "library"
}
}

View File

@ -0,0 +1,35 @@
{
"name": "twenty-emails",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "library",
"tags": ["scope:backend"],
"targets": {
"build": {
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "{projectRoot}/dist"
}
},
"typecheck": {},
"lint": {
"options": {
"lintFilePatterns": [
"{projectRoot}/src/**/*.{ts,tsx,json}",
"{projectRoot}/package.json"
],
"reportUnusedDisableDirectives": "error"
},
"configurations": {
"fix": {}
}
},
"fmt": {
"options": {
"files": "src"
},
"configurations": {
"fix": {}
}
}
}
}

View File

@ -1,3 +1,5 @@
/* eslint-disable @nx/workspace-no-hardcoded-colors */
const grayScale = {
gray100: '#000000',
gray90: '#141414',

View File

@ -1,5 +1,6 @@
import { PropsWithChildren } from 'react';
import { Container, Html } from '@react-email/components';
import { BaseHead } from 'src/components/BaseHead';
import { Logo } from 'src/components/Logo';

View File

@ -1,4 +1,5 @@
import { Font, Head } from '@react-email/components';
import { emailTheme } from 'src/common-style';
export const BaseHead = () => {

View File

@ -1,5 +1,6 @@
import { ReactNode } from 'react';
import { Button } from '@react-email/button';
import { emailTheme } from 'src/common-style';
const callToActionStyle = {

View File

@ -2,6 +2,7 @@ import { ReactNode } from 'react';
import { Column } from '@react-email/components';
import { Row } from '@react-email/row';
import { Text } from '@react-email/text';
import { emailTheme } from 'src/common-style';
const rowStyle = {

View File

@ -1,5 +1,6 @@
import { ReactNode } from 'react';
import { Link as EmailLink } from '@react-email/components';
import { emailTheme } from 'src/common-style';
const linkStyle = {

View File

@ -1,5 +1,6 @@
import { PropsWithChildren } from 'react';
import { PropsWithChildren as MainTextProps } from 'react';
import { Text } from '@react-email/text';
import { emailTheme } from 'src/common-style';
const mainTextStyle = {
@ -8,6 +9,6 @@ const mainTextStyle = {
color: emailTheme.font.colors.primary,
};
export const MainText = ({ children }: PropsWithChildren) => {
export const MainText = ({ children }: MainTextProps) => {
return <Text style={mainTextStyle}>{children}</Text>;
};

View File

@ -4,7 +4,7 @@ import { HighlightedText } from 'src/components/HighlightedText';
import { MainText } from 'src/components/MainText';
import { Title } from 'src/components/Title';
type CleanInactiveWorkspaceEmailData = {
type CleanInactiveWorkspaceEmailProps = {
daysLeft: number;
userName: string;
workspaceDisplayName: string;
@ -14,7 +14,7 @@ export const CleanInactiveWorkspaceEmail = ({
daysLeft,
userName,
workspaceDisplayName,
}: CleanInactiveWorkspaceEmailData) => {
}: CleanInactiveWorkspaceEmailProps) => {
const dayOrDays = daysLeft > 1 ? 'days' : 'day';
const remainingDays = daysLeft > 1 ? `${daysLeft} ` : '';

View File

@ -1,4 +1,5 @@
import { Column, Row, Section } from '@react-email/components';
import { BaseEmail } from 'src/components/BaseEmail';
import { MainText } from 'src/components/MainText';
import { Title } from 'src/components/Title';

View File

@ -1,4 +1,5 @@
import { format } from 'date-fns';
import { BaseEmail } from 'src/components/BaseEmail';
import { CallToAction } from 'src/components/CallToAction';
import { MainText } from 'src/components/MainText';

View File

@ -1,7 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"outDir": "../../.cache/tsc",
"types": [
"node",
"@nx/react/typings/image.d.ts",

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": {}
}
}

View File

@ -9,12 +9,12 @@ import {
} from '@/object-record/record-field/types/FieldMetadata';
import { type } from 'os';
import { FieldMetadataType } from '~/generated-metadata/graphql';
import { mockedCompanyObjectMetadataItem, mockedPersonObjectMetadataItem } from '~/testing/mock-data/metadata';
;
import {
mockedCompanyObjectMetadataItem,
mockedPersonObjectMetadataItem,
} from '~/testing/mock-data/metadata';
export const fieldMetadataId = 'fieldMetadataId';
export const textfieldDefinition: FieldDefinition<FieldTextMetadata> = {
fieldMetadataId,
label: 'User Name',
@ -64,7 +64,7 @@ export const linkFieldDefinition: FieldDefinition<FieldLinkMetadata> = {
label: 'LinkedIn URL',
iconName: 'url',
type: FieldMetadataType.Link,
defaultValue: { label: '', url: ''},
defaultValue: { label: '', url: '' },
metadata: {
fieldName: 'linkedInURL',
placeHolder: 'https://linkedin.com/user',

View File

@ -19,7 +19,7 @@
"noUnusedParameters": false,
"noFallthroughCasesInSwitch": true,
"forceConsistentCasingInFileNames": true,
"outDir": "../../dist/out-tsc",
"outDir": "../../.cache/tsc",
"paths": {
"@/*": ["packages/twenty-front/src/modules/*"],
"~/*": ["packages/twenty-front/src/*"],

View File

@ -3,7 +3,7 @@
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"builder": "swc",
"typeCheck": true
"builder": "swc",
"typeCheck": true
}
}

View File

@ -2,6 +2,7 @@
"name": "twenty-server",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"tags": ["scope:backend"],
"targets": {
"build": {
"executor": "nx:run-commands",
@ -35,6 +36,16 @@
"command": "nx start --debug"
}
},
"reset:env": {
"executor": "nx:run-commands",
"inputs": ["{projectRoot}/.env.example"],
"outputs": ["{projectRoot}/.env"],
"cache": true,
"options": {
"cwd": "{projectRoot}",
"command": "cp .env.example .env"
}
},
"command": {
"executor": "nx:run-commands",
"dependsOn": ["build"],
@ -81,42 +92,16 @@
}
},
"lint": {
"executor": "@nx/eslint:lint",
"options": {
"eslintConfig": "{projectRoot}/.eslintrc.cjs",
"ignorePath": "{workspaceRoot}/.gitignore",
"lintFilePatterns": ["{projectRoot}/src/**/*.{ts,json}"]
},
"configurations": {
"ci": { "lintFilePatterns": ["{projectRoot}/**/*.{ts,json}"] },
"fix": { "fix": true }
"fix": {}
}
},
"test:unit": {
"executor": "nx:run-commands",
"dependsOn": ["build"],
"options": {
"cwd": "packages/twenty-server",
"command": "jest"
}
},
"test:unit:watch": {
"executor": "nx:run-commands",
"dependsOn": ["build"],
"options": {
"cwd": "packages/twenty-server",
"command": "jest --watch"
}
},
"test:unit:coverage": {
"executor": "nx:run-commands",
"dependsOn": ["build"],
"options": {
"cwd": "packages/twenty-server",
"command": "jest --coverage"
}
},
"test:unit:debug": {
"test": {},
"test:debug": {
"executor": "nx:run-commands",
"options": {
"cwd": "packages/twenty-server",

View File

@ -81,11 +81,13 @@ describe('CompanyResolver (e2e)', () => {
.expect(200)
.expect((res) => {
const data = res.body.data.findManyCompany;
expect(data).toBeDefined();
expect(Array.isArray(data)).toBe(true);
expect(data.length).toBeGreaterThan(0);
const company = data.find((c) => c.id === companyId);
expect(company).toBeDefined();
expect(company).toHaveProperty('id');
expect(company).toHaveProperty('name', 'New Company');
@ -94,6 +96,7 @@ describe('CompanyResolver (e2e)', () => {
// Check if we have access to ressources outside of our workspace
const instagramCompany = data.find((c) => c.name === 'Instagram');
expect(instagramCompany).toBeUndefined();
});
});

View File

@ -31,7 +31,7 @@ export const createApp = async (
imports: [AppModule],
});
if (!!config.moduleBuilderHook) {
if (config.moduleBuilderHook) {
moduleBuilder = config.moduleBuilderHook(moduleBuilder);
}

View File

@ -3,6 +3,7 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/twenty-ui/src",
"projectType": "library",
"tags": ["scope:frontend"],
"targets": {
"build": {
"dependsOn": ["^build", "generateBarrels"]
@ -21,68 +22,40 @@
}
},
"lint": {
"executor": "@nx/eslint:lint",
"options": {
"eslintConfig": "{projectRoot}/.eslintrc.cjs",
"ignorePath": "{workspaceRoot}/.gitignore",
"lintFilePatterns": [
"{projectRoot}/src/**/*.{ts,tsx,json}",
"{projectRoot}/package.json"
],
"cache": true
]
},
"configurations": {
"fix": { "fix": true }
"fix": {}
}
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{projectRoot}/coverage"],
"fmt": {
"options": {
"jestConfig": "{projectRoot}/jest.config.ts"
}
},
"typecheck": {
"executor": "nx:run-commands",
"options": {
"cwd": "{projectRoot}",
"command": "tsc -b tsconfig.json",
"incremental": true
"files": "src"
},
"configurations": {
"ci": { "incremental": false },
"watch": { "watch": true }
"fix": {}
}
},
"test": {},
"typecheck": {},
"storybook:build": {},
"storybook:dev": {
"executor": "@nx/storybook:storybook",
"options": {
"port": 6007,
"configDir": "{projectRoot}/.storybook"
},
"configurations": {
"ci": { "quiet": true }
}
"options": { "port": 6007 }
},
"storybook:build": {
"executor": "@nx/storybook:build",
"outputs": ["{options.outputDir}"],
"storybook:static": {
"options": {
"outputDir": "{projectRoot}/storybook-static",
"configDir": "{projectRoot}/.storybook"
},
"configurations": {
"ci": {
"quiet": true
}
"buildTarget": "twenty-ui:storybook:build",
"port": 6007
}
},
"storybook:test": {
"executor": "nx:run-commands",
"options": {
"command": "test-storybook -c {projectRoot}/.storybook --url=http://localhost:6007"
"url": "http://localhost:6007"
}
}
},
"tags": []
}
}

View File

@ -8,7 +8,7 @@
"esModuleInterop": true,
"noEmit": true,
"types": ["node"],
"outDir": "../../dist/out-tsc",
"outDir": "../../.cache/tsc",
"paths": {
"@ui/*": ["packages/twenty-ui/src/*"]
}