Skip to content

Instantly share code, notes, and snippets.

@a-b
Last active March 27, 2025 17:45
Show Gist options
  • Save a-b/ca46beeb834cc68ffb38e120136a239d to your computer and use it in GitHub Desktop.
Save a-b/ca46beeb834cc68ffb38e120136a239d to your computer and use it in GitHub Desktop.
flaky cf cli jobs with multiple attempts

Jobs with Multiple Attempts

Job Name: get-sha

Job Name: Basic units to gate for integration tests

Job Name: Claim and Prep Environment

Job Name: Integration tests / run-integration-tests

Job Name: client creds / run-integration-tests

Job Name: Analyze

Job Name: lint

Job Name: Run go fmt

Job Name: Unit Tests (ubuntu-latest)

Job Name: Unit Tests (ubuntu-20.04)

Job Name: Unit Tests (macos-latest)

Job Name: Unit Tests (macos-13)

Job Name: Unit Tests (windows-latest)

Job Name: Unit Tests (windows-2019)

Job Name: check-cves

Job Name: CATS / run-integration-tests

Job Name: Unclaim environment

#!/usr/bin/env python3
import subprocess
import requests
token = subprocess.check_output(["gh", "auth", "token"]).strip().decode('utf-8')
owner = "cloudfoundry"
repo = "cli"
headers = {"Authorization": f"token {token}"}
runs_url = f"https://api.github.com/repos/{owner}/{repo}/actions/runs"
response = requests.get(runs_url, headers=headers)
workflow_runs = response.json()
jobs_data = {}
for run in workflow_runs.get('workflow_runs', []):
run_id = run['id']
jobs_url = f"https://api.github.com/repos/{owner}/{repo}/actions/runs/{run_id}/jobs"
jobs_response = requests.get(jobs_url, headers=headers)
for job in jobs_response.json().get('jobs', []):
job_name = job['name']
attempt = job['run_attempt']
job_url = job['html_url']
if job_name not in jobs_data:
jobs_data[job_name] = []
jobs_data[job_name].append((attempt, job_url))
if any(len(attempts) > 1 for attempts in jobs_data.values()):
print("# Jobs with Multiple Attempts\n")
for job_name, attempts in jobs_data.items():
if len(attempts) > 1:
print(f"### Job Name: {job_name}")
for attempt, job_url in attempts:
print(f"- Attempt: **{attempt}** - [{job_url}]({job_url})")
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment