Refine Android coverage workflow scripts #565
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: Test Android build scripts | |
| on: | |
| pull_request: | |
| paths: | |
| - '.github/workflows/scripts-android.yml' | |
| - 'scripts/setup-workspace.sh' | |
| - 'scripts/build-android-port.sh' | |
| - 'scripts/build-android-app.sh' | |
| - 'scripts/run-android-instrumentation-tests.sh' | |
| - 'scripts/android/lib/**/*.java' | |
| - 'scripts/android/tests/**/*.java' | |
| - 'scripts/android/screenshots/**' | |
| - '!scripts/android/screenshots/**/*.md' | |
| - 'scripts/templates/**' | |
| - '!scripts/templates/**/*.md' | |
| - 'CodenameOne/src/**' | |
| - '!CodenameOne/src/**/*.md' | |
| - 'Ports/Android/**' | |
| - '!Ports/Android/**/*.md' | |
| - 'maven/**' | |
| - '!maven/core-unittests/**' | |
| - 'tests/**' | |
| - '!tests/**/*.md' | |
| - '!docs/**' | |
| push: | |
| branches: | |
| - master | |
| paths: | |
| - '.github/workflows/scripts-android.yml' | |
| - 'scripts/setup-workspace.sh' | |
| - 'scripts/build-android-port.sh' | |
| - 'scripts/build-android-app.sh' | |
| - 'scripts/run-android-instrumentation-tests.sh' | |
| - 'scripts/android/lib/**/*.java' | |
| - 'scripts/android/tests/**/*.java' | |
| - 'scripts/android/screenshots/**' | |
| - '!scripts/android/screenshots/**/*.md' | |
| - 'scripts/templates/**' | |
| - '!scripts/templates/**/*.md' | |
| - 'CodenameOne/src/**' | |
| - '!CodenameOne/src/**/*.md' | |
| - 'Ports/Android/**' | |
| - '!Ports/Android/**/*.md' | |
| - 'maven/**' | |
| - '!maven/core-unittests/**' | |
| - 'tests/**' | |
| - '!tests/**/*.md' | |
| - '!docs/**' | |
| # The token in secrets.CN1SS_GH_TOKEN was generated on | |
| # Oct 16th 2025. If in Oct 2026 builds start failing, it | |
| # means the token needs to be regenerated: | |
| # 1. Go to https://github.com/settings/tokens → “Developer settings” → “Personal access tokens”. | |
| # 2. Choose Fine-grained token (recommended). | |
| # 3. Grant: | |
| # • Repository access → select Codename One | |
| # • Permissions: | |
| # • Contents → Read and Write | |
| # • Pull requests → Read and Write | |
| # • Issues → Read and Write | |
| # 4. Copy the generated token | |
| # 5. Go to https://github.com/codenameone/CodenameOne/settings/secrets/actions | |
| # and edit the CN1SS_GH_TOKEN to use the new token | |
| jobs: | |
| build-android: | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| issues: write | |
| runs-on: ubuntu-latest | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.CN1SS_GH_TOKEN }} | |
| GH_TOKEN: ${{ secrets.CN1SS_GH_TOKEN }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup workspace | |
| run: ./scripts/setup-workspace.sh -q -DskipTests | |
| - name: Build Android port | |
| run: ./scripts/build-android-port.sh -q -DskipTests | |
| - name: Build Hello Codename One Android app | |
| id: build-android-app | |
| run: ./scripts/build-android-app.sh -q -DskipTests | |
| - name: Enable KVM for Android emulator | |
| 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: Run Android instrumentation tests | |
| uses: reactivecircus/android-emulator-runner@v2 | |
| env: | |
| CN1SS_SKIP_COMMENT: "1" | |
| with: | |
| api-level: 31 | |
| arch: x86_64 | |
| target: google_apis | |
| script: | | |
| ./scripts/run-android-instrumentation-tests.sh "${{ steps.build-android-app.outputs.gradle_project_dir }}" | |
| - name: Collect Android coverage artifacts | |
| if: always() | |
| run: ./scripts/android/collect-android-coverage-artifacts.sh | |
| - name: Upload Android coverage artifacts | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: android-coverage-artifacts | |
| path: android-quality-artifacts | |
| if-no-files-found: ignore | |
| - name: Publish Android coverage preview | |
| if: ${{ always() && github.server_url == 'https://github.com' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) }} | |
| id: publish-android-coverage | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| SERVER_URL: ${{ github.server_url }} | |
| REPOSITORY: ${{ github.repository }} | |
| RUN_ID: ${{ github.run_id }} | |
| RUN_ATTEMPT: ${{ github.run_attempt }} | |
| run: ./scripts/android/publish-android-coverage-preview.sh | |
| - name: Generate Android test report comment | |
| if: always() | |
| env: | |
| COVERAGE_HTML_URL: ${{ steps.publish-android-coverage.outputs.coverage_url }} | |
| run: python3 ./scripts/android/generate-android-report-comment.py | |
| - name: Upload Android report comment | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: android-report-comment | |
| path: android-comment.md | |
| - name: Publish Android test report comment | |
| if: ${{ github.event_name == 'pull_request' }} | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const marker = '<!-- CN1SS_ANDROID_COMMENT -->'; | |
| const commentPath = 'android-comment.md'; | |
| if (!fs.existsSync(commentPath)) { | |
| core.warning('android-comment.md was not generated.'); | |
| return; | |
| } | |
| const body = fs.readFileSync(commentPath, 'utf8'); | |
| if (!body.includes(marker)) { | |
| core.warning('Comment marker missing from android-comment.md.'); | |
| return; | |
| } | |
| const { owner, repo } = context.repo; | |
| const issue_number = context.issue.number; | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| owner, | |
| repo, | |
| issue_number, | |
| per_page: 100, | |
| }); | |
| const existing = comments.find(comment => comment.body && comment.body.includes(marker)); | |
| if (existing) { | |
| await github.rest.issues.updateComment({ | |
| owner, | |
| repo, | |
| comment_id: existing.id, | |
| body, | |
| }); | |
| } else { | |
| await github.rest.issues.createComment({ | |
| owner, | |
| repo, | |
| issue_number, | |
| body, | |
| }); | |
| } | |
| - name: Upload emulator screenshot | |
| if: always() # still collect it if tests fail | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: emulator-screenshot | |
| path: artifacts/*.png | |
| if-no-files-found: warn | |
| retention-days: 14 | |
| compression-level: 6 |