itachi1706/SingBuses

View on GitHub
.github/workflows/android.yml

Summary

Maintainability
Test Coverage
name: Android CI

on: [push,pull_request]

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

jobs:
  build:
    name: Android Compilation Test
    runs-on: ubuntu-latest
    steps:
    - name: Checkout Repository
      uses: actions/checkout@v4.1.7
    - name: set up JDK 17
      uses: actions/setup-java@v4
      with:
        distribution: 'temurin'
        java-version: 17
        cache: 'gradle'
    - name: Copy secure values
      run: |
        echo $GOOGLE_SERVICES > ./app/google-services.json
        echo $SECRET_FILE > ./secrets.properties
      env:
        GOOGLE_SERVICES: ${{ secrets.GOOGLE_SERVICES }}
        SECRET_FILE: ${{ secrets.SECRET_FILE }}
    - name: Make Gradle executable
      run: chmod +x gradlew
    - name: Build with Gradle
      run: ./gradlew build
    - name: Move APK file to main folder
      run: mv ./app/build/outputs/apk/debug/app-debug.apk ./SingBuses-debug.apk
    - uses: actions/upload-artifact@v4
      with:
        name: SingBuses-debug-apk
        path: ./SingBuses-debug.apk
  device-test-latest:
    runs-on: ubuntu-latest
    if: github.event_name != 'pull_request' && github.ref != 'refs/heads/master' && !startsWith(github.ref, 'refs/tags/') && github.actor != 'dependabot[bot]'
    name: Test run on latest supported Android Device
    steps:
      - name: checkout
        uses: actions/checkout@v4.1.7
      - name: Run lscpu
        run: lscpu
      - name: Enable KVM group perms
        run: |
          echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
          sudo udevadm control --reload-rules
          sudo udevadm trigger --name-match=kvm
      - name: Copy secure values
        run: |
          echo $GOOGLE_SERVICES > ./app/google-services.json
          echo $SECRET_FILE > ./secrets.properties
        env:
          GOOGLE_SERVICES: ${{ secrets.GOOGLE_SERVICES }}
          SECRET_FILE: ${{ secrets.SECRET_FILE }}
      - name: Make Gradle executable
        run: chmod +x gradlew
      - name: List Available Android Devices
        run: $ANDROID_HOME/cmdline-tools/latest/bin/avdmanager list
      - name: set up JDK 17
        uses: actions/setup-java@v4
        with:
          distribution: 'temurin'
          java-version: 17
          cache: 'gradle'
      - name: run tests
        uses: reactivecircus/android-emulator-runner@v2.32.0
        with:
          api-level: 34
          target: google_apis
          profile: 'pixel_6_pro'
          arch: x86_64
          script: ./gradlew connectedAndroidTest
  device-test-full:
    runs-on: ubuntu-latest
    if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
    name: Test run on all Android Devices
    strategy:
      fail-fast: true
      matrix:
        api-level: [23, 24, 25, 26, 28, 29, 30, 31, 32, 33, 34, 35]
    steps:
    - name: Checkout Repository
      uses: actions/checkout@v4.1.7
    - name: Run lscpu
      run: lscpu
    - name: Enable KVM group perms
      run: |
        echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
        sudo udevadm control --reload-rules
        sudo udevadm trigger --name-match=kvm
    - name: Copy secure values
      run: |
        echo $GOOGLE_SERVICES > ./app/google-services.json
        echo $SECRET_FILE > ./secrets.properties
      env:
        GOOGLE_SERVICES: ${{ secrets.GOOGLE_SERVICES }}
        SECRET_FILE: ${{ secrets.SECRET_FILE }}
    - name: Make Gradle executable
      run: chmod +x gradlew
    - name: List Available Android Devices
      run: $ANDROID_HOME/cmdline-tools/latest/bin/avdmanager list
    - name: set up JDK 17
      uses: actions/setup-java@v4
      with:
        distribution: 'temurin'
        java-version: 17
        cache: 'gradle'
    - name: run tests
      uses: reactivecircus/android-emulator-runner@v2.32.0
      with:
        api-level: ${{ matrix.api-level }}
        target: google_apis
        profile: 'pixel_6_pro'
        arch: x86_64
        script: ./gradlew connectedAndroidTest
  release:
    name: Release APK file
    if: startsWith(github.ref, 'refs/tags/')
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4.1.7
        with:
          token: ${{ secrets.GH_PAT }}
      - name: set up JDK 17
        uses: actions/setup-java@v4
        with:
          distribution: 'temurin'
          java-version: 17
          cache: 'gradle'
      - name: Copy secure values
        run: |
          echo $GOOGLE_SERVICES > ./app/google-services.json
          echo $SECRET_FILE > ./secrets.properties
        env:
          GOOGLE_SERVICES: ${{ secrets.GOOGLE_SERVICES }}
          SECRET_FILE: ${{ secrets.SECRET_FILE }}
      - name: Make Gradle executable
        run: chmod +x gradlew
      - name: Build with Gradle
        run: ./gradlew build
      - name: Move APK file to main folder
        run: mv ./app/build/outputs/apk/debug/app-debug.apk ./SingBuses-debug.apk
      - name: Update CHANGELOG
        id: changelog
        uses: requarks/changelog-action@v1
        with:
          token: ${{ github.token }}
          tag: ${{ github.ref_name }}
      - name: Create Release
        id: create_release
        uses: softprops/action-gh-release@v2
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Provided by GH Actions
        with:
          tag_name: ${{ github.ref }}
          name: Release ${{ github.ref_name }}
          body: ${{ steps.changelog.outputs.changes }}
          generate_release_notes: true
          draft: false
          prerelease: false
          files: SingBuses-debug.apk
      - name: Commit CHANGELOG.md
        uses: stefanzweifel/git-auto-commit-action@v5
        with:
          branch: master
          commit_message: 'docs: update CHANGELOG.md for ${{ github.ref_name }} [skip ci]'
          file_pattern: CHANGELOG.md