|
1 | | -name: Compose UI Tests |
| 1 | +name: UI Tests |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | workflow_run: |
5 | 5 | workflows: ["CI"] |
6 | 6 | types: |
7 | 7 | - completed |
8 | | - branches: [ "master" ] |
| 8 | + branches: |
| 9 | + - "master" |
9 | 10 |
|
10 | 11 | jobs: |
11 | | - compose-tests: |
12 | | - if: > |
13 | | -# github.event.workflow_run.conclusion == 'success' && |
14 | | -# github.event.workflow_run.event == 'pull_request' && |
15 | | - github.event.workflow_run.pull_requests[0].draft == false |
| 12 | + check-conditions: |
16 | 13 | runs-on: ubuntu-latest |
| 14 | + outputs: |
| 15 | + should_run: ${{ steps.check-pr-status.outputs.should_run }} |
| 16 | + pr_number: ${{ steps.find-pr.outputs.pr_number }} |
17 | 17 |
|
18 | 18 | steps: |
19 | | - - name: Checkout code |
| 19 | + - name: Find associated pull request |
| 20 | + id: find-pr |
| 21 | + uses: actions/github-script@v7 |
| 22 | + with: |
| 23 | + script: | |
| 24 | + const commitSha = '${{ github.event.workflow_run.head_sha }}'; |
| 25 | + const { data: pullRequests } = await github.rest.pulls.list({ |
| 26 | + owner: context.repo.owner, |
| 27 | + repo: context.repo.repo, |
| 28 | + state: 'open', |
| 29 | + sort: 'updated', |
| 30 | + direction: 'desc', |
| 31 | + per_page: 100 |
| 32 | + }); |
| 33 | +
|
| 34 | + for (const pr of pullRequests) { |
| 35 | + if (pr.head.sha === commitSha) { |
| 36 | + console.log(`Found matching PR: #${pr.number}`); |
| 37 | + core.setOutput('pr_number', pr.number); |
| 38 | + return; |
| 39 | + } |
| 40 | + } |
| 41 | +
|
| 42 | + console.log('No matching PR found for this commit'); |
| 43 | + core.setOutput('pr_number', ''); |
| 44 | +
|
| 45 | + - name: Check PR draft status |
| 46 | + id: check-pr-status |
| 47 | + if: steps.find-pr.outputs.pr_number != '' |
| 48 | + uses: actions/github-script@v7 |
| 49 | + with: |
| 50 | + script: | |
| 51 | + const prNumber = parseInt('${{ steps.find-pr.outputs.pr_number }}'); |
| 52 | + if (!prNumber) { |
| 53 | + console.log('No PR number found, skipping UI tests'); |
| 54 | + core.setOutput('should_run', 'false'); |
| 55 | + return; |
| 56 | + } |
| 57 | +
|
| 58 | + const { data: pr } = await github.rest.pulls.get({ |
| 59 | + owner: context.repo.owner, |
| 60 | + repo: context.repo.repo, |
| 61 | + pull_number: prNumber |
| 62 | + }); |
| 63 | +
|
| 64 | + const shouldRun = !pr.draft; |
| 65 | + console.log(`PR #${prNumber} draft status: ${pr.draft}`); |
| 66 | + console.log(`Should run UI tests: ${shouldRun}`); |
| 67 | +
|
| 68 | + core.setOutput('should_run', shouldRun.toString()); |
| 69 | +
|
| 70 | + ui-tests: |
| 71 | + needs: check-conditions |
| 72 | + if: ${{ needs.check-conditions.outputs.should_run == 'true' }} |
| 73 | + runs-on: ubuntu-latest |
| 74 | + |
| 75 | + steps: |
| 76 | + - name: Checkout the code |
20 | 77 | uses: actions/checkout@v4 |
21 | 78 |
|
22 | 79 | - name: Set up JDK 17 |
|
43 | 100 | - name: Make gradlew executable |
44 | 101 | run: chmod +x gradlew |
45 | 102 |
|
46 | | - - name: Build debug APK |
| 103 | + - name: Build for debug with gradle |
47 | 104 | run: ./gradlew assembleDebug |
48 | 105 |
|
49 | 106 | - name: Start Android Emulator |
|
57 | 114 | - name: Run Compose UI tests |
58 | 115 | run: ./gradlew connectedDebugAndroidTest |
59 | 116 |
|
60 | | - - name: Upload test reports |
61 | | - uses: actions/upload-artifact@v4 |
| 117 | + - name: Upload UI test report |
62 | 118 | if: always() |
| 119 | + uses: actions/upload-artifact@v4 |
63 | 120 | with: |
64 | 121 | name: compose_test_report |
65 | 122 | path: app/build/reports/androidTests/connected/ |
0 commit comments