name: Build Artifacts

on:
  push:
    branches: [ master, build-test ]

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

      - name: Set up JDK
        uses: actions/setup-java@v5
        with:
          distribution: temurin
          java-version: 25

      - name: Set jadx version
        run: |
          JADX_REV=$(git rev-list --count HEAD)
          JADX_VERSION="r${JADX_REV}.${GITHUB_SHA:0:7}"
          echo "JADX_VERSION=$JADX_VERSION" >> $GITHUB_ENV

      - name: Setup Gradle
        uses: gradle/actions/setup-gradle@v5

      - name: Build
        run: ./gradlew dist distWin
        env:
          JADX_BUILD_JAVA_VERSION: 11

      - name: Save bundle artifact
        uses: actions/upload-artifact@v6
        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
          retention-days: 14

      - name: Save Windows bundle artifact
        uses: actions/upload-artifact@v6
        with:
          name: ${{ format('jadx-gui-{0}-no-jre-win', env.JADX_VERSION) }}
          # Upload unpacked files for now
          path: jadx-gui/build/jadx-gui-win/*
          if-no-files-found: error
          retention-days: 14

  build-win-bundle:
    runs-on: windows-latest
    steps:
      - uses: actions/checkout@v6
        with:
          fetch-depth: 0

      - name: Set up JDK
        uses: oracle-actions/setup-java@v1
        with:
          release: 25

      - name: Print Java version
        shell: bash
        run: java -version

      - name: Set jadx version
        shell: bash
        run: |
          JADX_REV=$(git rev-list --count HEAD)
          JADX_VERSION="r${JADX_REV}.${GITHUB_SHA:0:7}"
          echo "JADX_VERSION=$JADX_VERSION" >> $GITHUB_ENV

      - name: Setup Gradle
        uses: gradle/actions/setup-gradle@v5

      - name: Build
        run: ./gradlew dist -PbundleJRE=true

      - name: Save Windows with JRE bundle artifact
        uses: actions/upload-artifact@v6
        with:
          name: ${{ format('jadx-gui-{0}-with-jre-win', env.JADX_VERSION) }}
          # Upload unpacked files for now
          path: jadx-gui/build/jadx-gui-with-jre-win/*
          if-no-files-found: error
          retention-days: 14
