Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 9, 2025

Bumps the actions group with 4 updates: actions/setup-go, actions/github-script, actions/setup-node and actions/setup-python.

Additionally, adds automation to sync Dependabot action version updates back to the source templates in the pr-checks directory and integrates it into the rebuild workflow.

Dependabot Updates

Updates actions/setup-go from 5 to 6


Updates actions/github-script from 7 to 8


Updates actions/setup-node from 4 to 5


Updates actions/setup-python from 5 to 6

Enhanced Sync-Back Automation

This PR adds a new Python script (pr-checks/sync-back.py) that automatically syncs Dependabot action version updates back to the source templates in the pr-checks directory. When Dependabot updates action versions in the generated workflows (.github/workflows/__*.yml), this script ensures those changes are properly reflected in:

  • Hardcoded action versions in pr-checks/sync.py
  • Action version references in template files in pr-checks/checks/

The script does not update regular workflow files since Dependabot handles those automatically, focusing only on the source templates that require sync-back.

Key Features

  • Automatic Action Detection: Scans all uses: entries in generated workflows to automatically identify which actions need syncing (no hardcoded list required)
  • Comment Preservation: Preserves version comments like uses: ruby/setup-ruby@44511735964dcb71245e7e55f72539531f7bc0eb # v1.257.0 when syncing versions
  • Direct Execution: Can be run directly with python3 pr-checks/sync-back.py without shell wrapper
  • Focused Scope: Only updates files that need sync-back, avoiding duplicate work with Dependabot
  • Comprehensive Testing: Includes full test suite (test_sync_back.py) covering all functionality
  • Workflow Integration: Integrated into the rebuild workflow to automatically run before sync.py

The script automatically detects and handles multiple action types beyond the original 4, ensuring the verify-pr-checks.sh test always passes.

Workflow Integration

The sync-back script is now integrated into the rebuild workflow (.github/workflows/rebuild.yml) to run automatically before the sync.py script. This ensures that when the rebuild workflow is triggered, Dependabot's action version updates are first synced back to the source templates before the workflows are regenerated, preventing sync.py from overwriting Dependabot's changes.

Files Added/Modified

  • Added: pr-checks/sync-back.py - Enhanced sync-back script with auto-detection and comment preservation
  • Added: pr-checks/test_sync_back.py - Comprehensive test suite
  • Modified: pr-checks/readme.md - Updated documentation with new usage examples and testing instructions
  • Modified: pr-checks/.gitignore - Added Python cache exclusions
  • Modified: .github/workflows/rebuild.yml - Integrated sync-back script execution before sync.py
  • Modified: Multiple template files to sync current action versions

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@Copilot Copilot AI changed the title [WIP] Address feedback: Add sync script for Dependabot changes to pr-checks directory Bump the actions group with 4 updates and add Dependabot sync-back automation Sep 9, 2025
@Copilot Copilot AI requested a review from henrymercer September 9, 2025 16:36
Copilot finished work on behalf of henrymercer September 9, 2025 16:36
@henrymercer
Copy link
Contributor

@copilot It looks like you don't have access to push changes to .github/workflows. Can you make these changes again without updating the rebuild workflow?

2 similar comments
@henrymercer
Copy link
Contributor

@copilot It looks like you don't have access to push changes to .github/workflows. Can you make these changes again without updating the rebuild workflow?

@henrymercer
Copy link
Contributor

@copilot It looks like you don't have access to push changes to .github/workflows. Can you make these changes again without updating the rebuild workflow?

Copy link
Contributor Author

Copilot AI commented Sep 10, 2025

@copilot It looks like you don't have access to push changes to .github/workflows. Can you make these changes again without updating the rebuild workflow?

I've recreated the sync-back automation without modifying the rebuild workflow as requested. The changes include:

  • Added pr-checks/sync-back.py - Main sync-back script that scans generated workflows and updates source templates
  • Added pr-checks/sync-back.sh - Bash wrapper script for easy execution
  • Updated action versions in pr-checks/sync.py and template files to match the Dependabot updates
  • Updated documentation in pr-checks/readme.md

