name: Publish
on:
  release:
    types: [created]
  workflow_dispatch:

jobs:
  publish-docker:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ github.ref }}
          submodules: recursive
      - name: Set up JDK
        uses: actions/setup-java@v4
        with:
          distribution: 'zulu'
          java-version: 20
      - name: Setup gradle
        uses: gradle/gradle-build-action@v2
      - name: Upload to Docker
        run: make jib
        env:
          DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
          DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}

  publish-github:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ github.ref }}
          submodules: recursive
      - name: Set up JDK
        uses: actions/setup-java@v4
        with:
          distribution: 'zulu'
          java-version: 20
      - name: Setup gradle
        uses: gradle/gradle-build-action@v2
      - name: Build zip
        run: make distZip
      - name: Upload Release
        id: upload-release-asset
        uses: svenstaro/upload-release-action@v1-release
        with:
          repo_token: ${{ secrets.GITHUB_TOKEN }}
          tag: ${{ github.ref }}
          file: ./build/distributions/*.zip
          file_glob: true
