|
1 | 1 | name: agentkit-build |
2 | 2 |
|
3 | 3 | on: |
4 | | - pull_request: |
5 | | - types: |
6 | | - - closed |
7 | 4 | workflow_dispatch: |
8 | 5 | 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 |
15 | 9 |
|
16 | 10 | jobs: |
17 | 11 | agentkit-build: |
18 | | - if: > |
19 | | - ${{ (github.event_name == 'pull_request' && github.event.pull_request.merged == true) || github.event_name == 'workflow_dispatch' }} |
20 | 12 | runs-on: ubuntu-latest |
21 | 13 |
|
22 | 14 | env: |
|
28 | 20 | with: |
29 | 21 | fetch-depth: 0 |
30 | 22 |
|
| 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 | +
|
31 | 58 | - name: Set up Python |
32 | 59 | uses: actions/setup-python@v5 |
33 | 60 | with: |
|
45 | 72 |
|
46 | 73 | - name: Run main.py in changed use-case directories (build) |
47 | 74 | 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 }} |
50 | 77 | AGENTKIT_COMMAND: build |
51 | 78 | run: | |
52 | 79 | python -m workflow_utils.check_usecases |
0 commit comments