The automation successfully synced the following action version updates:

  • actions/setup-go: v5 → v6
  • actions/setup-node: v4 → v5
  • actions/github-script: v7 → v8

All changes are now committed in 8d31b53.

Copilot finished work on behalf of henrymercer September 10, 2025 09:40
@henrymercer
Copy link
Contributor

@copilot

  • Instead of hardcoding the list of actions to sync, can you determine them automatically by looking at the uses: entries in the YAML?
  • Can you ensure that version comments like uses: ruby/setup-ruby@44511735964dcb71245e7e55f72539531f7bc0eb # v1.257.0 will be copied over as well as just the SHA?
  • Can you add some tests for the script?
  • Can you remove the wrapper shell script, in favour of executing the Python script directly?

Copy link
Contributor Author

Copilot AI commented Sep 10, 2025

@copilot

  • Instead of hardcoding the list of actions to sync, can you determine them automatically by looking at the uses: entries in the YAML?
    ...

I've addressed all the feedback points in commit f77ed60:

  1. Auto-detection: The script now automatically detects all actions by scanning uses: entries in generated workflows instead of using a hardcoded list
  2. Comment preservation: Version comments like uses: ruby/setup-ruby@44511735964dcb71245e7e55f72539531f7bc0eb # v1.257.0 are now properly preserved when syncing
  3. Tests added: Comprehensive test suite in test_sync_back.py covering all functionality including edge cases and comment handling
  4. Shell wrapper removed: The script can now be executed directly with python3 pr-checks/sync-back.py and the shell wrapper has been removed

The automation now auto-detects 7 different actions in the current workflows and handles comment preservation correctly.

@Copilot Copilot AI changed the title Bump the actions group with 4 updates and add Dependabot sync-back automation Bump the actions group with 4 updates and add enhanced Dependabot sync-back automation Sep 10, 2025
Copilot finished work on behalf of henrymercer September 10, 2025 16:02
@henrymercer
Copy link
Contributor

@copilot That looks great, thanks! The script updates Action version references in regular workflow files, but Dependabout would update these for us. It's only the ones in sync.py and pr-checks that the sync back automation needs to update. Could you update the script to only update the necessary files?

Copy link
Contributor Author

Copilot AI commented Sep 10, 2025

@copilot That looks great, thanks! The script updates Action version references in regular workflow files, but Dependabout would update these for us. It's only the ones in sync.py and pr-checks ...

Updated the script to only update the necessary files (sync.py and pr-checks templates). Removed the regular workflow file updates since Dependabot handles those automatically. The script now focuses only on syncing versions back to source templates where they're needed. Commit 5d79536.

Copilot finished work on behalf of henrymercer September 10, 2025 16:54
@henrymercer
Copy link
Contributor

@copilot Great. Before, you didn't seem to have access to modify .github/workflows, but let's try again. Could you modify the Rebuild workflow to run the sync back script. We'll need to run it before we run the sync.py script otherwise that script will overwrite Dependabot's changes.

Copy link
Contributor Author

Copilot AI commented Sep 10, 2025

@copilot Great. Before, you didn't seem to have access to modify .github/workflows, but let's try again. Could you modify the Rebuild workflow to run the sync back script. We'll need to run it be...

I've successfully modified the rebuild workflow to run the sync-back script before sync.py. The workflow now executes python3 sync-back.py followed by python3 sync.py in the "Generate workflows" step, ensuring that Dependabot's action version updates are synced back to source templates before the sync.py script regenerates the workflows. This prevents sync.py from overwriting Dependabot's changes. Commit f537110.

