|
1 | 1 | name: Android CI Comment
|
2 | 2 |
|
3 |
| -on: [pull_request_target] |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: ["Android CI"] |
| 6 | + types: [completed] |
| 7 | + branches: [main] |
4 | 8 |
|
5 | 9 | permissions:
|
6 | 10 | issues: write
|
|
9 | 13 | comment:
|
10 | 14 | name: Comment on PR with APK links
|
11 | 15 | runs-on: ubuntu-latest
|
| 16 | + if: github.event.workflow_run.conclusion == 'success' |
12 | 17 | steps:
|
13 | 18 | - name: Checkout base branch
|
14 | 19 | uses: actions/checkout@v3
|
15 | 20 | with:
|
16 |
| - ref: ${{ github.base_ref }} |
17 |
| - |
| 21 | + ref: ${{ github.event.workflow_run.head_branch }} |
18 | 22 | - name: Download Run ID Artifact
|
19 | 23 | uses: actions/download-artifact@v4
|
20 | 24 | with:
|
21 | 25 | name: run-id
|
| 26 | + run-id: ${{ github.event.workflow_run.id }} |
22 | 27 |
|
23 | 28 | - name: Read Run ID
|
24 | 29 | id: read-run-id
|
25 | 30 | run: echo "RUN_ID=$(cat run_id.txt)" >> $GITHUB_ENV
|
26 | 31 |
|
27 | 32 | - name: Comment on PR with APK download links
|
28 | 33 | env:
|
29 |
| - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 34 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
30 | 35 | uses: actions/github-script@v6
|
31 | 36 | with:
|
32 | 37 | script: |
|
|
41 | 46 | throw new Error('Run ID not found.');
|
42 | 47 | }
|
43 | 48 |
|
| 49 | + // Get the PR number from the workflow_run event |
| 50 | + const prNumber = ${{ github.event.workflow_run.pull_requests[0].number }}; |
| 51 | + if (!prNumber) { |
| 52 | + console.log('No PR number found in workflow_run event.'); |
| 53 | + return; |
| 54 | + } |
| 55 | +
|
44 | 56 | const { data: { artifacts } } = await github.rest.actions.listWorkflowRunArtifacts({
|
45 | 57 | owner: context.repo.owner,
|
46 | 58 | repo: context.repo.repo,
|
|
71 | 83 | `;
|
72 | 84 |
|
73 | 85 | await github.rest.issues.createComment({
|
74 |
| - issue_number: context.issue.number, |
| 86 | + issue_number: prNumber, |
75 | 87 | owner: context.repo.owner,
|
76 | 88 | repo: context.repo.repo,
|
77 | 89 | body: commentBody
|
|
0 commit comments