From f85d6412fbc3789b4336ee8d652bc21524974de6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tha=C3=AFs=20Guigon?= Date: Mon, 22 Apr 2024 21:05:48 +0200 Subject: [PATCH] chore: use Nx affected tasks in CI Closes #5097 --- .../workflows/actions/nx-affected/action.yaml | 30 ++++ .../actions/yarn-install/action.yaml | 16 ++ .github/workflows/ci-chromatic.yaml | 5 +- .github/workflows/ci-chrome-extension.yaml | 43 +----- .github/workflows/ci-docs.yaml | 5 +- .github/workflows/ci-front.yaml | 141 ++++-------------- .github/workflows/ci-server.yaml | 5 +- .github/workflows/ci-utils.yaml | 5 +- .github/workflows/ci-website.yaml | 5 +- nx.json | 4 + package.json | 2 +- packages/twenty-front/project.json | 11 ++ packages/twenty-ui/project.json | 4 +- 13 files changed, 109 insertions(+), 167 deletions(-) create mode 100644 .github/workflows/actions/nx-affected/action.yaml create mode 100644 .github/workflows/actions/yarn-install/action.yaml diff --git a/.github/workflows/actions/nx-affected/action.yaml b/.github/workflows/actions/nx-affected/action.yaml new file mode 100644 index 0000000000000..e47eebd9d61f1 --- /dev/null +++ b/.github/workflows/actions/nx-affected/action.yaml @@ -0,0 +1,30 @@ +name: Nx Affected CI +on: + workflow_call: + inputs: + parallel: + required: false + types: [number] + tag: + required: false + types: [string] + target: + required: true + types: [string] + +jobs: + affected: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Nx Affected CI / Install Dependencies + uses: ./.github/workflows/actions/yarn-install + - uses: actions/checkout@v4 + with: + # Fetch last 100 branches and commits so that Nx affected has a base to compare against. + fetch-depth: 100 + - name: Nx Affected CI / Get last successful commit + id: setSHAs + uses: nrwl/nx-set-shas@v4 + - name: Run affected command + run: npx nx affected --nxBail --configuration=ci -t ${{ inputs.target }} --parallel=${{ inputs.parallel }} --exclude='*,!tag:${{ inputs.tag }}' \ No newline at end of file diff --git a/.github/workflows/actions/yarn-install/action.yaml b/.github/workflows/actions/yarn-install/action.yaml new file mode 100644 index 0000000000000..24fa026c4e1f7 --- /dev/null +++ b/.github/workflows/actions/yarn-install/action.yaml @@ -0,0 +1,16 @@ +name: Yarn Install +on: + workflow_call: + +jobs: + affected: + runs-on: ci-8-cores + steps: + - uses: actions/checkout@v4 + - name: Yarn Install / Setup Node.js and get cached dependencies + uses: actions/setup-node@v3 + with: + node-version: "18" + cache: yarn + - name: Yarn Install / Install Dependencies + run: yarn --immutable \ No newline at end of file diff --git a/.github/workflows/ci-chromatic.yaml b/.github/workflows/ci-chromatic.yaml index 8c87999e097dc..3bee3ec9fc190 100644 --- a/.github/workflows/ci-chromatic.yaml +++ b/.github/workflows/ci-chromatic.yaml @@ -27,17 +27,18 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 - - name: Setup Node.js + - name: Setup Node.js and get cached dependencies uses: actions/setup-node@v3 with: node-version: "18" + cache: yarn - name: Front / Write .env run: | cd packages/twenty-front touch .env echo "REACT_APP_SERVER_BASE_URL: $REACT_APP_SERVER_BASE_URL" >> .env - name: Front / Install Dependencies - run: yarn + run: yarn --immutable - name: Publish to Chromatic run: | cd packages/twenty-front diff --git a/.github/workflows/ci-chrome-extension.yaml b/.github/workflows/ci-chrome-extension.yaml index f5c80ca95f7e9..4ecf2111a64b2 100644 --- a/.github/workflows/ci-chrome-extension.yaml +++ b/.github/workflows/ci-chrome-extension.yaml @@ -15,33 +15,7 @@ concurrency: cancel-in-progress: true jobs: - chrome-extension-yarn-install: - runs-on: ci-8-cores - env: - VITE_SERVER_BASE_URL: http://localhost:3000 - VITE_FRONT_BASE_URL: http://localhost:3001 - steps: - - uses: actions/checkout@v4 - - name: Setup Node.js - uses: actions/setup-node@v3 - with: - node-version: "18" - - name: Cache chrome extension node modules - uses: actions/cache@v3 - with: - path: packages/twenty-chrome-extension/node_modules - key: chrome-extension-node_modules-${{hashFiles('yarn.lock')}} - restore-keys: chrome-extension-node_modules- - - name: Cache root node modules - uses: actions/cache@v3 - with: - path: node_modules - key: root-node_modules-${{hashFiles('yarn.lock')}} - restore-keys: root-node_modules- - - name: Chrome Extension / Install Dependencies - run: yarn chrome-extension-build: - needs: chrome-extension-yarn-install runs-on: ubuntu-latest env: VITE_SERVER_BASE_URL: http://localhost:3000 @@ -52,21 +26,12 @@ jobs: with: access_token: ${{ github.token }} - uses: actions/checkout@v4 - - name: Setup Node.js + - name: Setup Node.js and get cached dependencies uses: actions/setup-node@v3 with: node-version: "18" - - name: Cache chrome extension node modules - uses: actions/cache@v3 - with: - path: packages/twenty-chrome-extension/node_modules - key: chrome-extension-node_modules-${{hashFiles('yarn.lock')}} - restore-keys: chrome-extension-node_modules- - - name: Cache root node modules - uses: actions/cache@v3 - with: - path: node_modules - key: root-node_modules-${{hashFiles('yarn.lock')}} - restore-keys: root-node_modules- + cache: yarn + - name: Chome Extension / Install Dependencies + run: yarn --immutable - name: Chrome Extension / Run build run: npx nx build twenty-chrome-extension diff --git a/.github/workflows/ci-docs.yaml b/.github/workflows/ci-docs.yaml index 66a57f78c2713..02fb6b1a0c1b4 100644 --- a/.github/workflows/ci-docs.yaml +++ b/.github/workflows/ci-docs.yaml @@ -21,12 +21,13 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Setup Node.js + - name: Setup Node.js and get cached dependencies uses: actions/setup-node@v3 with: node-version: "18" + cache: yarn - name: Docs / Install Dependencies - run: yarn + run: yarn --immutable - name: Docs / Build Documentation run: npx nx build twenty-docs vale: diff --git a/.github/workflows/ci-front.yaml b/.github/workflows/ci-front.yaml index 0c65867b266b8..42bac3d2e4339 100644 --- a/.github/workflows/ci-front.yaml +++ b/.github/workflows/ci-front.yaml @@ -17,108 +17,51 @@ concurrency: cancel-in-progress: true jobs: - front-yarn-install: - runs-on: ci-8-cores - env: - REACT_APP_SERVER_BASE_URL: http://localhost:3000 - steps: - - uses: actions/checkout@v4 - - name: Setup Node.js - uses: actions/setup-node@v3 - with: - node-version: "18" - - name: Cache front node modules - uses: actions/cache@v3 - with: - path: packages/twenty-front/node_modules - key: front-node_modules-${{hashFiles('yarn.lock')}} - restore-keys: front-node_modules- - - name: Cache root node modules - uses: actions/cache@v3 - with: - path: node_modules - key: root-node_modules-${{hashFiles('yarn.lock')}} - restore-keys: root-node_modules- - - name: Front / Install Dependencies - run: yarn front-pages-sb-test: - needs: front-yarn-install runs-on: ci-8-cores env: REACT_APP_SERVER_BASE_URL: http://localhost:3000 + STORYBOOK_SCOPE: pages steps: - name: Cancel Previous Runs uses: styfle/cancel-workflow-action@0.11.0 with: - access_token: ${{ github.token }} + access_token: ${{ github.token }} - uses: actions/checkout@v4 - - name: Setup Node.js - uses: actions/setup-node@v3 - with: - node-version: "18" - - name: Front / Write .env - run: | - cd packages/twenty-front - cp .env.example .env - - name: Cache front node modules - uses: actions/cache@v3 - with: - path: packages/twenty-front/node_modules - key: front-node_modules-${{hashFiles('yarn.lock')}} - restore-keys: front-node_modules- - - name: Cache root node modules - uses: actions/cache@v3 - with: - path: node_modules - key: root-node_modules-${{hashFiles('yarn.lock')}} - restore-keys: root-node_modules- + - name: Install dependencies + uses: ./.github/workflows/yarn-install.yaml - name: Install Playwright run: cd packages/twenty-front && npx playwright install + - name: Front / Write .env + run: npx nx reset:env twenty-front - name: Run storybook tests run: | npx concurrently -k -s first -n "SB,TEST" -c "magenta,blue" \ - "STORYBOOK_SCOPE=pages npx nx run twenty-front:storybook:static:ci" \ - "npx wait-on tcp:6006 && STORYBOOK_SCOPE=pages npx nx run twenty-front:storybook:test" + "npx nx run twenty-front:storybook:static:ci" \ + "npx wait-on tcp:6006 && npx nx run twenty-front:storybook:test" front-modules-sb-test: - needs: front-yarn-install runs-on: ci-4-cores env: REACT_APP_SERVER_BASE_URL: http://localhost:3000 + STORYBOOK_SCOPE: modules steps: - name: Cancel Previous Runs uses: styfle/cancel-workflow-action@0.11.0 with: access_token: ${{ github.token }} - uses: actions/checkout@v4 - - name: Setup Node.js - uses: actions/setup-node@v3 - with: - node-version: "18" - - name: Front / Write .env - run: | - cd packages/twenty-front - cp .env.example .env - - name: Cache front node modules - uses: actions/cache@v3 - with: - path: packages/twenty-front/node_modules - key: front-node_modules-${{hashFiles('yarn.lock')}} - restore-keys: front-node_modules- - - name: Cache root node modules - uses: actions/cache@v3 - with: - path: node_modules - key: root-node_modules-${{hashFiles('yarn.lock')}} - restore-keys: root-node_modules- + - name: Install dependencies + uses: ./.github/workflows/actions/yarn-install - name: Install Playwright run: cd packages/twenty-front && npx playwright install + - name: Front / Write .env + run: npx nx reset:env twenty-front - name: Run storybook tests run: | npx concurrently -k -s first -n "SB,TEST" -c "magenta,blue" \ - "STORYBOOK_SCOPE=modules npx nx run twenty-front:storybook:static:ci" \ - "npx wait-on tcp:6006 && STORYBOOK_SCOPE=modules npx nx run twenty-front:storybook:test" + "npx nx run twenty-front:storybook:static:ci" \ + "npx wait-on tcp:6006 && npx nx run twenty-front:storybook:test" front-lint-tsc: - needs: front-yarn-install runs-on: ubuntu-latest env: REACT_APP_SERVER_BASE_URL: http://localhost:3000 @@ -126,34 +69,14 @@ jobs: - name: Cancel Previous Runs uses: styfle/cancel-workflow-action@0.11.0 with: - access_token: ${{ github.token }} + access_token: ${{ github.token }} - uses: actions/checkout@v4 - - name: Setup Node.js - uses: actions/setup-node@v3 + - name: Front / Run linter & typecheck + uses: ./.github/workflows/actions/nx-affected with: - node-version: "18" - - name: Cache front node modules - uses: actions/cache@v3 - with: - path: packages/twenty-front/node_modules - key: front-node_modules-${{hashFiles('yarn.lock')}} - restore-keys: front-node_modules- - - name: Cache root node modules - uses: actions/cache@v3 - with: - path: node_modules - key: root-node_modules-${{hashFiles('yarn.lock')}} - restore-keys: root-node_modules- - - name: UI / Run linter - run: npx nx lint twenty-ui - - name: UI / Run Typescript Check - run: npx nx run twenty-ui:typecheck:ci - - name: Front / Run linter - run: npx nx run twenty-front:lint:ci - - name: Front / Run Typescript Check - run: npx nx run twenty-front:typecheck:ci + tag: scope:frontend + target: lint typecheck front-jest: - needs: front-yarn-install runs-on: ubuntu-latest env: REACT_APP_SERVER_BASE_URL: http://localhost:3000 @@ -161,23 +84,11 @@ jobs: - name: Cancel Previous Runs uses: styfle/cancel-workflow-action@0.11.0 with: - access_token: ${{ github.token }} + access_token: ${{ github.token }} - uses: actions/checkout@v4 - - name: Setup Node.js - uses: actions/setup-node@v3 - with: - node-version: "18" - - name: Cache front node modules - uses: actions/cache@v3 - with: - path: packages/twenty-front/node_modules - key: front-node_modules-${{hashFiles('yarn.lock')}} - restore-keys: front-node_modules- - - name: Cache root node modules - uses: actions/cache@v3 - with: - path: node_modules - key: root-node_modules-${{hashFiles('yarn.lock')}} - restore-keys: root-node_modules- - name: Front / Run jest - run: npx nx test twenty-front --configuration=ci + uses: ./.github/workflows/actions/nx-affected + with: + parallel: 1 + tag: scope:frontend + target: test \ No newline at end of file diff --git a/.github/workflows/ci-server.yaml b/.github/workflows/ci-server.yaml index 53f86ce00b118..20701a42666ed 100644 --- a/.github/workflows/ci-server.yaml +++ b/.github/workflows/ci-server.yaml @@ -29,12 +29,13 @@ jobs: - 5432:5432 steps: - uses: actions/checkout@v4 - - name: Setup Node.js + - name: Setup Node.js and get cached dependencies uses: actions/setup-node@v3 with: node-version: "18" + cache: yarn - name: Server / Install Dependencies - run: yarn + run: yarn --immutable - name: Server / Run linter run: npx nx lint twenty-server - name: Server / Run jest tests diff --git a/.github/workflows/ci-utils.yaml b/.github/workflows/ci-utils.yaml index ac65a6c51734a..2826cbbd4b7a5 100644 --- a/.github/workflows/ci-utils.yaml +++ b/.github/workflows/ci-utils.yaml @@ -21,12 +21,13 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Setup Node.js + - name: Setup Node.js and get cached dependencies uses: actions/setup-node@v3 with: node-version: "18" + cache: yarn - name: Utils / Install Dependencies - run: yarn + run: yarn --immutable - name: Utils / Run Danger.js run: cd packages/twenty-utils && npx nx danger:ci env: diff --git a/.github/workflows/ci-website.yaml b/.github/workflows/ci-website.yaml index f925cb7189796..1a57491b580d9 100644 --- a/.github/workflows/ci-website.yaml +++ b/.github/workflows/ci-website.yaml @@ -19,11 +19,12 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Setup Node.js + - name: Setup Node.js and get cached dependencies uses: actions/setup-node@v3 with: node-version: "18" + cache: yarn - name: Website / Install Dependencies - run: yarn + run: yarn --immutable - name: Website / Build Website run: npx nx build twenty-website diff --git a/nx.json b/nx.json index 047ed0ca10909..1168a0960e8d4 100644 --- a/nx.json +++ b/nx.json @@ -1,4 +1,8 @@ { + "namedInputs": { + "default": ["{projectRoot}/**/*", "sharedGlobals"], + "sharedGlobals": ["{workspaceRoot}/.github/workflows/ci-front.yaml"] + }, "targetDefaults": { "build": { "cache": true, diff --git a/package.json b/package.json index 51629ce86a867..cd576aae7050f 100644 --- a/package.json +++ b/package.json @@ -331,7 +331,7 @@ "version": "0.2.1", "nx": {}, "scripts": { - "start": "nx run-many -t start -p twenty-server twenty-front" + "start": "npx nx run-many -t start -p twenty-server twenty-front" }, "workspaces": { "packages": [ diff --git a/packages/twenty-front/project.json b/packages/twenty-front/project.json index 06f26ee0e1117..ceb765bda0b41 100644 --- a/packages/twenty-front/project.json +++ b/packages/twenty-front/project.json @@ -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,6 +25,16 @@ "open": true } }, + "reset:env": { + "executor": "nx:run-commands", + "inputs": ["{projectRoot}/.env.example"], + "outputs": ["{projectRoot}/.env"], + "cache": true, + "options": { + "cwd": "{projectRoot}", + "command": "cp .env.example .env" + } + }, "typecheck": { "executor": "nx:run-commands", "options": { diff --git a/packages/twenty-ui/project.json b/packages/twenty-ui/project.json index 57aed0ec550a6..0700f77a23052 100644 --- a/packages/twenty-ui/project.json +++ b/packages/twenty-ui/project.json @@ -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"] @@ -83,6 +84,5 @@ "command": "test-storybook -c {projectRoot}/.storybook --url=http://localhost:6007" } } - }, - "tags": [] + } }