-
Notifications
You must be signed in to change notification settings - Fork 3
feat: create script to update versions automatically #132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c31b410
feat: create script to update versions automaticlly
shenxianpeng 518be04
chore: use full commit SHA hash for this dependency
shenxianpeng 07ec87c
fix: update update_versions.py
shenxianpeng 75397a4
fix: update update_versions.py
shenxianpeng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| name: Update Tool Versions | ||
|
|
||
| on: | ||
| schedule: | ||
| # Run every Monday at 2 AM UTC | ||
| - cron: '0 2 * * 1' | ||
| workflow_dispatch: # Allow manual trigger | ||
|
|
||
| jobs: | ||
| update-versions: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v4 | ||
| with: | ||
| python-version: '3.11' | ||
|
|
||
| - name: Update versions | ||
| run: | | ||
| python3 scripts/update_versions.py | ||
|
|
||
| - name: Check for changes | ||
| id: verify-changed-files | ||
| run: | | ||
| if [ -n "$(git status --porcelain)" ]; then | ||
| echo "changed=true" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "changed=false" >> $GITHUB_OUTPUT | ||
| fi | ||
|
|
||
| - name: Get latest versions for PR description | ||
| if: steps.verify-changed-files.outputs.changed == 'true' | ||
| id: get-versions | ||
| run: | | ||
| CLANG_FORMAT_VERSION=$(python3 -c 'from cpp_linter_hooks.versions import CLANG_FORMAT_VERSIONS; print(CLANG_FORMAT_VERSIONS[-1])') | ||
| CLANG_TIDY_VERSION=$(python3 -c 'from cpp_linter_hooks.versions import CLANG_TIDY_VERSIONS; print(CLANG_TIDY_VERSIONS[-1])') | ||
| echo "clang_format_version=$CLANG_FORMAT_VERSION" >> $GITHUB_OUTPUT | ||
| echo "clang_tidy_version=$CLANG_TIDY_VERSION" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Create Pull Request | ||
| if: steps.verify-changed-files.outputs.changed == 'true' | ||
| uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8 | ||
| with: | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
| commit-message: | | ||
| chore: update clang-format and clang-tidy versions | ||
|
|
||
| - Updated versions automatically from PyPI | ||
| title: "chore: update tool versions to latest" | ||
| body: | | ||
| ## 🔄 Automated Version Update | ||
|
|
||
| This PR updates the hardcoded versions for clang-format and clang-tidy tools to the latest available versions from PyPI. | ||
|
|
||
| ### 📦 Updated Versions | ||
| - **clang-format**: `${{ steps.get-versions.outputs.clang_format_version }}` | ||
| - **clang-tidy**: `${{ steps.get-versions.outputs.clang_tidy_version }}` | ||
|
|
||
| ### 🤖 Automation Details | ||
| - This update was triggered automatically by the scheduled workflow | ||
| - Versions are fetched from the official PyPI APIs | ||
| - Only stable versions (no pre-releases) are included | ||
|
|
||
| ### ✅ What's Changed | ||
| - Updated `cpp_linter_hooks/versions.py` with latest tool versions | ||
| - No breaking changes expected | ||
| - Maintains backward compatibility | ||
|
|
||
| ### 🔍 Review Checklist | ||
| - [ ] Verify the new versions are stable releases | ||
| - [ ] Check that no pre-release versions were included | ||
| - [ ] Confirm the version format matches expectations | ||
|
|
||
| --- | ||
|
|
||
| *This PR was created automatically by the `update-versions.yml` workflow.* | ||
| branch: update-tool-versions | ||
| delete-branch: true | ||
| base: main | ||
| labels: dependencies |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| """ | ||
| Version management for clang-format and clang-tidy. | ||
|
|
||
| This module provides hardcoded version lists that are updated periodically via GitHub Actions. | ||
| """ | ||
|
|
||
| # Updated automatically by GitHub Actions - DO NOT EDIT MANUALLY | ||
| CLANG_FORMAT_VERSIONS = [ | ||
| "6.0.1", | ||
| "7.1.0", | ||
| "8.0.1", | ||
| "9.0.0", | ||
| "10.0.1", | ||
| "10.0.1.1", | ||
| "11.0.1", | ||
| "11.0.1.1", | ||
| "11.0.1.2", | ||
| "11.1.0", | ||
| "11.1.0.1", | ||
| "11.1.0.2", | ||
| "12.0.1", | ||
| "12.0.1.1", | ||
| "12.0.1.2", | ||
| "13.0.0", | ||
| "13.0.1", | ||
| "13.0.1.1", | ||
| "14.0.0", | ||
| "14.0.1", | ||
| "14.0.3", | ||
| "14.0.4", | ||
| "14.0.5", | ||
| "14.0.6", | ||
| "15.0.4", | ||
| "15.0.6", | ||
| "15.0.7", | ||
| "16.0.0", | ||
| "16.0.1", | ||
| "16.0.2", | ||
| "16.0.3", | ||
| "16.0.4", | ||
| "16.0.5", | ||
| "16.0.6", | ||
| "17.0.1", | ||
| "17.0.2", | ||
| "17.0.3", | ||
| "17.0.4", | ||
| "17.0.5", | ||
| "17.0.6", | ||
| "18.1.0", | ||
| "18.1.1", | ||
| "18.1.2", | ||
| "18.1.3", | ||
| "18.1.4", | ||
| "18.1.5", | ||
| "18.1.6", | ||
| "18.1.7", | ||
| "18.1.8", | ||
| "19.1.0", | ||
| "19.1.1", | ||
| "19.1.2", | ||
| "19.1.3", | ||
| "19.1.4", | ||
| "19.1.5", | ||
| "19.1.6", | ||
| "19.1.7", | ||
| "20.1.0", | ||
| "20.1.3", | ||
| "20.1.4", | ||
| "20.1.5", | ||
| "20.1.6", | ||
| "20.1.7", | ||
| "20.1.8", | ||
| "21.1.0", | ||
| "21.1.1", | ||
| "21.1.2", | ||
| ] | ||
|
|
||
| # Updated automatically by GitHub Actions - DO NOT EDIT MANUALLY | ||
| CLANG_TIDY_VERSIONS = [ | ||
| "13.0.1.1", | ||
| "14.0.6", | ||
| "15.0.2", | ||
| "15.0.2.1", | ||
| "16.0.4", | ||
| "17.0.1", | ||
| "18.1.1", | ||
| "18.1.8", | ||
| "19.1.0", | ||
| "19.1.0.1", | ||
| "20.1.0", | ||
| "21.1.0", | ||
| "21.1.1", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| #!/usr/bin/env python3 | ||
| """ | ||
| Script to update clang-format and clang-tidy versions from PyPI API. | ||
|
|
||
| Usage: | ||
| python scripts/update_versions.py | ||
| """ | ||
|
|
||
| import json | ||
| import urllib.request | ||
| from pathlib import Path | ||
| import re | ||
| from typing import List | ||
|
|
||
|
|
||
| def fetch_versions_from_pypi(package_name: str) -> List[str]: | ||
| """Fetch available versions for a package from PyPI API.""" | ||
| url = f"https://pypi.org/pypi/{package_name}/json" | ||
| try: | ||
| with urllib.request.urlopen(url, timeout=10) as response: | ||
| data = json.loads(response.read()) | ||
| versions = list(data["releases"].keys()) | ||
| # Filter out pre-release versions using proper regex patterns | ||
| pre_release_pattern = re.compile( | ||
| r".*(alpha|beta|rc|dev|a\d+|b\d+).*", re.IGNORECASE | ||
| ) | ||
| stable_versions = [v for v in versions if not pre_release_pattern.match(v)] | ||
| return sorted(stable_versions, key=lambda x: tuple(map(int, x.split(".")))) | ||
shenxianpeng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| except Exception as e: | ||
| print(f"Failed to fetch versions for {package_name}: {e}") | ||
| return [] | ||
|
|
||
|
|
||
| def update_versions_file(): | ||
| """Update the versions.py file with latest versions from PyPI.""" | ||
| clang_format_versions = fetch_versions_from_pypi("clang-format") | ||
| clang_tidy_versions = fetch_versions_from_pypi("clang-tidy") | ||
|
|
||
| if not clang_format_versions or not clang_tidy_versions: | ||
| print("Failed to fetch versions from PyPI") | ||
| return False | ||
|
|
||
| versions_file = Path(__file__).parent.parent / "cpp_linter_hooks" / "versions.py" | ||
|
|
||
| with open(versions_file, "r") as f: | ||
| content = f.read() | ||
|
|
||
| # Update clang-format versions | ||
| clang_format_list = ( | ||
| "[\n" + "\n".join(f' "{v}",' for v in clang_format_versions) + "\n]" | ||
| ) | ||
| content = re.sub( | ||
| r"(CLANG_FORMAT_VERSIONS = )\[[^\]]*\]", | ||
| rf"\1{clang_format_list}", | ||
| content, | ||
| flags=re.DOTALL, | ||
| ) | ||
|
|
||
| # Update clang-tidy versions | ||
| clang_tidy_list = ( | ||
| "[\n" + "\n".join(f' "{v}",' for v in clang_tidy_versions) + "\n]" | ||
| ) | ||
| content = re.sub( | ||
| r"(CLANG_TIDY_VERSIONS = )\[[^\]]*\]", | ||
| rf"\1{clang_tidy_list}", | ||
| content, | ||
| flags=re.DOTALL, | ||
| ) | ||
|
|
||
| with open(versions_file, "w") as f: | ||
| f.write(content) | ||
|
|
||
| print("Updated versions:") | ||
| print( | ||
| f" clang-format: {len(clang_format_versions)} versions (latest: {clang_format_versions[-1]})" | ||
| ) | ||
| print( | ||
| f" clang-tidy: {len(clang_tidy_versions)} versions (latest: {clang_tidy_versions[-1]})" | ||
| ) | ||
|
|
||
| return True | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| success = update_versions_file() | ||
| exit(0 if success else 1) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.