mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Update android.yml
This commit is contained in:
parent
9f9456f282
commit
876ca037d8
1 changed files with 28 additions and 22 deletions
50
.github/workflows/android.yml
vendored
50
.github/workflows/android.yml
vendored
|
|
@ -1,7 +1,7 @@
|
|||
name: Android CI
|
||||
|
||||
on: [push, pull_request, workflow_dispatch]
|
||||
|
||||
on: [push, pull_request, pull_request_target, workflow_dispatch]
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
|
|
@ -19,9 +19,11 @@ concurrency:
|
|||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
build:
|
||||
build-and-upload:
|
||||
name: Run tests and generate APK
|
||||
runs-on: ubuntu-latest
|
||||
# Run this job for push, pull_request, and workflow_dispatch (not pull_request_target)
|
||||
if: github.event_name == 'push' || github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch'
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
|
@ -114,19 +116,29 @@ jobs:
|
|||
with:
|
||||
name: prodDebugAPK
|
||||
path: app/build/outputs/apk/prod/debug/app-*.apk
|
||||
|
||||
|
||||
comment-on-pr:
|
||||
name: Comment on PR with APK links
|
||||
runs-on: ubuntu-latest
|
||||
if: github.event_name == 'pull_request_target'
|
||||
needs: build-and-upload
|
||||
steps:
|
||||
- name: Checkout base branch
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
ref: ${{ github.base_ref }}
|
||||
|
||||
- name: Comment on PR with APK download links
|
||||
if: github.event_name == 'pull_request'
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
uses: actions/github-script@v6
|
||||
with:
|
||||
github-token: ${{secrets.GITHUB_TOKEN}}
|
||||
script: |
|
||||
try {
|
||||
const token = process.env.GITHUB_TOKEN;
|
||||
if (!token) {
|
||||
throw new Error('GITHUB_TOKEN is not set. Please check workflow permissions.');
|
||||
}
|
||||
|
||||
const token = process.env.GH_TOKEN;
|
||||
if (!token) {
|
||||
throw new Error('GITHUB_TOKEN is not set.');
|
||||
}
|
||||
|
||||
const { data: { artifacts } } = await github.rest.actions.listWorkflowRunArtifacts({
|
||||
owner: context.repo.owner,
|
||||
|
|
@ -152,9 +164,9 @@ jobs:
|
|||
const prodDownloadUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/suites/${context.runId}/artifacts/${prodArtifact.id}`;
|
||||
|
||||
const commentBody = `
|
||||
📱 **APK for pull request is ready to see the changes** 📱
|
||||
- [Download Beta APK](${betaDownloadUrl})
|
||||
- [Download Prod APK](${prodDownloadUrl})
|
||||
📱 **APK for pull request is ready to see the changes** 📱
|
||||
- [Download Beta APK](${betaDownloadUrl})
|
||||
- [Download Prod APK](${prodDownloadUrl})
|
||||
`;
|
||||
|
||||
await github.rest.issues.createComment({
|
||||
|
|
@ -163,15 +175,9 @@ jobs:
|
|||
repo: context.repo.repo,
|
||||
body: commentBody
|
||||
});
|
||||
|
||||
|
||||
console.log('Successfully posted comment with APK download links');
|
||||
} catch (error) {
|
||||
console.error('Error in PR comment creation:', error);
|
||||
if (error.message.includes('GITHUB_TOKEN')) {
|
||||
core.setFailed('Missing or invalid GITHUB_TOKEN. Please check repository secrets configuration.');
|
||||
} else if (error.status === 403) {
|
||||
core.setFailed('Permission denied. Please check workflow permissions in repository settings.');
|
||||
} else {
|
||||
core.setFailed(`Workflow failed: ${error.message}`);
|
||||
}
|
||||
core.setFailed(`Workflow failed: ${error.message}`);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue