Update android.yml

This commit is contained in:
Sujal 2025-02-19 17:45:27 +05:30 committed by GitHub
parent 9f5fcca20d
commit b2302020e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -5,7 +5,6 @@ on: [push, pull_request, workflow_dispatch]
permissions: permissions:
pull-requests: write pull-requests: write
contents: read contents: read
issues: write
concurrency: concurrency:
group: build-${{ github.event.pull_request.number || github.ref }} group: build-${{ github.event.pull_request.number || github.ref }}
@ -112,23 +111,38 @@ jobs:
if: github.event_name == 'pull_request' if: github.event_name == 'pull_request'
uses: actions/github-script@v6 uses: actions/github-script@v6
with: with:
github-token: ${{ secrets.GITHUB_TOKEN }} github-token: ${{secrets.GITHUB_TOKEN}}
script: | script: |
const { data: { artifacts } } = await github.rest.actions.listWorkflowRunArtifacts({ try {
owner: context.repo.owner, if (!process.env.GITHUB_TOKEN) {
repo: context.repo.repo, throw new Error('GITHUB_TOKEN is not set. Please configure repository secrets.');
run_id: context.runId }
});
const betaArtifact = artifacts.find(artifact => artifact.name === "betaDebugAPK"); const { data: { artifacts } } = await github.rest.actions.listWorkflowRunArtifacts({
const prodArtifact = artifacts.find(artifact => artifact.name === "prodDebugAPK"); 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;
}
if (betaArtifact && prodArtifact) {
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 = ` 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})
`; `;
@ -139,4 +153,15 @@ jobs:
repo: context.repo.repo, repo: context.repo.repo,
body: commentBody 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}`);
}
} }