diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 764252d41b..8d9e3b0465 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,6 +21,13 @@ jobs: if: github.event.pull_request.draft == false runs-on: ubuntu-latest + permissions: + contents: read + packages: read + + outputs: + artifact-url: ${{ steps.upload-apk.outputs.artifact-url }} + steps: - name: Checkout uses: actions/checkout@v7 @@ -47,6 +54,7 @@ jobs: GOOGLE_SERVICES_JSON_BASE64: ${{ secrets.GOOGLE_SERVICES_JSON_BASE64 }} - name: Build debug app + id: build env: GITHUB_ACTOR: ${{ github.actor }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -57,8 +65,56 @@ jobs: run: ./gradlew testDevDebugUnitTest - name: Upload test report + if: always() && steps.build.outcome == 'success' uses: actions/upload-artifact@v7 with: name: unit_test_report_${{ github.run_number }} path: app/build/reports/tests/testDevDebugUnitTest/ retention-days: 30 + + - name: Upload APK + id: upload-apk + uses: actions/upload-artifact@v7 + with: + name: bitkit-dev-debug-apk_${{ github.run_number }} + path: app/build/outputs/bitkit/devDebug/bitkit-dev-debug-*-universal.apk + retention-days: 30 + if-no-files-found: error + + apk-comment: + needs: build + if: needs.build.outputs.artifact-url != '' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false + runs-on: ubuntu-latest + + permissions: + pull-requests: write + + steps: + - name: Comment APK link on PR + uses: actions/github-script@v8 + env: + ARTIFACT_URL: ${{ needs.build.outputs.artifact-url }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + with: + script: | + const marker = ''; + const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`; + const body = [ + marker, + '### Regtest APK', + '', + `Built from ${process.env.HEAD_SHA} ([run](${runUrl})).`, + '', + `[Download bitkit-dev-debug universal APK](${process.env.ARTIFACT_URL}) (expires in 30 days).`, + ].join('\n'); + const comments = await github.paginate(github.rest.issues.listComments, { + ...context.repo, + issue_number: context.issue.number, + per_page: 100, + }); + const existing = comments.find((c) => c.body?.includes(marker)); + if (existing) { + await github.rest.issues.updateComment({ ...context.repo, comment_id: existing.id, body }); + } else { + await github.rest.issues.createComment({ ...context.repo, issue_number: context.issue.number, body }); + }