# Releases a new minor / major version from the HEAD of the main branch
name: Release Build
on:
  workflow_dispatch:
    inputs:
      version:
        description: The version to tag the release with, e.g., 1.2.0, 1.2.1-alpha.1
        required: true

jobs:
  build:
    name: Build and release
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-java@v1
        with:
          java-version: 11
      - name: Build and publish artifacts
        uses: burrunan/gradle-cache-action@v1.6
        with:
          job-id: jdk11
          remote-build-cache-proxy-enabled: false
          arguments: build final closeAndReleaseRepository --stacktrace -Prelease.version=${{ github.event.inputs.version }}
        env:
          BINTRAY_USER: ${{ secrets.BINTRAY_USER }}
          BINTRAY_API_KEY: ${{ secrets.BINTRAY_API_KEY }}
          SONATYPE_USER: ${{ secrets.SONATYPE_USER }}
          SONATYPE_KEY: ${{ secrets.SONATYPE_KEY }}
          GRGIT_USER: ${{ github.actor }}
          GRGIT_PASS: ${{ secrets.GITHUB_TOKEN }}
          GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
          GPG_PASSWORD: ${{ secrets.GPG_PASSWORD }}
      - name: Create Release
        id: create_release
        uses: actions/create-release@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tag_name: v${{ github.event.inputs.version }}
          release_name: Release v${{ github.event.inputs.version }}
          draft: true
          prerelease: false
      - name: Upload Release Asset
        id: upload-release-asset
        uses: actions/upload-release-asset@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          upload_url: ${{ steps.create_release.outputs.upload_url }}
          asset_path: javaagent/build/libs/opentelemetry-javaagent-${{ github.event.inputs.version }}-all.jar
          asset_name: opentelemetry-javaagent-all.jar
          asset_content_type: application/java-archive
