mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Update android.yml
This commit is contained in:
parent
8d0da86569
commit
5a12ca5500
1 changed files with 24 additions and 39 deletions
63
.github/workflows/android.yml
vendored
63
.github/workflows/android.yml
vendored
|
|
@ -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}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue