Skip to content

Commit 246bbbf

Browse files
authored
Migrate to Checks API for Integration Tests (#4268)
## Summary Migrate from GitHub Statuses API to Checks API for integration test reporting. **Why:** The current setup uses a Personal Access Token (PAT) with the Statuses API, which requires monthly token rotation. By switching to the Checks API with GitHub App authentication, we eliminate this maintenance burden. **Changes:** - Generate a second GitHub App token (`DECO_TEST_APPROVAL_APP`) for creating check runs - Create an "Integration Tests" check before triggering the workflow - Pass `check_run_id` to eng-dev-ecosystem so it can update the check status - Update `get_status()` to query Checks API instead of Statuses API This aligns CLI with how the SDKs handle integration test status reporting. --------- Co-authored-by: Omer Lachish <rauchy@users.noreply.github.com>
1 parent 70f3953 commit 246bbbf

File tree

2 files changed

+80
-27
lines changed

2 files changed

+80
-27
lines changed

.github/workflows/start-integration-tests.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
name: start-integration-tests
22

33
on:
4-
#schedule:
5-
# - cron: '*/10 * * * *'
64
workflow_dispatch:
75

86
jobs:
@@ -22,7 +20,7 @@ jobs:
2220
if: "${{ !github.event.pull_request.head.repo.fork }}"
2321

2422
steps:
25-
- name: Generate GitHub App Token
23+
- name: Generate GitHub App Token for Workflow Trigger
2624
id: generate-token
2725
uses: actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e # v2.0.6
2826
with:
@@ -31,11 +29,20 @@ jobs:
3129
owner: ${{ secrets.ORG_NAME }}
3230
repositories: ${{secrets.REPO_NAME}}
3331

32+
- name: Generate GitHub App Token for Check Updates
33+
id: generate-check-token
34+
uses: actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e # v2.0.6
35+
with:
36+
app-id: ${{ secrets.DECO_TEST_APPROVAL_APP_ID }}
37+
private-key: ${{ secrets.DECO_TEST_APPROVAL_PRIVATE_KEY }}
38+
owner: databricks
39+
3440
- name: Fetch start_integration_tests.py
3541
run: wget https://raw.githubusercontent.com/databricks/cli/refs/heads/main/tools/start_integration_tests.py
3642

3743
- name: Run start_integration_tests.py
3844
env:
3945
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
46+
GH_CHECK_TOKEN: ${{ steps.generate-check-token.outputs.token }}
4047
run: |-
4148
python3 ./start_integration_tests.py -R ${{ secrets.ORG_NAME }}/${{secrets.REPO_NAME}} --yes

tools/start_integration_tests.py

Lines changed: 70 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88

99
import argparse
1010
import json
11+
import os
1112
import subprocess
1213
import sys
13-
from pathlib import Path
14-
import re
1514

1615

1716
CLI_REPO = "databricks/cli"
@@ -20,14 +19,17 @@
2019
ALLOWED_HEAD_OWNER = {"id": "MDEyOk9yZ2FuaXphdGlvbjQ5OTgwNTI=", "login": "databricks"}
2120

2221

23-
def run(cmd):
22+
def run(cmd, env=None):
2423
sys.stderr.write("+ " + " ".join(cmd) + "\n")
25-
return subprocess.run(cmd, check=True)
24+
return subprocess.run(cmd, check=True, env=env)
2625

2726

28-
def run_json(cmd):
27+
def run_json(cmd, env=None):
2928
sys.stderr.write("+ " + " ".join(cmd) + "\n")
30-
result = subprocess.run(cmd, stdout=subprocess.PIPE, encoding="utf-8", check=True)
29+
run_env = os.environ.copy()
30+
if env:
31+
run_env.update(env)
32+
result = subprocess.run(cmd, stdout=subprocess.PIPE, encoding="utf-8", check=True, env=run_env)
3133

3234
try:
3335
return json.loads(result.stdout)
@@ -36,6 +38,38 @@ def run_json(cmd):
3638
raise
3739

3840

41+
def create_check(commit_sha):
42+
"""Create a check run for the given commit and return the check_run_id."""
43+
check_token = os.environ.get("GH_CHECK_TOKEN")
44+
if not check_token:
45+
print("Warning: GH_CHECK_TOKEN not set, skipping check creation")
46+
return None
47+
48+
response = run_json(
49+
[
50+
"gh",
51+
"api",
52+
"-X",
53+
"POST",
54+
f"/repos/{CLI_REPO}/check-runs",
55+
"-f",
56+
"name=Integration Tests",
57+
"-f",
58+
f"head_sha={commit_sha}",
59+
"-f",
60+
"status=queued",
61+
"-f",
62+
"output[title]=Integration Tests",
63+
"-f",
64+
"output[summary]=Tests queued and will be triggered shortly...",
65+
],
66+
env={"GH_TOKEN": check_token},
67+
)
68+
check_run_id = response.get("id")
69+
print(f"Created check run: {check_run_id}")
70+
return check_run_id
71+
72+
3973
def get_approved_prs_by_non_team():
4074
prs = run_json(
4175
[
@@ -108,30 +142,42 @@ def start_job(pr_number, commit_sha, author, approved_by, workflow, repo, force=
108142
response = input("Start integration tests? (y/n): ")
109143

110144
if response.lower() == "y":
111-
result = run(
112-
[
113-
"gh",
114-
"workflow",
115-
"run",
116-
workflow,
117-
"-R",
118-
repo,
119-
"-F",
120-
f"pull_request_number={pr_number}",
121-
"-F",
122-
f"commit_sha={commit_sha}",
123-
],
124-
)
145+
check_run_id = create_check(commit_sha)
146+
147+
cmd = [
148+
"gh",
149+
"workflow",
150+
"run",
151+
workflow,
152+
"-R",
153+
repo,
154+
"--ref",
155+
"main",
156+
"-F",
157+
f"pull_request_number={pr_number}",
158+
"-F",
159+
f"commit_sha={commit_sha}",
160+
]
161+
if check_run_id:
162+
cmd.extend(["-F", f"check_run_id={check_run_id}"])
163+
164+
run(cmd)
125165
print(f"Started integration tests for PR #{pr_number}")
126166

127167

128168
def get_status(commit_sha):
129-
statuses = run_json(["gh", "api", f"repos/{CLI_REPO}/commits/{commit_sha}/statuses"])
169+
response = run_json(["gh", "api", f"repos/{CLI_REPO}/commits/{commit_sha}/check-runs"])
130170
result = []
131-
for st in statuses:
132-
if st["context"] != "Integration Tests Check":
171+
for check in response.get("check_runs", []):
172+
if check["name"] != "Integration Tests":
133173
continue
134-
result.append(f"{st['state']} {st['target_url']}")
174+
status = check["status"]
175+
conclusion = check.get("conclusion", "")
176+
details_url = check.get("details_url", "")
177+
if conclusion:
178+
result.append(f"{conclusion} {details_url}")
179+
else:
180+
result.append(f"{status} {details_url}")
135181
return result
136182

137183

0 commit comments

Comments
 (0)