mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-28 05:13:53 +01:00
87 lines
2.9 KiB
YAML
87 lines
2.9 KiB
YAML
name: Android CI
|
|
|
|
on: [push, pull_request_target, workflow_dispatch]
|
|
|
|
permissions:
|
|
pull-requests: write
|
|
contents: read
|
|
issues: write
|
|
|
|
concurrency:
|
|
group: build-${{ github.event.pull_request.number || github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
build:
|
|
name: Run tests and generate APK
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Set up JDK
|
|
uses: actions/setup-java@v3
|
|
with:
|
|
distribution: 'temurin'
|
|
java-version: '17'
|
|
|
|
- name: Cache packages
|
|
id: cache-packages
|
|
uses: actions/cache@v3
|
|
with:
|
|
path: |
|
|
~/.gradle/caches
|
|
~/.gradle/wrapper
|
|
key: gradle-packages-${{ runner.os }}-${{ hashFiles('**/*.gradle', '**/*.gradle.kts', 'gradle.properties') }}
|
|
restore-keys: gradle-packages-${{ runner.os }}
|
|
|
|
- name: Generate betaDebug APK
|
|
run: bash ./gradlew assembleBetaDebug --stacktrace
|
|
|
|
- name: Upload betaDebug APK
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: betaDebugAPK
|
|
path: app/build/outputs/apk/beta/debug/app-*.apk
|
|
|
|
- name: Generate prodDebug APK
|
|
run: bash ./gradlew assembleProdDebug --stacktrace
|
|
|
|
- name: Upload prodDebug APK
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: prodDebugAPK
|
|
path: app/build/outputs/apk/prod/debug/app-*.apk
|
|
|
|
- name: Comment on PR with APK download links
|
|
if: github.event_name == 'pull_request_target' # Updated for proper permissions
|
|
uses: actions/github-script@v6
|
|
with:
|
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
script: |
|
|
const { data: { artifacts } } = await github.rest.actions.listWorkflowRunArtifacts({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
run_id: context.runId
|
|
});
|
|
|
|
const betaArtifact = artifacts.find(artifact => artifact.name === "betaDebugAPK");
|
|
const prodArtifact = artifacts.find(artifact => artifact.name === "prodDebugAPK");
|
|
|
|
if (betaArtifact && prodArtifact) {
|
|
const betaDownloadUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/suites/${context.runId}/artifacts/${betaArtifact.id}`;
|
|
const prodDownloadUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/suites/${context.runId}/artifacts/${prodArtifact.id}`;
|
|
|
|
const commentBody = `
|
|
📱 **APK for pull request is ready!** 📱
|
|
- [Download Beta APK](${betaDownloadUrl})
|
|
- [Download Prod APK](${prodDownloadUrl})
|
|
`;
|
|
|
|
await github.rest.issues.createComment({
|
|
issue_number: context.issue.number,
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
body: commentBody
|
|
});
|
|
}
|