|
| 1 | +name: Retry Variant Creation |
| 2 | +on: |
| 3 | + schedule: |
| 4 | + # Run every 4 hours |
| 5 | + - cron: '0 */4 * * *' |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +jobs: |
| 9 | + retry-failed-variants: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + permissions: |
| 12 | + contents: write |
| 13 | + issues: write |
| 14 | + pull-requests: write |
| 15 | + steps: |
| 16 | + - name: Checkout repository |
| 17 | + uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Set up Python |
| 20 | + uses: actions/setup-python@v4 |
| 21 | + with: |
| 22 | + python-version: '3.11' |
| 23 | + |
| 24 | + - name: Install dependencies |
| 25 | + run: | |
| 26 | + pip install requests PyYAML |
| 27 | +
|
| 28 | + - name: Find and retry failed variant creations |
| 29 | + env: |
| 30 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 31 | + run: | |
| 32 | + python << 'EOF' |
| 33 | + import os |
| 34 | + import requests |
| 35 | + from datetime import datetime, timedelta |
| 36 | +
|
| 37 | + GITHUB_TOKEN = os.environ['GITHUB_TOKEN'] |
| 38 | + REPO = os.environ['GITHUB_REPOSITORY'] |
| 39 | + MAX_AGE_DAYS = 3 |
| 40 | +
|
| 41 | + def get_issues_needing_retry(): |
| 42 | + """Find open issues with variant-creation-needed label that are not too old""" |
| 43 | + url = f"https://api.github.com/repos/{REPO}/issues" |
| 44 | + headers = { |
| 45 | + 'Authorization': f'token {GITHUB_TOKEN}', |
| 46 | + 'Accept': 'application/vnd.github.v3+json' |
| 47 | + } |
| 48 | + params = { |
| 49 | + 'labels': 'variant-creation-needed', |
| 50 | + 'state': 'open', |
| 51 | + 'sort': 'created', |
| 52 | + 'direction': 'desc' |
| 53 | + } |
| 54 | + |
| 55 | + try: |
| 56 | + response = requests.get(url, headers=headers, params=params) |
| 57 | + response.raise_for_status() |
| 58 | + issues = response.json() |
| 59 | + |
| 60 | + # Filter issues that are not too old |
| 61 | + cutoff_date = datetime.now() - timedelta(days=MAX_AGE_DAYS) |
| 62 | + recent_issues = [] |
| 63 | + |
| 64 | + for issue in issues: |
| 65 | + created_at = datetime.fromisoformat(issue['created_at'].replace('Z', '+00:00')) |
| 66 | + if created_at > cutoff_date: |
| 67 | + recent_issues.append(issue) |
| 68 | + else: |
| 69 | + print(f"⏰ Issue #{issue['number']} is too old ({created_at}), skipping") |
| 70 | + |
| 71 | + return recent_issues |
| 72 | + except Exception as e: |
| 73 | + print(f"❌ Error getting issues: {e}") |
| 74 | + return [] |
| 75 | +
|
| 76 | + def trigger_variant_creation(issue_number): |
| 77 | + """Trigger the variant creation workflow for a specific issue""" |
| 78 | + url = f"https://api.github.com/repos/{REPO}/actions/workflows/variant-creator.yaml/dispatches" |
| 79 | + headers = { |
| 80 | + 'Authorization': f'token {GITHUB_TOKEN}', |
| 81 | + 'Accept': 'application/vnd.github.v3+json' |
| 82 | + } |
| 83 | + data = { |
| 84 | + 'ref': 'feat/nextclade_monitor', # or 'master' when merged |
| 85 | + 'inputs': { |
| 86 | + 'issue_number': str(issue_number) |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + try: |
| 91 | + response = requests.post(url, headers=headers, json=data) |
| 92 | + response.raise_for_status() |
| 93 | + print(f"✅ Triggered variant creation for issue #{issue_number}") |
| 94 | + return True |
| 95 | + except Exception as e: |
| 96 | + print(f"❌ Error triggering workflow for issue #{issue_number}: {e}") |
| 97 | + return False |
| 98 | +
|
| 99 | + # Main execution |
| 100 | + print("🔄 Checking for issues that need variant creation retry...") |
| 101 | + |
| 102 | + issues = get_issues_needing_retry() |
| 103 | + print(f"📋 Found {len(issues)} recent issues with variant-creation-needed label") |
| 104 | + |
| 105 | + if not issues: |
| 106 | + print("✅ No issues need retry at this time") |
| 107 | + exit(0) |
| 108 | + |
| 109 | + success_count = 0 |
| 110 | + for issue in issues: |
| 111 | + issue_number = issue['number'] |
| 112 | + print(f"🔄 Triggering retry for issue #{issue_number}: {issue['title']}") |
| 113 | + |
| 114 | + if trigger_variant_creation(issue_number): |
| 115 | + success_count += 1 |
| 116 | + |
| 117 | + print(f"📊 Triggered retry for {success_count}/{len(issues)} issues") |
| 118 | + |
| 119 | + EOF |
0 commit comments