Skip to content

Commit 4d64aae

Browse files
aidenmitchellclaude
andcommitted
Preserve rules from previous passing CI when current CI fails
When a PR has a new commit that fails CI (or CI is still pending), preserve the existing synced rules from the previous passing commit instead of removing them. Also don't remove the in-test-rules label since the rule is still in test-rules (just an older version). This prevents: 1. Rules disappearing when CI is slow or temporarily failing 2. False "manual exclusion" detection when the label was removed by the script due to CI failure, not by a user Changes: - sync_test_rules.py: Remove label removal on CI failure, add file preservation logic - sync_shared_samples.py: Add CI checking (was missing entirely), with file preservation for failing/pending CI Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 7739f0e commit 4d64aae

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

.github/scripts/sync_shared_samples.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
DEFAULT_AUTHOR_TAG_PREFIX,
3232
DEFAULT_RULE_STATUS_PREFIX,
3333
DEFAULT_OPEN_PR_TAG,
34+
DEFAULT_REQUIRED_CHECK_NAME,
35+
DEFAULT_REQUIRED_CHECK_CONCLUSION,
3436
# GraphQL
3537
create_graphql_session,
3638
fetch_all_prs,
@@ -76,6 +78,11 @@
7678
SKIP_BULK_PRS = os.getenv('SKIP_BULK_PRS', 'true').lower() == 'true'
7779
MAX_RULES_PER_PR = int(os.getenv('MAX_RULES_PER_PR', str(DEFAULT_MAX_RULES_PER_PR)))
7880

81+
# Action completion checks
82+
CHECK_ACTION_COMPLETION = os.getenv('CHECK_ACTION_COMPLETION', 'true').lower() == 'true'
83+
REQUIRED_CHECK_NAME = os.getenv('REQUIRED_CHECK_NAME', DEFAULT_REQUIRED_CHECK_NAME)
84+
REQUIRED_CHECK_CONCLUSION = os.getenv('REQUIRED_CHECK_CONCLUSION', DEFAULT_REQUIRED_CHECK_CONCLUSION)
85+
7986
# Create output folder if it doesn't exist
8087
if not os.path.exists(OUTPUT_FOLDER):
8188
os.makedirs(OUTPUT_FOLDER)
@@ -307,6 +314,18 @@ def handle_pr_rules(graphql_session, rest_session):
307314
latest_sha = pr.head_sha
308315
print(f"\tLatest commit SHA: {latest_sha}")
309316

317+
# Check if required checks have completed (in-memory check)
318+
if CHECK_ACTION_COMPLETION:
319+
if not pr.has_required_check(REQUIRED_CHECK_NAME, REQUIRED_CHECK_CONCLUSION):
320+
print(f"\tSkipping PR #{pr_number}: Required check '{REQUIRED_CHECK_NAME}' has not completed with conclusion '{REQUIRED_CHECK_CONCLUSION}'")
321+
# Preserve existing synced files from previous passing commits
322+
prefix = f"{pr_number}_"
323+
for filename in os.listdir(OUTPUT_FOLDER):
324+
if filename.startswith(prefix) and filename.endswith('.yml'):
325+
print(f"\tPreserving existing file: {filename}")
326+
new_files.add(filename)
327+
continue
328+
310329
# Use files from GraphQL data (already fetched)
311330
files = pr.files
312331

.github/scripts/sync_test_rules.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,13 @@ def handle_pr_rules(graphql_session, rest_session):
218218
if CHECK_ACTION_COMPLETION:
219219
if not pr.has_required_check(REQUIRED_CHECK_NAME, REQUIRED_CHECK_CONCLUSION):
220220
print(f"\tSkipping PR #{pr_number}: Required check '{REQUIRED_CHECK_NAME}' has not completed with conclusion '{REQUIRED_CHECK_CONCLUSION}'")
221-
# Remove in-test-rules label if previously applied
222-
if pr.has_label(IN_TEST_RULES_LABEL):
223-
remove_label(rest_session, REPO_OWNER, REPO_NAME, pr_number, IN_TEST_RULES_LABEL)
221+
# Preserve existing synced files from previous passing commits
222+
# Don't remove in-test-rules label since the rule is still in test-rules (older version)
223+
prefix = f"{pr_number}_"
224+
for filename in os.listdir(OUTPUT_FOLDER):
225+
if filename.startswith(prefix) and filename.endswith('.yml'):
226+
print(f"\tPreserving existing file: {filename}")
227+
new_files.add(filename)
224228
continue
225229

226230
# Use files from GraphQL data (already fetched)

0 commit comments

Comments
 (0)