name: CI Chrome Extension
on:
  push:
    branches:
      - main
  pull_request:
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:
      - 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: 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
      VITE_FRONT_BASE_URL: http://localhost:3001
    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: 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 / Run build
        run: yarn nx build twenty-chrome-extension
