From b050367a6590cb6d499f5a84bcc7d99e70284d45 Mon Sep 17 00:00:00 2001 From: Inaki Fernandez Date: Sun, 12 Jul 2026 21:15:17 +0200 Subject: [PATCH] feat(workflow): add run-attempt caching, PR creation resilience, and fallback triage issue creation --- .../02.1.intelligent_link_cleaner.yml | 33 +++++++++++++++++-- src/gitops_manager.py | 24 ++++++++++---- 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/.github/workflows/02.1.intelligent_link_cleaner.yml b/.github/workflows/02.1.intelligent_link_cleaner.yml index 3cb6a511..eda76464 100644 --- a/.github/workflows/02.1.intelligent_link_cleaner.yml +++ b/.github/workflows/02.1.intelligent_link_cleaner.yml @@ -51,6 +51,17 @@ jobs: if: steps.playwright-cache.outputs.cache-hit != 'true' run: playwright install chromium --with-deps + - name: Restore Link Checker Cache + uses: actions/cache/restore@v4 + id: link-checker-cache + with: + path: | + shard_result.json + triage_report.md + key: link-cleaner-results-${{ github.run_id }}-${{ github.run_attempt }} + restore-keys: | + link-cleaner-results-${{ github.run_id }}- + - name: Global Intelligent Cleaning Execution (Sequential Fast-Track) env: GEMINI_API_KEY_1: ${{ secrets.GEMINI_API_KEY_1 }} @@ -60,7 +71,11 @@ jobs: PYTHONPATH: ${{ github.workspace }} PYTHONUNBUFFERED: 1 run: | - python src/intelligent_health_checker.py + if [ -f shard_result.json ]; then + echo "shard_result.json found in cache/restored files. Skipping health checker execution." + else + python src/intelligent_health_checker.py + fi - name: Run Inventory Reducer & Apply Changes env: @@ -79,9 +94,23 @@ jobs: EXISTING_ISSUE=$(gh issue list --search "$ISSUE_TITLE" --state open --json number --jq '.[0].number') if [ -z "$EXISTING_ISSUE" ]; then - gh issue create --title "$ISSUE_TITLE" --body-file triage_report.md --label "triage, automated-report" + gh issue create --title "$ISSUE_TITLE" --body-file triage_report.md --label "triage, automated-report" || gh issue create --title "$ISSUE_TITLE" --body-file triage_report.md else echo "A triage issue already exists (#$EXISTING_ISSUE). Updating with new report..." gh issue comment $EXISTING_ISSUE --body-file triage_report.md fi fi + + - name: Ensure Cache Files Exist + if: always() + run: | + touch shard_result.json triage_report.md + + - name: Save Link Checker Cache + if: always() + uses: actions/cache/save@v4 + with: + path: | + shard_result.json + triage_report.md + key: link-cleaner-results-${{ github.run_id }}-${{ github.run_attempt }} diff --git a/src/gitops_manager.py b/src/gitops_manager.py index 364bec01..e75a368b 100644 --- a/src/gitops_manager.py +++ b/src/gitops_manager.py @@ -151,12 +151,24 @@ class RepositoryController: pr_body += f"{ai_intel}\n\n{mermaid}\n{source_md}\n{gems_md}\n---\n**Audit Matrix and Logs follow in successive comments.**\n" - pr = self.repository.create_pull( - title=f"💎 Knowledge Update & Optimization: {datetime.now().strftime('%d %b %Y')}", - body=pr_body[:65000], - head=branch_name, - base=self.default_branch_name - ) + try: + pr = self.repository.create_pull( + title=f"💎 Knowledge Update & Optimization: {datetime.now().strftime('%d %b %Y')}", + body=pr_body[:65000], + head=branch_name, + base=self.default_branch_name + ) + except Exception as e: + if "pull request already exists" in str(e).lower() or "422" in str(e): + print(f"[INFO] Pull request already exists for branch {branch_name}. Fetching existing one...") + pulls = self.repository.get_pulls(state='open', head=f"{self.repository.owner.login}:{branch_name}") + if pulls.totalCount > 0: + pr = pulls[0] + pr.edit(body=pr_body[:65000]) + else: + raise e + else: + raise e # 1. Safety Report (if huge) if not safety_in_body: