name: Model Catalog Release

on:
  push:
    tags:
      - 'models-catalog@*'

permissions:
  contents: read

concurrency:
  group: model-catalog-${{ github.ref_name }}
  cancel-in-progress: false

jobs:
  catalog:
    runs-on: ubuntu-latest
    environment: maven-central
    steps:
      - uses: actions/checkout@v4
      - uses: gradle/actions/wrapper-validation@v4
      - uses: actions/setup-java@v4
        with:
          distribution: temurin
          java-version: '21'
      - uses: gradle/actions/setup-gradle@v4
      - name: Validate catalog tag
        run: ./tools/parse-model-release-tag.sh "${GITHUB_REF_NAME}" .
      - name: Build only signed catalog metadata
        env:
          SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
          SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
        run: ./gradlew --no-daemon verifyModelCatalogReleaseCandidate
      - name: Publish only catalog metadata
        env:
          CENTRAL_BEARER_TOKEN: ${{ secrets.CENTRAL_BEARER_TOKEN }}
        run: ./tools/publish-central-bundle.sh "build/model-catalog-release-candidate/radixor-models-catalog-${GITHUB_REF_NAME#models-catalog@}-central-bundle.zip" "org.egothor:radixor-models-catalog:${GITHUB_REF_NAME#models-catalog@}"
