name: Release
on:
  push:
    tags:
      - v4.0.[0-9]+
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
jobs:
  build-and-stage-release:
    name: Build and Stage Release
    if: ${{ github.repository == 'spring-projects/spring-ws' }}
    runs-on: ubuntu-latest
    steps:
      - name: Check Out Code
        uses: actions/checkout@v4
      - name: Build and Publish
        id: build-and-publish
        uses: ./.github/actions/build
        with:
          develocity-access-key: ${{ secrets.DEVELOCITY_ACCESS_KEY }}
          publish: true
      - name: Stage Release
        uses: spring-io/artifactory-deploy-action@dc1913008c0599f0c4b1fdafb6ff3c502b3565ea # v0.0.2
        with:
          artifact-properties: |
            /**/spring-ws-docs-*.zip::zip.type=docs,zip.name=spring-ws,zip.deployed=false
          build-name: ${{ format('spring-ws-{0}', steps.build-and-publish.outputs.version)}}
          folder: 'deployment-repository'
          password: ${{ secrets.ARTIFACTORY_PASSWORD }}
          repository: 'libs-staging-local'
          signing-key: ${{ secrets.GPG_PRIVATE_KEY }}
          signing-passphrase: ${{ secrets.GPG_PASSPHRASE }}
          uri: 'https://repo.spring.io'
          username: ${{ secrets.ARTIFACTORY_USERNAME }}
    outputs:
      version: ${{ steps.build-and-publish.outputs.version }}
  verify:
    name: Verify
    needs: build-and-stage-release
    uses: ./.github/workflows/verify.yml
    secrets:
      google-chat-webhook-url: ${{ secrets.GOOGLE_CHAT_WEBHOOK_URL }}
      repository-password: ${{ secrets.ARTIFACTORY_PASSWORD }}
      repository-username: ${{ secrets.ARTIFACTORY_USERNAME }}
      token: ${{ secrets.GH_ACTIONS_REPO_TOKEN }}
    with:
      staging: true
      version: ${{ needs.build-and-stage-release.outputs.version }}
  sync-to-maven-central:
    name: Sync to Maven Central
    needs:
      - build-and-stage-release
      - verify
    runs-on: ubuntu-latest
    steps:
      - name: Check Out Code
        uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
      - name: Sync to Maven Central
        uses: ./.github/actions/sync-to-maven-central
        with:
          central-token-password: ${{ secrets.CENTRAL_TOKEN_PASSWORD }}
          central-token-username: ${{ secrets.CENTRAL_TOKEN_USERNAME }}
          jfrog-cli-config-token: ${{ secrets.JF_ARTIFACTORY_SPRING }}
          spring-ws-version: ${{ needs.build-and-stage-release.outputs.version }}
  promote-release:
    name: Promote Release
    needs:
      - build-and-stage-release
      - sync-to-maven-central
    runs-on: ubuntu-latest
    steps:
      - name: Set up JFrog CLI
        uses: jfrog/setup-jfrog-cli@dff217c085c17666e8849ebdbf29c8fe5e3995e6 # v4.5.2
        env:
          JF_ENV_SPRING: ${{ secrets.JF_ARTIFACTORY_SPRING }}
      - name: Promote build
        run: jfrog rt build-promote ${{ format('spring-ws-{0}', needs.build-and-stage-release.outputs.version)}} ${{ github.run_number }} libs-release-local
  create-github-release:
    name: Create GitHub Release
    needs:
      - build-and-stage-release
      - promote-release
    runs-on: ubuntu-latest
    steps:
      - name: Check Out Code
        uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
      - name: Create GitHub Release
        uses: ./.github/actions/create-github-release
        with:
          milestone: ${{ needs.build-and-stage-release.outputs.version }}
          token: ${{ secrets.GH_ACTIONS_REPO_TOKEN }}
