name: Build and test Backend

on:
  pull_request:
    branches: [ "master" ]
  workflow_dispatch:

jobs:
  build:
    name: Build Backend
    runs-on: self-hosted

    steps:
    - uses: actions/checkout@v4

    - name: Use Node.js
      uses: actions/setup-node@v4
      with:
        node-version: '20.x'

    - name: Install Frontend dependencies
      run: npm install
      working-directory: Frontend

    - name: Create .env file
      run: echo "VITE_APP_WEBSOCKET_IP=localhost" > .env
      working-directory: Frontend

    - name: Build Frontend
      run: npm run build
      working-directory: Frontend
    
    - name: Set up JDK 21
      uses: actions/setup-java@v4
      with:
        java-version: '21'
        distribution: 'temurin'
        architecture: x64
    
    - name: Set up Maven
      uses: stCarolas/setup-maven@v5
      with:
        maven-version: 3.8.2
        
    - name: Build with Maven
      run: mvn -B package --file pom.xml
      working-directory: Backend
