pachli-android/.github/workflows/apk-on-comment.yml

87 lines
3.4 KiB
YAML

name: "Build and sign APK for PR"
# Based on https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows
on:
issue_comment:
types: [created]
jobs:
deploy:
name: Deploy
# Only run on PR comments containing "/apk"
if: github.event.issue.pull_request && contains(github.event.comment.body, '/apk')
runs-on: ubuntu-latest
steps:
- name: Get branch of PR
uses: xt0rted/pull-request-comment-branch@e8b8daa837e8ea7331c0003c9c316a64c6d8b0b1 # v3
id: comment-branch
- name: Set latest commit status as pending
uses: myrotvorets/set-commit-status-action@3730c0a348a2ace3c110851bed53331bc6406e9f # v2.0.1
with:
sha: ${{ steps.comment-branch.outputs.head_sha }}
token: ${{ secrets.GITHUB_TOKEN }}
status: pending
- name: Checkout PR branch ${{ steps.comment-branch.outputs.head_ref }} / ${{ steps.comment-branch.outputs.head_sha }}
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
ref: ${{ steps.comment-branch.outputs.head_sha }}
- uses: ./.github/actions/setup-build-env
with:
gradle-cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
- name: Test
run: ./gradlew app:testOrangeGoogleReleaseUnitTest --stacktrace
- name: Build APK
run: ./gradlew assembleOrangeGoogleRelease --stacktrace
- uses: r0adkll/sign-android-release@dbeba6b98a60b0fd540c02443c7f428cdedf0e7f # v1.0.4
name: Sign app APK
id: sign_app_apk
with:
releaseDirectory: app/build/outputs/apk/orangeGoogle/release
signingKeyBase64: ${{ secrets.SIGNING_KEY }}
alias: ${{ secrets.SIGNING_KEY_ALIAS }}
keyStorePassword: ${{ secrets.KEY_STORE_PASSWORD }}
keyPassword: ${{ secrets.KEY_PASSWORD }}
env:
BUILD_TOOLS_VERSION: "34.0.0"
- name: Upload APK Release Asset
id: upload-release-asset-apk
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4
with:
name: app-release.apk
path: ${{steps.sign_app_apk.outputs.signedReleaseFile}}
compression-level: 0
- name: Add workflow result as comment on PR
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
if: always()
with:
script: |
const name = '${{ github.workflow }}';
const workflowUrl = '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}';
const apkUrl = '${{ steps.upload-release-asset-apk.outputs.artifact-url }}'
const success = '${{ job.status }}' === 'success';
const body = `Workflow ${name}: ${success ? 'succeeded ✅' : 'failed ❌'}\nResults: ${workflowUrl}\nAPK: ${apkUrl}`;
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
})
- name: Set latest commit status as ${{ job.status }}
uses: myrotvorets/set-commit-status-action@3730c0a348a2ace3c110851bed53331bc6406e9f # v2.0.1
if: always()
with:
sha: ${{ steps.comment-branch.outputs.head_sha }}
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status }}