name: Release

on:
  push:
    tags:
      - '**'

jobs:
  release:
    runs-on: ubuntu-24.04-arm
    if: github.event.repository.fork == false
    environment:
      name: maven-central
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-java@v5
        with:
          distribution: 'zulu'
          java-version-file: .github/workflows/.java-version
      - uses: gradle/actions/setup-gradle@v6
        with:
          cache-read-only: true
      - run: ./gradlew publishToMavenCentral publishPlugins
        env:
          GRADLE_PUBLISH_KEY: ${{ secrets.GRADLE_KEY }}
          GRADLE_PUBLISH_SECRET: ${{ secrets.GRADLE_SECRET }}
          ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.CENTRAL_PORTAL_USERNAME }}
          ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.CENTRAL_PORTAL_PASSWORD }}
          ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_KEY }}
          ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.GPG_KEY_PASSWORD }}
      - name: Extract release notes
        uses: ffurrer2/extract-release-notes@v3
        with:
          changelog_file: docs/changes/README.md
          release_notes_file: RELEASE_NOTES.md
      - name: Create release
        run: gh release create ${{ github.ref_name }} --notes-file RELEASE_NOTES.md
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

  deploy:
    needs: release
    uses: ./.github/workflows/deploy.yml
