name: Test CI

on:
  push:
    branches: [main]

jobs:
  build:
    runs-on: runner

    env:
      DOCKER_VOLUME: ${{ vars.DOCKER_VOLUME }}

    steps:
    - name: Checkout
      uses: actions/checkout@v4

    - name: Check PWD
      run: |
        echo $DOCKER_VOLUME
        echo $PWD
        ls .

    - name: Restore node_modules
      id: cache-node
      uses: actions/cache@v4
      with:
        path: node_modules
        key: ${{ runner.os }}-yarn-v1-${{ hashFiles('**/yarn.lock') }}
        restore-keys: |
          ${{ runner.os }}-yarn-v1-

    - name: Install Dependencies with yarn
      if: steps.cache-node.outputs.cache-hit != 'true'
      run: |
        yarn install --immutable
        ls .

    - name: Build Nestjs project
      run: |
        yarn build
        ls .

    - name: Deploy dist
      run: |
        cp -r dist $DOCKER_VOLUME/scheduler/back/
        cp -r node_modules $DOCKER_VOLUME/scheduler/back/
        ls $DOCKER_VOLUME/scheduler/back

    - name: Clean project
      run: |
        rm -rf node_modules
        rm -rf dist