name: Server

on:
  pull_request:
  workflow_dispatch:
  schedule:
    # Run everday at midnight UTC / 5:30 IST
    - cron: "0 0 * * *"

concurrency:
  group: server-${{ github.event_name }}-${{ github.event.number }}
  cancel-in-progress: true

permissions:
  # Do not change this as GITHUB_TOKEN is being used by roulette
  contents: read

jobs:
  checkrun:
    name: Plan Tests
    runs-on: ubuntu-latest
    outputs:
      build: ${{ steps.check-build.outputs.build }}
      run_postgres: ${{ steps.check-build.outputs.run_postgres }}
    steps:
      - name: Clone
        uses: actions/checkout@v6
      - name: Check if unit tests should be run
        id: check-build
        run: |
          python "${GITHUB_WORKSPACE}/.github/helper/roulette.py"
        env:
          TYPE: "server"
          PR_NUMBER: ${{ github.event.number }}
          REPO_NAME: ${{ github.repository }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  test:
    name: Tests
    uses: ./.github/workflows/_base-server-tests.yml
    with:
      enable-postgres: ${{ needs.checkrun.outputs.run_postgres == 'true' }} # This enables PostgreSQL to run tests
      enable-sqlite: false  # This will test against both MariaDB and SQLite if enabled
      parallel-runs: 2
      fake-success: ${{ needs.checkrun.outputs.build != 'strawberry' }}
    needs: checkrun
    secrets: inherit

  migrate:
    name: Migration
    needs: checkrun
    uses: ./.github/workflows/_base-migration.yml
    with:
      db-artifact-url: https://frappe.io/files/v14-frappe.sql.gz
      python-version: '3.14'
      node-version: 24
      fake-success: ${{ needs.checkrun.outputs.build != 'strawberry' }}

  coverage:
    name: Coverage Wrap Up
    needs: [test, checkrun]
    runs-on: ubuntu-latest
    steps:
      - name: Clone
        uses: actions/checkout@v6
      - name: Download artifacts
        uses: actions/download-artifact@v8.0.1
      - name: Upload coverage data
        uses: codecov/codecov-action@v6
        with:
          name: Server
          token: ${{ secrets.CODECOV_TOKEN }}
          fail_ci_if_error: true
          verbose: true
          flags: server
