Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /SHAdd0WTAka_Zen-Ai-Pentest /.kimi /trigger_workflow.py
| #!/usr/bin/env python3 | |
| """Trigger a GitHub Actions workflow manually""" | |
| import os | |
| import sys | |
| sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
| import requests | |
| from github_app_auth import ( | |
| REPO_NAME, | |
| REPO_OWNER, | |
| get_headers, | |
| get_installation_token, | |
| ) | |
| def trigger_workflow(workflow_id, branch="main"): | |
| """Trigger a workflow dispatch event""" | |
| token = get_installation_token() | |
| headers = get_headers(token) | |
| headers["Accept"] = "application/vnd.github.v3+json" | |
| url = f"https://api.github.com/repos/{REPO_OWNER}/{REPO_NAME}/actions/workflows/{workflow_id}/dispatches" | |
| data = {"ref": branch} | |
| response = requests.post(url, headers=headers, json=data, timeout=30) | |
| if response.status_code == 204: | |
| print( | |
| f"[OK] Workflow '{workflow_id}' triggered successfully on branch '{branch}'" | |
| ) | |
| print( | |
| f" Check status at: https://github.com/{REPO_OWNER}/{REPO_NAME}/actions" | |
| ) | |
| return True | |
| else: | |
| print(f"[FAIL] Failed to trigger workflow: {response.status_code}") | |
| print(response.text) | |
| return False | |
| def list_workflows(): | |
| """List available workflows""" | |
| token = get_installation_token() | |
| headers = get_headers(token) | |
| headers["Accept"] = "application/vnd.github.v3+json" | |
| url = f"https://api.github.com/repos/{REPO_OWNER}/{REPO_NAME}/actions/workflows" | |
| response = requests.get(url, headers=headers, timeout=30) | |
| if response.status_code == 200: | |
| workflows = response.json().get("workflows", []) | |
| print(f"\nAvailable workflows ({len(workflows)}):") | |
| print("-" * 60) | |
| for wf in workflows: | |
| state = "✓" if wf.get("state") == "active" else "✗" | |
| print(f"{state} {wf.get('name')}") | |
| print(f" ID: {wf.get('id')}") | |
| print( | |
| f" File: {wf.get('path', '').replace('.github/workflows/', '')}" | |
| ) | |
| print() | |
| else: | |
| print(f"Failed to list workflows: {response.status_code}") | |
| if __name__ == "__main__": | |
| import argparse | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("workflow", nargs="?", help="Workflow ID or filename") | |
| parser.add_argument("--branch", default="main", help="Branch to run on") | |
| parser.add_argument("--list", action="store_true", help="List workflows") | |
| args = parser.parse_args() | |
| if args.list: | |
| list_workflows() | |
| elif args.workflow: | |
| trigger_workflow(args.workflow, args.branch) | |
| else: | |
| # Default: trigger coverage workflow | |
| trigger_workflow("coverage.yml", "main") | |
Xet Storage Details
- Size:
- 2.65 kB
- Xet hash:
- cf00f0995a6c2f5e31c4cfd33f4914d38aec6bda6c21fc6e16a88dd67cdf6103
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.