diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 51c23c8ee..9125d4106 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -5,7 +5,6 @@ on: [push, pull_request, workflow_dispatch] permissions: pull-requests: write contents: read - issues: write concurrency: group: build-${{ github.event.pull_request.number || github.ref }} @@ -112,23 +111,38 @@ jobs: if: github.event_name == 'pull_request' uses: actions/github-script@v6 with: - github-token: ${{ secrets.GITHUB_TOKEN }} + 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 - }); + try { + if (!process.env.GITHUB_TOKEN) { + throw new Error('GITHUB_TOKEN is not set. Please configure repository secrets.'); + } - const betaArtifact = artifacts.find(artifact => artifact.name === "betaDebugAPK"); - const prodArtifact = artifacts.find(artifact => artifact.name === "prodDebugAPK"); + 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) { + 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 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** 📱 + 📱 **APK for pull request is ready to see the changes** 📱 - [Download Beta APK](${betaDownloadUrl}) - [Download Prod APK](${prodDownloadUrl}) `; @@ -139,4 +153,15 @@ jobs: repo: context.repo.repo, 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}`); + } }