|
| 1 | +name: Build and Test |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ "main" ] |
| 6 | + pull_request: |
| 7 | + branches: [ "main" ] |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +# Ensure that only the latest commit is tested for PRs |
| 11 | +concurrency: |
| 12 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} |
| 13 | + cancel-in-progress: true |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: write # Needed for git-auto-commit-action |
| 17 | + |
| 18 | +jobs: |
| 19 | + build_test_lint: |
| 20 | + name: "Build, Test, and Lint" |
| 21 | + runs-on: ubuntu-latest |
| 22 | + timeout-minutes: 60 |
| 23 | + |
| 24 | + steps: |
| 25 | + - name: Checkout code |
| 26 | + uses: actions/checkout@v4 |
| 27 | + |
| 28 | + - name: Set up JDK 17 |
| 29 | + uses: actions/setup-java@v4 |
| 30 | + with: |
| 31 | + java-version: '17' |
| 32 | + distribution: 'temurin' |
| 33 | + |
| 34 | + - name: Setup Gradle |
| 35 | + uses: gradle/actions/setup-gradle@v4 |
| 36 | + # Add cache-encryption-key if you set up the GRADLE_ENCRYPTION_KEY secret |
| 37 | + # with: |
| 38 | + # cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }} |
| 39 | + |
| 40 | + - name: Grant execute permission for gradlew |
| 41 | + run: chmod +x gradlew |
| 42 | + |
| 43 | + - name: Build debug APK |
| 44 | + run: ./gradlew assembleDebug --no-configuration-cache |
| 45 | + |
| 46 | + - name: Apply Spotless |
| 47 | + run: ./gradlew spotlessApply --init-script gradle/init.gradle.kts --no-configuration-cache |
| 48 | + |
| 49 | + - name: Commit Spotless changes |
| 50 | + uses: stefanzweifel/git-auto-commit-action@v5 |
| 51 | + with: |
| 52 | + commit_message: 🤖 Apply Spotless formatting |
| 53 | + file_pattern: '**/*.kt **/*.kts **/*.java **/*.xml' |
| 54 | + |
| 55 | + - name: Verify Screenshot Tests (AndroidX) |
| 56 | + run: ./gradlew verifyDebugAndroidTestScreenshot |
| 57 | + |
| 58 | + - name: Run local unit tests |
| 59 | + run: ./gradlew testDebugUnitTest |
| 60 | + |
| 61 | + - name: Check lint |
| 62 | + run: ./gradlew lintDebug |
| 63 | + |
| 64 | + - name: Upload build outputs (APKs) |
| 65 | + if: ${{ !cancelled() }} |
| 66 | + uses: actions/upload-artifact@v4 |
| 67 | + with: |
| 68 | + name: APKs |
| 69 | + path: '**/build/outputs/apk/debug/*.apk' |
| 70 | + |
| 71 | + - name: Upload JVM local test results (XML) |
| 72 | + if: ${{ !cancelled() }} |
| 73 | + uses: actions/upload-artifact@v4 |
| 74 | + with: |
| 75 | + name: local-test-results |
| 76 | + path: '**/build/test-results/test*UnitTest/TEST-*.xml' |
| 77 | + |
| 78 | + - name: Upload lint reports (HTML) |
| 79 | + if: ${{ !cancelled() }} |
| 80 | + uses: actions/upload-artifact@v4 |
| 81 | + with: |
| 82 | + name: lint-reports-html |
| 83 | + path: '**/build/reports/lint-results-debug.html' |
| 84 | + |
| 85 | + androidTest: |
| 86 | + name: "Instrumentation Tests (GMD)" |
| 87 | + needs: build_test_lint # Run after the build job |
| 88 | + runs-on: ubuntu-latest # GMD requires Linux runner with KVM |
| 89 | + timeout-minutes: 60 |
| 90 | + strategy: |
| 91 | + matrix: |
| 92 | + api-level: [34] |
| 93 | + |
| 94 | + steps: |
| 95 | + - name: Delete unnecessary tools 🔧 |
| 96 | + |
| 97 | + with: |
| 98 | + android: false # Don't remove Android tools |
| 99 | + tool-cache: true # Remove image tool cache |
| 100 | + dotnet: true |
| 101 | + haskell: true |
| 102 | + swap-storage: true |
| 103 | + |
| 104 | + - name: Enable KVM group perms |
| 105 | + run: | |
| 106 | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules |
| 107 | + sudo udevadm control --reload-rules |
| 108 | + sudo udevadm trigger --name-match=kvm |
| 109 | +
|
| 110 | + - name: Checkout code |
| 111 | + uses: actions/checkout@v4 |
| 112 | + |
| 113 | + - name: Set up JDK 17 |
| 114 | + uses: actions/setup-java@v4 |
| 115 | + with: |
| 116 | + java-version: '17' |
| 117 | + distribution: 'temurin' |
| 118 | + |
| 119 | + - name: Setup Gradle |
| 120 | + uses: gradle/actions/setup-gradle@v4 |
| 121 | + # Add cache-encryption-key if you set up the GRADLE_ENCRYPTION_KEY secret |
| 122 | + # with: |
| 123 | + # cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }} |
| 124 | + |
| 125 | + - name: Grant execute permission for gradlew |
| 126 | + run: chmod +x gradlew |
| 127 | + |
| 128 | + - name: Run instrumentation tests (Gradle Managed Device) |
| 129 | + # Assumes GMD device name 'pixel6Api${{ matrix.api-level }}' and task name accordingly. |
| 130 | + # Adjust the task name if your GMD configuration is different (e.g., includes module name like :app:). |
| 131 | + run: ./gradlew pixel6Api${{ matrix.api-level }}DebugAndroidTest --info |
| 132 | + |
| 133 | + - name: Upload test reports |
| 134 | + if: ${{ !cancelled() }} |
| 135 | + uses: actions/upload-artifact@v4 |
| 136 | + with: |
| 137 | + name: test-reports-gmd-api-${{ matrix.api-level }} |
| 138 | + # GMD reports are typically in a path like this, adjust if needed |
| 139 | + path: '**/build/outputs/androidTest-results/managedDevice/' |
0 commit comments