Skip to content

Commit 5d79536

Browse files
Copilothenrymercer
andcommitted
Remove regular workflow file updates from sync-back script
Co-authored-by: henrymercer <[email protected]>
1 parent f77ed60 commit 5d79536

File tree

3 files changed

+4
-86
lines changed

3 files changed

+4
-86
lines changed

pr-checks/readme.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ python3 pr-checks/sync-back.py
3636
The sync-back script automatically updates:
3737
- Hardcoded action versions in `pr-checks/sync.py`
3838
- Action version references in template files in `pr-checks/checks/`
39-
- Action version references in regular workflow files
39+
40+
Regular workflow files are updated directly by Dependabot and don't need sync-back.
4041

4142
This ensures that the `verify-pr-checks.sh` test always passes after Dependabot PRs.
4243

pr-checks/sync-back.py

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
all external action versions used, then updates:
88
1. Hardcoded action versions in pr-checks/sync.py
99
2. Action version references in template files in pr-checks/checks/
10-
3. Action version references in regular workflow files
1110
1211
The script automatically detects all actions used in generated workflows and
1312
preserves version comments (e.g., # v1.2.3) when syncing versions.
1413
1514
This ensures that when Dependabot updates action versions in generated workflows,
16-
those changes are properly synced back to the source templates.
15+
those changes are properly synced back to the source templates. Regular workflow
16+
files are updated directly by Dependabot and don't need sync-back.
1717
"""
1818

1919
import os
@@ -132,45 +132,6 @@ def update_template_files(checks_dir: str, action_versions: Dict[str, str]) -> L
132132
return modified_files
133133

134134

135-
def update_regular_workflows(workflow_dir: str, action_versions: Dict[str, str]) -> List[str]:
136-
"""
137-
Update action versions in regular (non-generated) workflow files
138-
139-
Args:
140-
workflow_dir: Path to .github/workflows directory
141-
action_versions: Dictionary of action names to versions (may include comments)
142-
143-
Returns:
144-
List of files that were modified
145-
"""
146-
modified_files = []
147-
148-
# Get all workflow files that are NOT generated (don't start with __)
149-
all_files = glob.glob(os.path.join(workflow_dir, "*.yml"))
150-
regular_files = [f for f in all_files if not os.path.basename(f).startswith("__")]
151-
152-
for file_path in regular_files:
153-
with open(file_path, 'r') as f:
154-
content = f.read()
155-
156-
original_content = content
157-
158-
# Update action versions
159-
for action_name, version_with_comment in action_versions.items():
160-
# Look for patterns like 'uses: actions/setup-node@v4' or 'uses: actions/setup-node@sha # comment'
161-
pattern = rf"(uses:\s+{re.escape(action_name)})@([^@\n]+)"
162-
replacement = rf"\1@{version_with_comment}"
163-
content = re.sub(pattern, replacement, content)
164-
165-
if content != original_content:
166-
with open(file_path, 'w') as f:
167-
f.write(content)
168-
modified_files.append(file_path)
169-
print(f"Updated {file_path}")
170-
171-
return modified_files
172-
173-
174135
def main():
175136
parser = argparse.ArgumentParser(description="Sync action versions from generated workflows back to templates")
176137
parser.add_argument("--dry-run", action="store_true", help="Show what would be changed without making changes")
@@ -214,10 +175,6 @@ def main():
214175
template_modified = update_template_files(str(checks_dir), action_versions)
215176
modified_files.extend(template_modified)
216177

217-
# Update regular workflow files
218-
workflow_modified = update_regular_workflows(str(workflow_dir), action_versions)
219-
modified_files.extend(workflow_modified)
220-
221178
if modified_files:
222179
print(f"\nSync completed. Modified {len(modified_files)} files:")
223180
for file_path in modified_files:

pr-checks/test_sync_back.py

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -248,46 +248,6 @@ def test_update_template_files_preserves_comments(self):
248248

249249
self.assertIn("uses: ruby/setup-ruby@55511735964dcb71245e7e55f72539531f7bc0eb # v1.257.0", updated_content)
250250

251-
def test_update_regular_workflows(self):
252-
"""Test updating regular workflow files"""
253-
# Create a regular workflow file
254-
workflow_content = """
255-
name: Regular Workflow
256-
jobs:
257-
test:
258-
runs-on: ubuntu-latest
259-
steps:
260-
- uses: actions/checkout@v3
261-
- uses: actions/setup-node@v4
262-
"""
263-
264-
workflow_path = os.path.join(self.workflow_dir, "regular.yml")
265-
with open(workflow_path, 'w') as f:
266-
f.write(workflow_content)
267-
268-
# Create a generated workflow file (should be ignored)
269-
generated_path = os.path.join(self.workflow_dir, "__generated.yml")
270-
with open(generated_path, 'w') as f:
271-
f.write(workflow_content)
272-
273-
action_versions = {
274-
'actions/checkout': 'v4',
275-
'actions/setup-node': 'v5'
276-
}
277-
278-
result = sync_back.update_regular_workflows(self.workflow_dir, action_versions)
279-
280-
# Should only update the regular file, not the generated one
281-
self.assertEqual(len(result), 1)
282-
self.assertIn(workflow_path, result)
283-
self.assertNotIn(generated_path, result)
284-
285-
with open(workflow_path, 'r') as f:
286-
updated_content = f.read()
287-
288-
self.assertIn("uses: actions/checkout@v4", updated_content)
289-
self.assertIn("uses: actions/setup-node@v5", updated_content)
290-
291251
def test_no_changes_needed(self):
292252
"""Test that functions return False/empty when no changes are needed"""
293253
# Test sync.py with no changes needed

0 commit comments

Comments
 (0)