Skip to content

Commit 3754dde

Browse files
committed
fix svc event handling
1 parent 365bb6c commit 3754dde

2 files changed

Lines changed: 55 additions & 8 deletions

File tree

.github/workflows/service__event_dispatcher__pull_request__closed__main.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@ jobs:
99
runs-on: ubuntu-latest
1010
steps:
1111
- name: Emit metadata
12-
run: echo "Running for PR ${{ github.event.number }} state=${{ github.event.action }}"
12+
run: |
13+
echo "Running for PR ${{ github.event.number }}"
14+
echo "State: ${{ github.event.pull_request.state }}"
15+
echo "Base ref: ${{ github.event.pull_request.base.ref }}"
16+
echo "Merged: ${{ github.event.pull_request.merged }}"

.github/workflows/update-nuspec.yml

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,63 @@ concurrency:
1313
jobs:
1414
validate:
1515
runs-on: ubuntu-latest
16-
if: >
17-
github.event.workflow_run.event == 'pull_request' &&
18-
github.event.workflow_run.conclusion == 'success' &&
19-
fromJson(github.event.workflow_run.payload).pull_request.state == 'closed' &&
20-
fromJson(github.event.workflow_run.payload).pull_request.base.ref == 'main'
21-
env:
22-
PULL_REQUEST_MERGED: ${{ github.event.pull_request.merged }}
16+
if: github.event.workflow_run.conclusion == 'success'
2317
outputs:
2418
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 }}
2521
steps:
2622
- uses: actions/checkout@v4
2723

24+
- name: Initialize
25+
id: initialize
26+
env:
27+
GH_TOKEN: ${{ secrets.PAT }}
28+
WORKFLOW_EVENT: ${{ github.event.workflow_run.event }}
29+
run: |
30+
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
31+
echo "[skip] workflow_dispatch"
32+
exit 0
33+
fi
34+
35+
if [ "$WORKFLOW_EVENT" != "pull_request" ]; then
36+
echo "[skip] Not a pull_request event"
37+
echo "pull_request_merged=false" >> $GITHUB_OUTPUT
38+
echo "pull_request_head_ref=" >> $GITHUB_OUTPUT
39+
exit 0
40+
fi
41+
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"
45+
echo "pull_request_merged=false" >> $GITHUB_OUTPUT
46+
echo "pull_request_head_ref=" >> $GITHUB_OUTPUT
47+
exit 0
48+
fi
49+
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')
54+
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+
62+
PR_HEAD_REF=$(echo "$PR_JSON" | jq -r '.headRefName')
63+
PR_BASE=$(echo "$PR_JSON" | jq -r '.baseRefName')
64+
65+
echo "pull_request_merged=$PR_MERGED" >> $GITHUB_OUTPUT
66+
echo "pull_request_head_ref=$PR_HEAD_REF" >> $GITHUB_OUTPUT
67+
2868
- name: Validate
2969
id: validate
70+
env:
71+
PULL_REQUEST_MERGED: ${{ steps.initialize.outputs.pull_request_merged }}
72+
GITHUB_HEAD_REF: ${{ steps.initialize.outputs.pull_request_head_ref }}
3073
run: |
3174
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
3275
echo "result=true" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)