name: Publish

on:
  workflow_dispatch:

jobs:
  publish:
    name: Release build and publish
    runs-on: ubuntu-latest
    steps:
      - name: Check out code
        uses: actions/checkout@v4
      - name: Set up JDK 21
        uses: actions/setup-java@v4
        with:
          distribution: adopt
          java-version: '21'
      - name: Release build
        run: ./gradlew writeopia:assemble writeopia_models:assemble writeopia_ui:assemble plugins:writeopia_export:assemble plugins:writeopia_import_document:assemble plugins:writeopia_network:assemble plugins:writeopia_persistence_core:assemble plugins:writeopia_persistence_sqldelight:assemble plugins:writeopia_presentation:assemble plugins:writeopia_serialization:assemble
      - name: Publish to MavenCentral
        run: ./gradlew publishAllPublicationsToMavenCentralRepository --no-configuration-cache
        env:
          ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_NEXUS_USERNAME }}
          ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_NEXUS_PASSWORD }}
          ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.SIGNING_KEY_ID }}
          ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }}
          ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_KEY }}
#          SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }}
