Skip to content

Commit 5526709

Browse files
committed
fix workflow event handling
1 parent 3754dde commit 5526709

1 file changed

Lines changed: 9 additions & 18 deletions

File tree

.github/workflows/update-nuspec.yml

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ jobs:
1616
if: github.event.workflow_run.conclusion == 'success'
1717
outputs:
1818
result: ${{ steps.validate.outputs.result }}
19-
pull_request_merged: ${{ steps.initialize.outputs.pr_merged }}
20-
pull_request_head_ref: ${{ steps.initialize.outputs.pr_head_ref }}
2119
steps:
2220
- uses: actions/checkout@v4
2321

@@ -39,37 +37,30 @@ jobs:
3937
exit 0
4038
fi
4139
42-
PR_NUMBER=$(echo '${{ toJson(github.event.workflow_run.pull_requests) }}' | jq -r '.[0].number // empty')
43-
if [ -z "$PR_NUMBER" ]; then
44-
echo "[skip] No PR number found"
40+
PR_JSON=$(gh pr list --repo ${{ github.repository }} --state all --json number,mergeCommit,headRefName,baseRefName,state --search "$HEAD_SHA" --limit 1)
41+
if [ "$(echo "$PR_JSON" | jq '. | length')" -eq 0 ]; then
42+
echo "[skip] No PR found for commit $HEAD_SHA"
4543
echo "pull_request_merged=false" >> $GITHUB_OUTPUT
4644
echo "pull_request_head_ref=" >> $GITHUB_OUTPUT
4745
exit 0
4846
fi
4947
50-
# Fetch PR details
51-
PR_JSON=$(gh pr view "$PR_NUMBER" --repo ${{ github.repository }} --json merged,headRefName,baseRefName,state)
52-
53-
PR_MERGED=$(echo "$PR_JSON" | jq -r '.merged')
48+
PR_JSON=$(gh pr view "$PR_NUMBER" --repo ${{ github.repository }} --json headRefName,baseRefName,state)
5449
PR_STATE=$(echo "$PR_JSON" | jq -r '.state')
55-
56-
# Validate PR is closed and targeting main
57-
if [ "$PR_STATE" != "CLOSED" ] || [ "$PR_BASE" != "main" ]; then
58-
echo "[skip] PR not valid: state=$PR_STATE base=$PR_BASE"
59-
exit 0
60-
fi
61-
50+
PR_BASE_REF_NAME=$(echo "$PR_JSON" | jq -r '.baseRefName')
6251
PR_HEAD_REF=$(echo "$PR_JSON" | jq -r '.headRefName')
63-
PR_BASE=$(echo "$PR_JSON" | jq -r '.baseRefName')
64-
52+
PR_MERGED="$([[ "$PR_STATE" == "MERGED" ]] && echo true || echo false)"
53+
6554
echo "pull_request_merged=$PR_MERGED" >> $GITHUB_OUTPUT
6655
echo "pull_request_head_ref=$PR_HEAD_REF" >> $GITHUB_OUTPUT
56+
echo "pull_request_base_ref_name=$PR_BASE_REF_NAME" >> $GITHUB_OUTPUT
6757
6858
- name: Validate
6959
id: validate
7060
env:
7161
PULL_REQUEST_MERGED: ${{ steps.initialize.outputs.pull_request_merged }}
7262
GITHUB_HEAD_REF: ${{ steps.initialize.outputs.pull_request_head_ref }}
63+
GITHUB_BASE_REF: ${{ steps.initialize.outputs.pull_request_base_ref_name }}
7364
run: |
7465
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
7566
echo "result=true" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)