mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-28 05:13:53 +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
|
name: Android CI
|
||||||
|
|
||||||
on: [push, pull_request, workflow_dispatch]
|
on: [push, pull_request, pull_request_target, workflow_dispatch]
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
pull-requests: write
|
pull-requests: write
|
||||||
|
|
@ -19,9 +19,11 @@ concurrency:
|
||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build-and-upload:
|
||||||
name: Run tests and generate APK
|
name: Run tests and generate APK
|
||||||
runs-on: ubuntu-latest
|
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:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
@ -114,19 +116,29 @@ jobs:
|
||||||
with:
|
with:
|
||||||
name: prodDebugAPK
|
name: prodDebugAPK
|
||||||
path: app/build/outputs/apk/prod/debug/app-*.apk
|
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
|
- 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
|
uses: actions/github-script@v6
|
||||||
with:
|
with:
|
||||||
github-token: ${{secrets.GITHUB_TOKEN}}
|
|
||||||
script: |
|
script: |
|
||||||
try {
|
try {
|
||||||
const token = process.env.GITHUB_TOKEN;
|
const token = process.env.GH_TOKEN;
|
||||||
if (!token) {
|
if (!token) {
|
||||||
throw new Error('GITHUB_TOKEN is not set. Please check workflow permissions.');
|
throw new Error('GITHUB_TOKEN is not set.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const { data: { artifacts } } = await github.rest.actions.listWorkflowRunArtifacts({
|
const { data: { artifacts } } = await github.rest.actions.listWorkflowRunArtifacts({
|
||||||
owner: context.repo.owner,
|
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 prodDownloadUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/suites/${context.runId}/artifacts/${prodArtifact.id}`;
|
||||||
|
|
||||||
const commentBody = `
|
const commentBody = `
|
||||||
📱 **APK for pull request is ready to see the changes** 📱
|
📱 **APK for pull request is ready to see the changes** 📱
|
||||||
- [Download Beta APK](${betaDownloadUrl})
|
- [Download Beta APK](${betaDownloadUrl})
|
||||||
- [Download Prod APK](${prodDownloadUrl})
|
- [Download Prod APK](${prodDownloadUrl})
|
||||||
`;
|
`;
|
||||||
|
|
||||||
await github.rest.issues.createComment({
|
await github.rest.issues.createComment({
|
||||||
|
|
@ -163,15 +175,9 @@ jobs:
|
||||||
repo: context.repo.repo,
|
repo: context.repo.repo,
|
||||||
body: commentBody
|
body: commentBody
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('Successfully posted comment with APK download links');
|
console.log('Successfully posted comment with APK download links');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error in PR comment creation:', error);
|
console.error('Error in PR comment creation:', error);
|
||||||
if (error.message.includes('GITHUB_TOKEN')) {
|
core.setFailed(`Workflow failed: ${error.message}`);
|
||||||
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}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue