name: "Publish WebView Client"

on:
  push:
    tags:
      - "webview-*"
  workflow_dispatch:

jobs:
  create_prerelease:
    runs-on: ubuntu-latest
    permissions:
      contents: write
      packages: write
    defaults:
      run:
        shell: bash

    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      - name: Set up JDK
        uses: actions/setup-java@v3
        with:
          java-version: "16"
          distribution: 'adopt'

      - name: Set up Android SDK
        uses: android-actions/setup-android@v2

      - name: Install Android SDK 32
        run: sdkmanager --install platforms\;android-32

      - name: Get version info
        id: ver
        run: echo "::set-output name=value::$(echo ${{ github.ref }} | sed -e 's/^.*webview-//')"

      - name: Build APKs
        run: >
          ant -noinput -buildfile build.xml dist_android_client
          -Dgradle.params="-Pandroid.ver=${{ steps.ver.outputs.value }} assembleDebug assembleRelease"

      - name: Publish
        uses: softprops/action-gh-release@v1
        if: startsWith(github.ref, 'refs/tags/')
        with:
          files: build/stendhal-webview-*.apk
          prerelease: true
