Update android.yml

This commit is contained in:
Sujal 2025-02-19 23:14:28 +05:30 committed by GitHub
parent 4f6822ed97
commit 4707d0cbf8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -119,17 +119,15 @@ 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: |
try { try {
if (!process.env.GITHUB_TOKEN) { const token = process.env.GITHUB_TOKEN;
console.log('❌ GITHUB_TOKEN is not available. Please check repository secrets.'); if (!token) {
core.setFailed('GITHUB_TOKEN is missing.'); throw new Error('GITHUB_TOKEN is not set. Please check workflow permissions.');
return;
} else {
console.log(`✅ GITHUB_TOKEN is present: ****${process.env.GITHUB_TOKEN.slice(-4)}`);
} }
const { data: { artifacts } } = await github.rest.actions.listWorkflowRunArtifacts({ const { data: { artifacts } } = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
@ -137,33 +135,43 @@ jobs:
}); });
if (!artifacts || artifacts.length === 0) { if (!artifacts || artifacts.length === 0) {
throw new Error('No artifacts found for this workflow run.'); console.log('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) {
throw new Error('Could not find both Beta and Prod APK artifacts.'); 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}/actions/runs/${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}/actions/runs/${context.runId}/artifacts/${prodArtifact.id}`; const prodDownloadUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/suites/${context.runId}/artifacts/${prodArtifact.id}`;
await github.rest.issues.createComment({ const commentBody = `
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `
📱 **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})
`;
*Note: You need to be logged in to GitHub to download the APKs.* await github.rest.issues.createComment({
` issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
}); });
console.log('✅ Successfully created comment with APK links');
console.log('Successfully posted comment with APK download links');
} catch (error) { } catch (error) {
console.error('❌ Error details:', 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}`);
}
} }