mirror of
https://github.com/armbian/build
synced 2025-09-24 19:47:06 +07:00
Reliable PR number relay for labeler workflow (#8628)
This commit is contained in:
30
.github/workflows/pr-label-on-approved.yml
vendored
30
.github/workflows/pr-label-on-approved.yml
vendored
@@ -1,7 +1,7 @@
|
||||
name: PR review labeler
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["PR review listener"] # must match the other workflow's name
|
||||
workflows: ["PR review listener"]
|
||||
types: [completed]
|
||||
|
||||
jobs:
|
||||
@@ -14,30 +14,18 @@ jobs:
|
||||
pull-requests: write
|
||||
|
||||
steps:
|
||||
- name: Resolve PR number from head_sha
|
||||
id: pr
|
||||
uses: actions/github-script@v7
|
||||
- name: Download PR number artifact from upstream run
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
script: |
|
||||
const { owner, repo } = context.repo;
|
||||
const sha = context.payload.workflow_run.head_sha;
|
||||
name: pr-number-${{ github.event.workflow_run.id }} # same unique name
|
||||
path: .
|
||||
run-id: ${{ github.event.workflow_run.id }} # ← CRITICAL: fetch from the upstream run
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
const { data: prs } = await github.rest.repos.listPullRequestsAssociatedWithCommit({
|
||||
owner, repo, commit_sha: sha
|
||||
});
|
||||
|
||||
if (!prs.length) {
|
||||
core.setFailed(`❌ No PR found for commit ${sha}`);
|
||||
return;
|
||||
}
|
||||
|
||||
// Pick an open PR if possible
|
||||
const pr = prs.find(p => p.state === 'open') || prs[0];
|
||||
core.info(`Using PR #${pr.number}`);
|
||||
core.setOutput('number', String(pr.number));
|
||||
- id: pr
|
||||
run: echo "number=$(cat pr.txt)" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Label when approved
|
||||
if: ${{ success() }}
|
||||
uses: j-fulbright/label-when-approved-action@v1.2
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
13
.github/workflows/pr-review-listener.yml
vendored
13
.github/workflows/pr-review-listener.yml
vendored
@@ -6,10 +6,15 @@ on:
|
||||
jobs:
|
||||
ping:
|
||||
if: ${{ github.event.review.state == 'approved' }}
|
||||
name: "Listen"
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- run:
|
||||
echo "Approved review detected for PR ${{ github.event.pull_request.number }}"
|
||||
- name: Save PR number
|
||||
run: echo "${{ github.event.pull_request.number }}" > pr.txt
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
# unique name: includes workflow run id
|
||||
name: pr-number-${{ github.run_id }}
|
||||
path: pr.txt
|
||||
|
||||
Reference in New Issue
Block a user