Update android.yml

This commit is contained in:
Sujal 2025-02-19 18:49:12 +05:30 committed by GitHub
parent 8d0da86569
commit 5a12ca5500
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2,10 +2,12 @@ name: Android CI
on: [push, pull_request, workflow_dispatch] on: [push, pull_request, workflow_dispatch]
permissions: permissions:
pull-requests: write
contents: read contents: read
pull-requests: write
issues: write
actions: read actions: read
checks: write
concurrency: concurrency:
group: build-${{ github.event.pull_request.number || github.ref }} group: build-${{ github.event.pull_request.number || github.ref }}
@ -111,60 +113,43 @@ jobs:
- name: Comment on PR with APK download links - name: Comment on PR with APK download links
if: github.event_name == 'pull_request' if: github.event_name == 'pull_request'
uses: actions/github-script@v6 uses: actions/github-script@v6
env:
GH_TOKEN: ${{ github.token }}
with: with:
github-token: ${{secrets.GITHUB_TOKEN}} github-token: ${{ github.token }}
script: | script: |
try { try {
const token = process.env.GITHUB_TOKEN; const octokit = github.getOctokit(process.env.GH_TOKEN);
if (!token) {
throw new Error('GITHUB_TOKEN is not set. Please check workflow permissions.'); const { data: { artifacts } } = await octokit.rest.actions.listWorkflowRunArtifacts({
} owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.runId
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) { if (!artifacts || artifacts.length === 0) {
console.log('No artifacts found for this workflow run.'); throw new Error('No artifacts found for this workflow run.');
return;
} }
const betaArtifact = artifacts.find(artifact => artifact.name === "betaDebugAPK"); const betaArtifact = artifacts.find(artifact => artifact.name === "betaDebugAPK");
const prodArtifact = artifacts.find(artifact => artifact.name === "prodDebugAPK"); const prodArtifact = artifacts.find(artifact => artifact.name === "prodDebugAPK");
if (!betaArtifact || !prodArtifact) { if (!betaArtifact || !prodArtifact) {
console.log('Could not find both Beta and Prod APK artifacts.'); throw new Error('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 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 prodDownloadUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/suites/${context.runId}/artifacts/${prodArtifact.id}`;
const commentBody = ` await octokit.rest.issues.createComment({
📱 **APK for pull request is ready to see the changes** 📱 ...context.repo,
- [Download Beta APK](${betaDownloadUrl})
- [Download Prod APK](${prodDownloadUrl})
`;
await github.rest.issues.createComment({
issue_number: context.issue.number, issue_number: context.issue.number,
owner: context.repo.owner, body: `
repo: context.repo.repo, 📱 **APK for pull request is ready to see the changes** 📱
body: commentBody - [Download Beta APK](${betaDownloadUrl})
- [Download Prod APK](${prodDownloadUrl})
`
}); });
console.log('Successfully posted comment with APK download links');
} catch (error) { } catch (error) {
console.error('Error in PR comment creation:', error); core.setFailed(`Action failed: ${error.message}`);
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}`);
}
} }