mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Separate Workflow for Commenting on PR with APK Links (#6199)
* Update android.yml * Create android-ci-comment.yml * Update android.yml
This commit is contained in:
parent
44f69fcabd
commit
8dd1091608
2 changed files with 93 additions and 60 deletions
84
.github/workflows/android-ci-comment.yml
vendored
Normal file
84
.github/workflows/android-ci-comment.yml
vendored
Normal file
|
|
@ -0,0 +1,84 @@
|
||||||
|
name: Android CI Comment
|
||||||
|
|
||||||
|
on: [pull_request_target]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
issues: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
comment:
|
||||||
|
name: Comment on PR with APK links
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout base branch
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
ref: ${{ github.base_ref }}
|
||||||
|
|
||||||
|
- name: Download Run ID Artifact
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: run-id
|
||||||
|
|
||||||
|
- name: Read Run ID
|
||||||
|
id: read-run-id
|
||||||
|
run: echo "RUN_ID=$(cat run_id.txt)" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Comment on PR with APK download links
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
uses: actions/github-script@v6
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
try {
|
||||||
|
const token = process.env.GH_TOKEN;
|
||||||
|
if (!token) {
|
||||||
|
throw new Error('GITHUB_TOKEN is not set.');
|
||||||
|
}
|
||||||
|
|
||||||
|
const runId = "${{ env.RUN_ID }}";
|
||||||
|
if (!runId) {
|
||||||
|
throw new Error('Run ID not found.');
|
||||||
|
}
|
||||||
|
|
||||||
|
const { data: { artifacts } } = await github.rest.actions.listWorkflowRunArtifacts({
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
run_id: runId
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!artifacts || artifacts.length === 0) {
|
||||||
|
console.log('No artifacts found for this workflow run.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const betaArtifact = artifacts.find(artifact => artifact.name === "betaDebugAPK");
|
||||||
|
const prodArtifact = artifacts.find(artifact => artifact.name === "prodDebugAPK");
|
||||||
|
|
||||||
|
if (!betaArtifact || !prodArtifact) {
|
||||||
|
console.log('Could not find both Beta and Prod APK artifacts.');
|
||||||
|
console.log('Available artifacts:', artifacts.map(a => a.name).join(', '));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const betaDownloadUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/suites/${runId}/artifacts/${betaArtifact.id}`;
|
||||||
|
const prodDownloadUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/suites/${runId}/artifacts/${prodArtifact.id}`;
|
||||||
|
|
||||||
|
const commentBody = `
|
||||||
|
📱 **APK for pull request is ready to see the changes** 📱
|
||||||
|
- [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
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log('Successfully posted comment with APK download links');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error in PR comment creation:', error);
|
||||||
|
core.setFailed(`Workflow failed: ${error.message}`);
|
||||||
|
}
|
||||||
67
.github/workflows/android.yml
vendored
67
.github/workflows/android.yml
vendored
|
|
@ -3,7 +3,6 @@ name: Android CI
|
||||||
on: [push, pull_request, workflow_dispatch]
|
on: [push, pull_request, workflow_dispatch]
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
pull-requests: write
|
|
||||||
contents: read
|
contents: read
|
||||||
actions: read
|
actions: read
|
||||||
|
|
||||||
|
|
@ -108,63 +107,13 @@ jobs:
|
||||||
name: prodDebugAPK
|
name: prodDebugAPK
|
||||||
path: app/build/outputs/apk/prod/debug/app-*.apk
|
path: app/build/outputs/apk/prod/debug/app-*.apk
|
||||||
|
|
||||||
- name: Comment on PR with APK download links
|
- name: Store Workflow Run ID
|
||||||
if: github.event_name == 'pull_request'
|
if: github.event_name == 'pull_request'
|
||||||
uses: actions/github-script@v6
|
run: echo "${{ github.run_id }}" > run_id.txt
|
||||||
|
|
||||||
|
- name: Upload Run ID as Artifact
|
||||||
|
if: github.event_name == 'pull_request'
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
github-token: ${{secrets.GITHUB_TOKEN}}
|
name: run-id
|
||||||
script: |
|
path: run_id.txt
|
||||||
try {
|
|
||||||
const token = process.env.GITHUB_TOKEN;
|
|
||||||
if (!token) {
|
|
||||||
throw new Error('GITHUB_TOKEN is not set. Please check workflow permissions.');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const { data: { artifacts } } = await github.rest.actions.listWorkflowRunArtifacts({
|
|
||||||
owner: context.repo.owner,
|
|
||||||
repo: context.repo.repo,
|
|
||||||
run_id: context.runId
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!artifacts || artifacts.length === 0) {
|
|
||||||
console.log('No artifacts found for this workflow run.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const betaArtifact = artifacts.find(artifact => artifact.name === "betaDebugAPK");
|
|
||||||
const prodArtifact = artifacts.find(artifact => artifact.name === "prodDebugAPK");
|
|
||||||
|
|
||||||
if (!betaArtifact || !prodArtifact) {
|
|
||||||
console.log('Could not find both Beta and Prod APK artifacts.');
|
|
||||||
console.log('Available artifacts:', artifacts.map(a => a.name).join(', '));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 to see the changes** 📱
|
|
||||||
- [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
|
|
||||||
});
|
|
||||||
|
|
||||||
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}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue