name: Build MOTD

on:
  push:
    branches: [ main, master ]
  pull_request:
    branches: [ main, master ]
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

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

      - name: Set up JDK 21
        uses: actions/setup-java@v3
        with:
          distribution: 'temurin'
          java-version: '21'
          cache: 'maven'

      - name: Install Maven
        run: |
          if ! command -v mvn &> /dev/null; then
            echo "Maven not found, installing..."
            sudo apt-get update
            sudo apt-get install -y maven
          fi
          mvn --version

      - name: Build with Maven
        run: mvn -B clean package

      - name: Upload artifact
        uses: actions/upload-artifact@v3
        with:
          name: MOTD
          path: target/MOTD-*.jar
          if-no-files-found: error
