name: "Release Build"

on:
  push:
    tags:
      - "v*"

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - name: Set up JDK 12
        uses: actions/setup-java@v1
        with:
          java-version: '12.x'
      - uses: subosito/flutter-action@v1
        with:
          channel: 'stable'
      - name: Set up Flutter
        run: flutter pub get
      - name: Generate files with Builder
        run: flutter packages pub run build_runner build --delete-conflicting-outputs
      - name: Build with Flutter
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: flutter build apk
      - name: Add version to APK
        run: mv build/app/outputs/flutter-apk/app-release.apk revanced-manager-$GITHUB_REF_NAME.apk
      - name: Publish release APK
        uses: "marvinpinto/action-automatic-releases@latest"
        with:
          repo_token: "${{ secrets.GITHUB_TOKEN }}"
          prerelease: false
          files: revanced-manager-$GITHUB_REF_NAME.apk
