name: Build Java-LibKiwix

on:
  push:
    branches-ignore:
      - '*'
      - '*/**'
    tags:
      - '*'
      - '*/**'

jobs:
  publish:

    runs-on: ubuntu-18.04

    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 1

      - name: Set up JDK 11
        uses: actions/setup-java@v2
        with:
          distribution: adopt
          java-version: 11

      - name: Install dependencies
        run: bash ./install_deps.sh

      - name: Compile Project
        run: |
          ./gradlew generateHeaderFilesFromJavaWrapper
          ./gradlew build

      - name: Release build
        run: |
          ./gradlew assemble

      - name: Genrate Source jar
        run: |
          ./gradlew androidSourcesJar

      - name: Publish to MavenCentral
        run: ./gradlew publishReleasePublicationToSonatypeRepository --max-workers 1 closeAndReleaseSonatypeStagingRepository
        env:
          ossrhUsername: ${{ secrets.OSSRH_USERNAME }}
          ossrhPassword: ${{ secrets.OSSRH_PASSWORD }}
          signing.keyId: ${{ secrets.SIGNING_KEY_ID }}
          siging.password: ${{ secrets.SIGNING_PASSWORD }}
          siging.key: ${{ secrets.SIGNING_KEY }}
          sonatypeStagingProfileId: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }}
