From 5a12ca5500166a29b106c7d7e3658994a1151925 Mon Sep 17 00:00:00 2001 From: Sujal Date: Wed, 19 Feb 2025 18:49:12 +0530 Subject: [PATCH] Update android.yml --- .github/workflows/android.yml | 63 +++++++++++++---------------------- 1 file changed, 24 insertions(+), 39 deletions(-) diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index bcbef52fd..0488beed8 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -2,10 +2,12 @@ name: Android CI on: [push, pull_request, workflow_dispatch] -permissions: - pull-requests: write +permissions: contents: read + pull-requests: write + issues: write actions: read + checks: write concurrency: group: build-${{ github.event.pull_request.number || github.ref }} @@ -111,60 +113,43 @@ jobs: - name: Comment on PR with APK download links if: github.event_name == 'pull_request' uses: actions/github-script@v6 + env: + GH_TOKEN: ${{ github.token }} with: - github-token: ${{secrets.GITHUB_TOKEN}} + github-token: ${{ github.token }} script: | 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 + const octokit = github.getOctokit(process.env.GH_TOKEN); + + const { data: { artifacts } } = await octokit.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; + throw new Error('No artifacts found for this workflow run.'); } 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; + throw new Error('Could not find both Beta and Prod APK artifacts.'); } 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({ + + await octokit.rest.issues.createComment({ + ...context.repo, issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: commentBody + body: ` + 📱 **APK for pull request is ready to see the changes** 📱 + - [Download Beta APK](${betaDownloadUrl}) + - [Download Prod APK](${prodDownloadUrl}) + ` }); - - 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}`); - } + core.setFailed(`Action failed: ${error.message}`); }