name: Release Project

on:
  push:
    tags:
      - "v*"

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: Setup Java
        uses: actions/setup-java@v4
        with:
          java-version: 21
          distribution: temurin
      - name: Setup Gradle
        uses: gradle/actions/setup-gradle@v5.0.0
        with:
          gradle-version: wrapper
          cache-read-only: false
          cache-write-only: false
      - name: Make gradlew executable
        run: chmod +x gradlew
      - name: Build & Publish
        env:
          ORG_GRADLE_PROJECT_MAVEN_AIRGAME_USERNAME: ${{ secrets.MAVEN_AIRGAME_USERNAME }}
          ORG_GRADLE_PROJECT_MAVEN_AIRGAME_PASSWORD: ${{ secrets.MAVEN_AIRGAME_PASSWORD }}
        run: ./gradlew build --info --console plain --no-daemon
      - name: Generate Changelog
        uses: orhun/git-cliff-action@v4
        id: git-cliff
        with:
          args: --latest --strip header
        env:
          GITHUB_TOKEN: ${{ secrets.ACCESS_GITHUB_TOKEN }}
      - name: Publish to Release
        uses: softprops/action-gh-release@v2
        with:
          files: build/*.jar
          name: ${{ github.ref_name }}
          body: ${{ steps.git-cliff.outputs.content }}
