# Releases a new minor / major version of gradle plugins from a release branch
name: Release Gradle Plugins
on:
  workflow_dispatch:
    inputs:
      release-branch-name:
        description: The release branch to use, e.g. v1.9.x
        required: true
      version:
        # TODO (trask) this is redundant
        description: The version of the release, e.g. 1.9.0 (without the "v" prefix)
        required: true

jobs:
  test:
    uses: ./.github/workflows/test.yml

  # testLatestDeps is intentionally not included in the release workflows
  # because any time a new library version is released to maven central
  # it can fail due to test code incompatibility with the new library version,
  # or due to slight changes in emitted telemetry

  smoke-test:
    uses: ./.github/workflows/smoke-test.yml

  # muzzle is intentionally not included in the release workflows
  # because any time a new library version is released to maven central it can fail,
  # and this is not a reason to hold up the release

  examples:
    uses: ./.github/workflows/examples.yml

  release:
    needs: [ test, smoke-test, examples ]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          ref: ${{ github.event.inputs.release-branch-name }}

      - name: Set up JDK 11 for running Gradle
        uses: actions/setup-java@v2
        with:
          distribution: temurin
          java-version: 11

      - name: Build and publish gradle plugins
        uses: gradle/gradle-build-action@v2
        env:
          SONATYPE_USER: ${{ secrets.SONATYPE_USER }}
          SONATYPE_KEY: ${{ secrets.SONATYPE_KEY }}
          GRADLE_PUBLISH_KEY: ${{ secrets.GRADLE_PUBLISH_KEY }}
          GRADLE_PUBLISH_SECRET: ${{ secrets.GRADLE_PUBLISH_SECRET }}
          GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
          GPG_PASSWORD: ${{ secrets.GPG_PASSWORD }}
        with:
          # Don't use publishToSonatype since we don't want to publish the marker artifact
          arguments: build publishPlugins publishPluginMavenPublicationToSonatypeRepository closeAndReleaseSonatypeStagingRepository
          build-root-directory: gradle-plugins
