Skip to content

Instantly share code, notes, and snippets.

@sagudev
Created July 5, 2025 08:21
Show Gist options
  • Select an option

  • Save sagudev/953e41fd0acab8274963ed113a56dbda to your computer and use it in GitHub Desktop.

Select an option

Save sagudev/953e41fd0acab8274963ed113a56dbda to your computer and use it in GitHub Desktop.
servo bisect
git bisect start
git bisect bad <bad-commit>
git bisect good <good-commit>
git bisect run ../bisect.py
#!/usr/bin/env python3
import subprocess
import os
import shutil
import tarfile
import json
import sys
ARTIFACT_NAME = "linux-release"
RUN_DIR = "artifact-run"
ARGS = ["https://curran.github.io/HTML5Examples/canvas/smileyFace.html"]
def run_cmd(cmd, cwd=None):
result = subprocess.run(cmd, shell=True, capture_output=True, text=True, cwd=cwd)
return result.stdout.strip(), result.returncode
def get_commit_sha():
out, _ = run_cmd("git rev-parse HEAD")
return out
def find_run_for_commit(commit_sha):
print(f"πŸ” Searching for CI run for commit: {commit_sha}")
cmd = f'gh run list --workflow Main -c {commit_sha} -e push --json databaseId'
output, code = run_cmd(cmd)
if code != 0:
print("❌ Failed to fetch run list")
return None
runs = json.loads(output)
for run in runs:
return run['databaseId']
return None
def download_artifact(run_id):
print(f"⬇️ Downloading artifact from run ID: {run_id}")
shutil.rmtree(RUN_DIR, ignore_errors=True)
os.makedirs(RUN_DIR, exist_ok=True)
cmd = f'gh run download {run_id} -n "{ARTIFACT_NAME}" -D {RUN_DIR}'
_, code = run_cmd(cmd)
return code == 0
def extract_zip():
for fname in os.listdir(RUN_DIR):
if fname.endswith(".tar.gz"):
zip_path = os.path.join(RUN_DIR, fname)
with tarfile.open(zip_path) as zip_ref:
zip_ref.extractall(RUN_DIR)
print(f"βœ… Extracted: {zip_path}")
return True
print("❌ No zip file found in artifact")
return False
def run_servo():
# Look for the servo binary
for root, _, files in os.walk(RUN_DIR):
if "servo" in files:
servo_path = os.path.join(root, "servo")
print(f"πŸš€ Running: {servo_path} {ARGS}")
os.chmod(servo_path, 0o755)
subprocess.run([servo_path, *ARGS])
return True
print("❌ 'servo' binary not found in artifact")
return False
def main():
commit = get_commit_sha()
print(f"\n==== Checking Commit: {commit} ====\n")
run_id = find_run_for_commit(commit)
if not run_id:
print("⚠️ No successful CI run for this commit.")
sys.exit(125)
if not download_artifact(run_id):
print("⚠️ Failed to download artifact.")
sys.exit(125)
if not extract_zip():
sys.exit(125)
if not run_servo():
sys.exit(125)
# Ask user for input
print("\nβœ… Manual Evaluation:")
print(" [g] good")
print(" [b] bad")
print(" [s] skip")
choice = input("Your choice: ").strip().lower()
if choice == "g":
sys.exit(0)
elif choice == "b":
sys.exit(1)
else:
sys.exit(125)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment