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
|
name: PR review labeler
|
||||||
on:
|
on:
|
||||||
workflow_run:
|
workflow_run:
|
||||||
workflows: ["PR review listener"] # must match the other workflow's name
|
workflows: ["PR review listener"]
|
||||||
types: [completed]
|
types: [completed]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
@@ -14,30 +14,18 @@ jobs:
|
|||||||
pull-requests: write
|
pull-requests: write
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Resolve PR number from head_sha
|
- name: Download PR number artifact from upstream run
|
||||||
id: pr
|
uses: actions/download-artifact@v4
|
||||||
uses: actions/github-script@v7
|
|
||||||
with:
|
with:
|
||||||
script: |
|
name: pr-number-${{ github.event.workflow_run.id }} # same unique name
|
||||||
const { owner, repo } = context.repo;
|
path: .
|
||||||
const sha = context.payload.workflow_run.head_sha;
|
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({
|
- id: pr
|
||||||
owner, repo, commit_sha: sha
|
run: echo "number=$(cat pr.txt)" >> $GITHUB_OUTPUT
|
||||||
});
|
|
||||||
|
|
||||||
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));
|
|
||||||
|
|
||||||
- name: Label when approved
|
- name: Label when approved
|
||||||
if: ${{ success() }}
|
|
||||||
uses: j-fulbright/label-when-approved-action@v1.2
|
uses: j-fulbright/label-when-approved-action@v1.2
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
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:
|
jobs:
|
||||||
ping:
|
ping:
|
||||||
if: ${{ github.event.review.state == 'approved' }}
|
if: ${{ github.event.review.state == 'approved' }}
|
||||||
name: "Listen"
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
steps:
|
||||||
- run:
|
- name: Save PR number
|
||||||
echo "Approved review detected for PR ${{ github.event.pull_request.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