Add compose test step to CI #3
Workflow file for this run
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: UI Tests | |
| on: | |
| push: | |
| branches: [ "master" ] | |
| pull_request: | |
| branches: [ "master" ] | |
| jobs: | |
| check-conditions: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| should_run: ${{ steps.check-pr-status.outputs.should_run }} | |
| pr_number: ${{ steps.find-pr.outputs.pr_number }} | |
| steps: | |
| - name: Find associated pull request | |
| id: find-pr | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const commitSha = '${{ github.event.workflow_run.head_sha }}'; | |
| const { data: pullRequests } = await github.rest.pulls.list({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| state: 'open', | |
| sort: 'updated', | |
| direction: 'desc', | |
| per_page: 100 | |
| }); | |
| for (const pr of pullRequests) { | |
| if (pr.head.sha === commitSha) { | |
| console.log(`Found matching PR: #${pr.number}`); | |
| core.setOutput('pr_number', pr.number); | |
| return; | |
| } | |
| } | |
| console.log('No matching PR found for this commit'); | |
| core.setOutput('pr_number', ''); | |
| - name: Check PR draft status | |
| id: check-pr-status | |
| if: steps.find-pr.outputs.pr_number != '' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const prNumber = parseInt('${{ steps.find-pr.outputs.pr_number }}'); | |
| if (!prNumber) { | |
| console.log('No PR number found, skipping UI tests'); | |
| core.setOutput('should_run', 'false'); | |
| return; | |
| } | |
| const { data: pr } = await github.rest.pulls.get({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: prNumber | |
| }); | |
| const shouldRun = !pr.draft; | |
| console.log(`PR #${prNumber} draft status: ${pr.draft}`); | |
| console.log(`Should run UI tests: ${shouldRun}`); | |
| core.setOutput('should_run', shouldRun.toString()); | |
| ui-tests: | |
| needs: check-conditions | |
| if: ${{ needs.check-conditions.outputs.should_run == 'true' }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout the code | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '17' | |
| distribution: 'adopt' | |
| - name: Cache gradle | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.gradle/caches | |
| ~/.gradle/wrapper | |
| key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
| restore-keys: | | |
| gradle-${{ runner.os }}- | |
| - name: Decode google-services.json | |
| run: echo "$GOOGLE_SERVICES_JSON_BASE64" | base64 -d > app/google-services.json | |
| env: | |
| GOOGLE_SERVICES_JSON_BASE64: ${{ secrets.GOOGLE_SERVICES_JSON_BASE64 }} | |
| - name: Make gradlew executable | |
| run: chmod +x gradlew | |
| - name: Build for debug with gradle | |
| run: ./gradlew assembleDebug | |
| - name: Start Android Emulator | |
| uses: reactivecircus/android-emulator-runner@v2 | |
| with: | |
| api-level: 31 | |
| arch: x86_64 | |
| profile: Nexus 6 | |
| script: ./gradlew connectedDebugAndroidTest | |
| - name: Run Compose UI tests | |
| run: ./gradlew connectedDebugAndroidTest | |
| - name: Upload UI test report | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: compose_test_report | |
| path: app/build/reports/androidTests/connected/ |