Skip to content

Commit 1d399ec

Browse files
committed
fix: workflow dispatch with pr
1 parent cf697c6 commit 1d399ec

File tree

2 files changed

+80
-22
lines changed

2 files changed

+80
-22
lines changed

.github/workflows/agentkit-build.yaml

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
11
name: agentkit-build
22

33
on:
4-
pull_request:
5-
types:
6-
- closed
74
workflow_dispatch:
85
inputs:
9-
base_sha:
10-
description: "Base commit SHA (optional)"
11-
required: false
12-
head_sha:
13-
description: "Head commit SHA (optional)"
14-
required: false
6+
pr_number:
7+
description: "Pull request number"
8+
required: true
159

1610
jobs:
1711
agentkit-build:
18-
if: >
19-
${{ (github.event_name == 'pull_request' && github.event.pull_request.merged == true) || github.event_name == 'workflow_dispatch' }}
2012
runs-on: ubuntu-latest
2113

2214
env:
@@ -28,6 +20,41 @@ jobs:
2820
with:
2921
fetch-depth: 0
3022

23+
- name: Resolve BASE/HEAD from PR number
24+
if: github.event.inputs.pr_number != ''
25+
env:
26+
PR_NUMBER: ${{ github.event.inputs.pr_number }}
27+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28+
run: |
29+
python - << 'PY'
30+
import json
31+
import os
32+
import urllib.request
33+
34+
repo = os.environ["GITHUB_REPOSITORY"]
35+
pr_number = os.environ["PR_NUMBER"]
36+
token = os.environ["GITHUB_TOKEN"]
37+
38+
url = f"https://api.github.com/repos/{repo}/pulls/{pr_number}"
39+
req = urllib.request.Request(
40+
url,
41+
headers={
42+
"Authorization": f"Bearer {token}",
43+
"Accept": "application/vnd.github+json",
44+
},
45+
)
46+
with urllib.request.urlopen(req) as resp:
47+
data = json.load(resp)
48+
49+
base_sha = data["base"]["sha"]
50+
head_sha = data["head"]["sha"]
51+
52+
github_env = os.environ["GITHUB_ENV"]
53+
with open(github_env, "a", encoding="utf-8") as f:
54+
f.write(f"BASE_SHA={base_sha}\n")
55+
f.write(f"HEAD_SHA={head_sha}\n")
56+
PY
57+
3158
- name: Set up Python
3259
uses: actions/setup-python@v5
3360
with:
@@ -45,8 +72,8 @@ jobs:
4572
4673
- name: Run main.py in changed use-case directories (build)
4774
env:
48-
BASE_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.inputs.base_sha }}
49-
HEAD_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.event.inputs.head_sha }}
75+
BASE_SHA: ${{ env.BASE_SHA }}
76+
HEAD_SHA: ${{ env.HEAD_SHA }}
5077
AGENTKIT_COMMAND: build
5178
run: |
5279
python -m workflow_utils.check_usecases

.github/workflows/agentkit-check.yaml

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
name: agentkit-check
22

33
on:
4-
pull_request:
54
workflow_dispatch:
65
inputs:
7-
base_sha:
8-
description: "Base commit SHA (optional)"
9-
required: false
10-
head_sha:
11-
description: "Head commit SHA (optional)"
12-
required: false
6+
pr_number:
7+
description: "Pull request number"
8+
required: true
139

1410
jobs:
1511
agentkit-launch:
@@ -39,9 +35,44 @@ jobs:
3935
cat > .env << 'EOF'
4036
EOF
4137
38+
- name: Resolve BASE/HEAD from PR number
39+
if: github.event.inputs.pr_number != ''
40+
env:
41+
PR_NUMBER: ${{ github.event.inputs.pr_number }}
42+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43+
run: |
44+
python - << 'PY'
45+
import json
46+
import os
47+
import urllib.request
48+
49+
repo = os.environ["GITHUB_REPOSITORY"]
50+
pr_number = os.environ["PR_NUMBER"]
51+
token = os.environ["GITHUB_TOKEN"]
52+
53+
url = f"https://api.github.com/repos/{repo}/pulls/{pr_number}"
54+
req = urllib.request.Request(
55+
url,
56+
headers={
57+
"Authorization": f"Bearer {token}",
58+
"Accept": "application/vnd.github+json",
59+
},
60+
)
61+
with urllib.request.urlopen(req) as resp:
62+
data = json.load(resp)
63+
64+
base_sha = data["base"]["sha"]
65+
head_sha = data["head"]["sha"]
66+
67+
github_env = os.environ["GITHUB_ENV"]
68+
with open(github_env, "a", encoding="utf-8") as f:
69+
f.write(f"BASE_SHA={base_sha}\n")
70+
f.write(f"HEAD_SHA={head_sha}\n")
71+
PY
72+
4273
- name: Run main.py in changed use-case directories
4374
env:
44-
BASE_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.inputs.base_sha }}
45-
HEAD_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.event.inputs.head_sha }}
75+
BASE_SHA: ${{ env.BASE_SHA }}
76+
HEAD_SHA: ${{ env.HEAD_SHA }}
4677
run: |
4778
python -m workflow_utils.check_usecases

0 commit comments

Comments
 (0)