name: Deploy App

on:
  push:
    branches: ["master"]
    paths-ignore:
      - .gitignore
      - README.md
      - LICENSE
      - docker-compose.yml

jobs:
  docker:
    strategy:
      matrix:
        arch: ["ubuntu-latest"]
        git-version: ["2.44.0"]
        java-version: ["17"]
        maven-version: ["3.8.5"]
    runs-on: ${{ matrix.arch }}

    # Steps to run
    steps:
      # Checkout the repo
      - name: Checkout
        uses: actions/checkout@v4

      # Setup Java and Maven
      - name: Set up JDK and Maven
        uses: s4u/setup-maven-action@v1.14.0
        with:
          java-version: ${{ matrix.java-version }}
          distribution: "zulu"
          maven-version: ${{ matrix.maven-version }}

      # Run JUnit Tests
      - name: Run Tests
        run: mvn --batch-mode test -q

      # Re-checkout to reset the FS before deploying to Dokku
      - name: Checkout - Reset FS
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      # Deploy to Dokku
      - name: Push to dokku
        uses: dokku/github-action@master
        with:
          git_remote_url: "ssh://dokku@10.0.50.137:22/minecraft-helper"
          ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}