Automatically Link APKs in PR Discussion After Building

This commit is contained in:
Sujal 2025-02-16 18:54:00 +05:30 committed by GitHub
parent 34943542bf
commit bd61e2ec05
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -102,3 +102,36 @@ 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
- name: Comment on PR with APK download links
if: github.event_name == 'pull_request'
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 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
});
}