name: CI Chrome Extension
on:
  push:
    branches:
      - main
  
  pull_request:
    
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  chrome-extension-build:
    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
        with:
          fetch-depth: 0

      - name: Check for changed files
        id: changed-files
        uses: tj-actions/changed-files@v11
        with:
          files: |
            package.json
            packages/twenty-chrome-extension/**
             
      - name: Install dependencies
        if: steps.changed-files.outputs.any_changed == 'true'
        uses: ./.github/workflows/actions/yarn-install
      - name: Chrome Extension / Run build
        if: steps.changed-files.outputs.any_changed == 'true'
        run: npx nx build twenty-chrome-extension

      - name: Mark as Valid if No Changes
        if: steps.changed-files.outputs.changed != 'true'
        run: |
          echo "No relevant changes detected. Marking as valid."  
