name: tool-exportV1-release

on:
  workflow_dispatch:
    inputs:
      tag_name:
        description: 'Release Version (e.g. 2.0.0.Final)'
        required: true

jobs:
  build:
    runs-on: ubuntu-22.04
    steps:
    - uses: actions/checkout@v3
    - name: Set up JDK 17
      uses: actions/setup-java@v3
      with:
        java-version: '17'
        distribution: 'temurin'
    - name: Configure Environment (dispatch)
      if: github.event.inputs.tag_name != null
      run: echo "TAG_NAME=${{ github.event.inputs.tag_name }}" >> $GITHUB_ENV
    - name: Get Upload URL
      run: |
        UPLOAD_URL=`curl https://api.github.com/repos/Apicurio/apicurio-registry/releases/tags/$TAG_NAME | jq -r ".upload_url"`
        echo "UPLOAD_URL=$UPLOAD_URL" >> $GITHUB_ENV
    - name: Log Environment Variables
      run: |
        echo "Tag name:   $TAG_NAME"
        echo "Upload URL: $UPLOAD_URL"
    - name: Get maven wrapper
      run: mvn -N io.takari:maven:wrapper -Dmaven=3.8.2
    - name: Set version
      run: ./mvnw versions:set -DnewVersion="$TAG_NAME"
    - name: Build exportV1 jar
      run: ./mvnw package -pl utils/exportV1/ -am
    - name: Upload exportV1 jar
      id: upload-jar
      uses: actions/upload-release-asset@v1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        upload_url: ${{ env.UPLOAD_URL }}
        asset_path: ./utils/exportV1/target/apicurio-registry-utils-exportV1-${{ env.TAG_NAME }}-runner.jar
        asset_name: apicurio-registry-utils-exportV1-${{ env.TAG_NAME }}.jar
        asset_content_type: application/octet-stream