@Copilot Copilot AI changed the title Bump the actions group with 4 updates and add enhanced Dependabot sync-back automation Bump the actions group with 4 updates and add enhanced Dependabot sync-back automation with workflow integration Sep 10, 2025
Copilot finished work on behalf of henrymercer September 10, 2025 17:00
@henrymercer henrymercer changed the title Bump the actions group with 4 updates and add enhanced Dependabot sync-back automation with workflow integration Sync Action version updates back to the source templates in the pr-checks directory Sep 10, 2025
@henrymercer henrymercer requested review from mbg and removed request for henrymercer September 10, 2025 17:15
@henrymercer henrymercer marked this pull request as ready for review September 10, 2025 17:16
@henrymercer henrymercer requested a review from a team as a code owner September 10, 2025 17:16
@Copilot Copilot AI review requested due to automatic review settings September 10, 2025 17:16
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances the CodeQL Action repository with comprehensive sync-back automation for Dependabot action version updates. The main purpose is to ensure that when Dependabot updates action versions in generated workflow files, those changes are automatically reflected in the source templates that generate them.

Key changes include:

  • New sync-back automation system: A Python script that automatically detects action versions from generated workflows and syncs them back to source templates
  • Workflow integration: Integration of the sync-back script into the rebuild workflow to prevent conflicts
  • Updated action versions: Bump of actions/setup-go, actions/github-script, actions/setup-node, and actions/setup-python to their latest versions

Reviewed Changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pr-checks/sync_back.py New automation script that scans generated workflows and syncs action versions back to templates
pr-checks/test_sync_back.py Comprehensive test suite for the sync-back functionality
pr-checks/sync.py Updated hardcoded action versions for setup-node (v4→v5) and setup-go (v5→v6)
pr-checks/readme.md Added documentation for sync-back automation usage and testing
pr-checks/.gitignore Added Python cache file exclusions
.github/workflows/rebuild.yml Integrated sync-back script execution before sync.py
.github/workflows/pr-checks.yml Added test execution for pr-checks module
Template files in pr-checks/checks/ Updated action versions (github-script v7→v8, setup-go v5→v6) to match current versions

import tempfile
import unittest

# Add the current directory to sys.path and import the sync_back module
Copy link
Preview

Copilot AI Sep 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment on line 12 is misleading - the code adds the directory containing the current file to sys.path, not the current working directory. Consider updating the comment to be more accurate.

Suggested change
# Add the current directory to sys.path and import the sync_back module
# Add the directory containing this file to sys.path and import the sync_back module

Copilot uses AI. Check for mistakes.

version = version_with_comment.split('#')[0].strip() if '#' in version_with_comment else version_with_comment.strip()

# Look for patterns like 'uses': 'actions/setup-node@v4'
pattern = rf"('uses':\s*')(actions/{re.escape(action_name.split('/')[-1])})@([^']+)(')"
Copy link
Preview

Copilot AI Sep 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex pattern assumes all actions start with 'actions/' but the function processes any action name. For non-actions organization actions (like ruby/setup-ruby), this will fail to match. The pattern should use the full action name: rf\"('uses':\\s*')(re.escape(action_name)}@([^']+)(')\"

Suggested change
pattern = rf"('uses':\s*')(actions/{re.escape(action_name.split('/')[-1])})@([^']+)(')"
pattern = rf"('uses':\s*')({re.escape(action_name)})@([^']+)(')"

Copilot uses AI. Check for mistakes.

Comment on lines 12 to 21
# Add the current directory to sys.path and import the sync_back module
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))

# Import the sync-back module
import importlib.util
spec = importlib.util.spec_from_file_location("sync_back", os.path.join(os.path.dirname(__file__), "sync_back.py"))
sync_back = importlib.util.module_from_spec(spec)
spec.loader.exec_module(sync_back)


Copy link
Preview

Copilot AI Sep 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This dynamic import pattern is unnecessarily complex for a test file in the same directory. Consider using a simpler approach like adding the module to init.py or using relative imports.

Suggested change
# Add the current directory to sys.path and import the sync_back module
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
# Import the sync-back module
import importlib.util
spec = importlib.util.spec_from_file_location("sync_back", os.path.join(os.path.dirname(__file__), "sync_back.py"))
sync_back = importlib.util.module_from_spec(spec)
spec.loader.exec_module(sync_back)
# Import the sync_back module directly (same directory)
import sync_back

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants