name: Build

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0

      - name: Set up JDK
        uses: actions/setup-java@v1
        with:
          java-version: 8

      - name: Set jadx version
        run: |
          JADX_LAST_TAG=$(git describe --abbrev=0 --tags)
          JADX_VERSION="${JADX_LAST_TAG:1}.$GITHUB_RUN_NUMBER-${GITHUB_SHA:0:8}"
          echo "JADX_VERSION=$JADX_VERSION" >> $GITHUB_ENV

      - uses: burrunan/gradle-cache-action@v1
        name: Build with Gradle
        env:
          TERM: dumb
        with:
          arguments: build dist copyExe --warning-mode=all

      - name: Save bundle artifact
        if: success() && github.event_name == 'push'
        uses: actions/upload-artifact@v2
        with:
          name: ${{ format('jadx-{0}', env.JADX_VERSION) }}
          # Waiting fix for https://github.com/actions/upload-artifact/issues/39 to upload zip file
          # Upload unpacked files for now
          path: build/jadx/**/*
          if-no-files-found: error

      - name: Save exe artifact
        if: success() && github.event_name == 'push'
        uses: actions/upload-artifact@v2
        with:
          name: ${{ format('jadx-gui-{0}-no-jre-win.exe', env.JADX_VERSION) }}
          path: build/*.exe
          if-no-files-found: error
