name: Release build
on:
  push:
    tags:
      - "[0-9]+.[0-9]+.[0-9]+"
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
      with:
        fetch-depth: 0
        ref: ${{ github.ref }}
    - name: Setting up publication keystore
      run: |
        echo "${{ secrets.ANDROID_KEYSTORE }}" > ${HOME}/release.jks.asc
        gpg -q --yes --batch -d --passphrase="${{ secrets.ENCRYPTION_KEY }}" -o ${HOME}/release.jks ${HOME}/release.jks.asc
        echo -e "signing.store=${HOME}/release.jks\nsigning.key_passphrase=${{ secrets.ANDROID_KEYSTORE_KEY_PASSPHRASE }}\nsigning.alias=release\nsigning.store_passphrase=${{ secrets.ANDROID_KEYSTORE_STORE_PASSPHRASE }}" > local.properties
    - name: Set up JDK 1.8
      uses: actions/setup-java@v1
      with:
        java-version: 1.8
    - name: Build Otter
      run: |
        mkdir -p /home/runner/.android && touch /home/runner/.android/repositories.cfg
        ./gradlew assembleRelease
    - name: Create Otter's release
      id: create_release
      uses: actions/create-release@v1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        tag_name: ${{ github.ref }}
        release_name: ${{ github.ref }}
        draft: false
        prerelease: true
    - name: Upload Otter's artifact (full version)
      uses: actions/upload-release-asset@v1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        upload_url: ${{ steps.create_release.outputs.upload_url }}
        asset_path: app/build/outputs/apk/release/app-release.apk
        asset_name: otter-full-release.apk
        asset_content_type: application/zip
