name: Release JAR

on:
  push:
    tags:
      - "v[0-9]+.[0-9]+.[0-9]+"  # Matches "v1.2.3" but not "v1.2.3.4"

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    # ---- Create a release first, even if build fails -------------------------
    - name: Create Release
      id: create_release
      uses: actions/create-release@v1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        tag_name: ${{ github.ref }}
        release_name: ${{ github.ref }}
        prerelease: true
        draft: true

    # ---- Set up environment --------------------------------------------------
    - name: Checkout Source
      uses: actions/checkout@v2
    - name: Set up JDK 1.8
      uses: actions/setup-java@v1
      with:
        java-version: 1.8

    # ---- Build the JAR -------------------------------------------------------
    - name: Build the JAR
      run: ./gradlew jar
    - name: Upload JAR to GitHub Release
      uses: actions/upload-release-asset@v1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        upload_url: ${{ steps.create_release.outputs.upload_url }}
        asset_path: build/libs/crux-${{ github.event.release.tag_name }}.jar
        asset_name: crux-${{ github.event.release.tag_name }}.jar
        asset_content_type: application/java-archive

Add new GitHub Action to automatically publish a JAR to GitHub Releases when a tag is created.
Add new GitHub Action to automatically publish a JAR to GitHub Releases when a tag is created.
