CI workflow #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Test | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| pull_request: | |
| branches: [ "main" ] | |
| workflow_dispatch: | |
| # Ensure that only the latest commit is tested for PRs | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: write # Needed for git-auto-commit-action | |
| jobs: | |
| build_test_lint: | |
| name: "Build, Test, and Lint" | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 60 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| - name: Setup Gradle | |
| uses: gradle/actions/setup-gradle@v4 | |
| # Add cache-encryption-key if you set up the GRADLE_ENCRYPTION_KEY secret | |
| # with: | |
| # cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }} | |
| - name: Grant execute permission for gradlew | |
| run: chmod +x gradlew | |
| - name: Build debug APK | |
| run: ./gradlew assembleDebug --no-configuration-cache | |
| - name: Apply Spotless | |
| run: ./gradlew spotlessApply --init-script gradle/init.gradle.kts --no-configuration-cache | |
| - name: Commit Spotless changes | |
| uses: stefanzweifel/git-auto-commit-action@v5 | |
| with: | |
| commit_message: 🤖 Apply Spotless formatting | |
| file_pattern: '**/*.kt **/*.kts **/*.java **/*.xml' | |
| - name: Verify Screenshot Tests (AndroidX) | |
| run: ./gradlew validateDebugScreenshotTest | |
| - name: Run local unit tests | |
| run: ./gradlew testDebugUnitTest | |
| - name: Check lint | |
| run: ./gradlew lintDebug | |
| - name: Upload build outputs (APKs) | |
| if: ${{ !cancelled() }} | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: APKs | |
| path: '**/build/outputs/apk/debug/*.apk' | |
| - name: Upload JVM local test results (XML) | |
| if: ${{ !cancelled() }} | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: local-test-results | |
| path: '**/build/test-results/test*UnitTest/TEST-*.xml' | |
| - name: Upload lint reports (HTML) | |
| if: ${{ !cancelled() }} | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: lint-reports-html | |
| path: '**/build/reports/lint-results-debug.html' | |
| androidTest: | |
| name: "Instrumentation Tests (GMD)" | |
| needs: build_test_lint # Run after the build job | |
| runs-on: ubuntu-latest # GMD requires Linux runner with KVM | |
| timeout-minutes: 60 | |
| strategy: | |
| matrix: | |
| api-level: [34] | |
| steps: | |
| - name: Delete unnecessary tools 🔧 | |
| uses: jlumbroso/free-disk-space@v1.3.1 | |
| with: | |
| android: false # Don't remove Android tools | |
| tool-cache: true # Remove image tool cache | |
| dotnet: true | |
| haskell: true | |
| swap-storage: true | |
| - 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: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| - name: Setup Gradle | |
| uses: gradle/actions/setup-gradle@v4 | |
| # Add cache-encryption-key if you set up the GRADLE_ENCRYPTION_KEY secret | |
| # with: | |
| # cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }} | |
| - name: Grant execute permission for gradlew | |
| run: chmod +x gradlew | |
| - name: Run instrumentation tests (Gradle Managed Device) | |
| # Assumes GMD device name 'pixel6Api${{ matrix.api-level }}' and task name accordingly. | |
| # Adjust the task name if your GMD configuration is different (e.g., includes module name like :app:). | |
| run: ./gradlew pixel6Api${{ matrix.api-level }}DebugAndroidTest --info | |
| - name: Upload test reports | |
| if: ${{ !cancelled() }} | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: test-reports-gmd-api-${{ matrix.api-level }} | |
| # GMD reports are typically in a path like this, adjust if needed | |
| path: '**/build/outputs/androidTest-results/managedDevice/' |