From 5a2fc56b2af41d8f56589ef1a623de4a1037e02f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 18 Sep 2025 20:54:47 +0000 Subject: [PATCH 1/9] Initial plan From 7b4ce0adf60e3e300e85362451b0ee0be9014d75 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 18 Sep 2025 21:03:03 +0000 Subject: [PATCH 2/9] Add default tool versions to release notes Co-authored-by: shenxianpeng <3353385+shenxianpeng@users.noreply.github.com> --- .github/release-drafter.yml | 17 ++++++++++++ .github/workflows/release-drafter.yml | 40 ++++++++++++++++++++++++++- scripts/get_default_versions.py | 23 +++++++++++++++ tests/test_util.py | 29 +++++++++++++++++++ 4 files changed, 108 insertions(+), 1 deletion(-) create mode 100755 scripts/get_default_versions.py diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index 0d0b1c9..0e49037 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -1 +1,18 @@ +# Configuration for Release Drafter: https://github.com/toolmantim/release-drafter _extends: .github + +# Override the template to include default tool versions +template: | + + + ## Default Tool Versions + + This release uses the following default versions: + - **clang-format**: `$CLANG_FORMAT_VERSION` + - **clang-tidy**: `$CLANG_TIDY_VERSION` + + Users can override these versions by specifying a different version in their hook configuration. + + $CHANGES + + **Full Changelog**: https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...v$RESOLVED_VERSION diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index 2250d38..3aea0be 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -8,4 +8,42 @@ on: jobs: draft-release: - uses: cpp-linter/.github/.github/workflows/release-drafter.yml@main + permissions: + # write permission is required to create a github release + contents: write + # write permission is required for autolabeler + # otherwise, read permission is required at least + pull-requests: write + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install -e . + + - name: Extract default tool versions + id: versions + run: | + CLANG_FORMAT_VERSION=$(python -c "from cpp_linter_hooks.util import DEFAULT_CLANG_FORMAT_VERSION; print(DEFAULT_CLANG_FORMAT_VERSION)") + CLANG_TIDY_VERSION=$(python -c "from cpp_linter_hooks.util import DEFAULT_CLANG_TIDY_VERSION; print(DEFAULT_CLANG_TIDY_VERSION)") + echo "CLANG_FORMAT_VERSION=$CLANG_FORMAT_VERSION" >> $GITHUB_OUTPUT + echo "CLANG_TIDY_VERSION=$CLANG_TIDY_VERSION" >> $GITHUB_OUTPUT + echo "Default clang-format version: $CLANG_FORMAT_VERSION" + echo "Default clang-tidy version: $CLANG_TIDY_VERSION" + + # Draft your next Release notes as Pull Requests are merged into the default branch + - uses: release-drafter/release-drafter@b1476f6e6eb133afa41ed8589daba6dc69b4d3f5 #v6 + with: + commitish: 'main' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + CLANG_FORMAT_VERSION: ${{ steps.versions.outputs.CLANG_FORMAT_VERSION }} + CLANG_TIDY_VERSION: ${{ steps.versions.outputs.CLANG_TIDY_VERSION }} diff --git a/scripts/get_default_versions.py b/scripts/get_default_versions.py new file mode 100755 index 0000000..d47522a --- /dev/null +++ b/scripts/get_default_versions.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +"""Script to extract default clang-format and clang-tidy versions from pyproject.toml.""" + +import sys +from pathlib import Path + +# Add the project root to Python path +project_root = Path(__file__).parent.parent +sys.path.insert(0, str(project_root)) + +from cpp_linter_hooks.util import DEFAULT_CLANG_FORMAT_VERSION, DEFAULT_CLANG_TIDY_VERSION + +def main(): + """Print the default tool versions.""" + print(f"Default clang-format version: {DEFAULT_CLANG_FORMAT_VERSION}") + print(f"Default clang-tidy version: {DEFAULT_CLANG_TIDY_VERSION}") + + # Also output in a format suitable for GitHub Actions + print(f"CLANG_FORMAT_VERSION={DEFAULT_CLANG_FORMAT_VERSION}") + print(f"CLANG_TIDY_VERSION={DEFAULT_CLANG_TIDY_VERSION}") + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/tests/test_util.py b/tests/test_util.py index 9ce5b21..a99c044 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -262,6 +262,35 @@ def test_version_lists_not_empty(): assert all(isinstance(v, str) for v in CLANG_TIDY_VERSIONS) +@pytest.mark.benchmark +def test_get_default_versions_script(): + """Test that the get_default_versions script works correctly.""" + import subprocess + import sys + from pathlib import Path + + script_path = Path(__file__).parent.parent / "scripts" / "get_default_versions.py" + assert script_path.exists(), "get_default_versions.py script should exist" + + result = subprocess.run( + [sys.executable, str(script_path)], + capture_output=True, + text=True + ) + + assert result.returncode == 0, f"Script failed with: {result.stderr}" + output_lines = result.stdout.strip().split('\n') + + # Should have 4 lines of output + assert len(output_lines) >= 4 + + # Check that it contains expected format + assert any(line.startswith("Default clang-format version:") for line in output_lines) + assert any(line.startswith("Default clang-tidy version:") for line in output_lines) + assert any(line.startswith("CLANG_FORMAT_VERSION=") for line in output_lines) + assert any(line.startswith("CLANG_TIDY_VERSION=") for line in output_lines) + + @pytest.mark.benchmark def test_resolve_install_with_none_default_version(): """Test _resolve_install when DEFAULT versions are None.""" From 01af8109020b5838650ba2ee3216b60f9c601399 Mon Sep 17 00:00:00 2001 From: Xianpeng Shen Date: Fri, 19 Sep 2025 09:28:24 +0300 Subject: [PATCH 3/9] Update scripts/get_default_versions.py --- scripts/get_default_versions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/get_default_versions.py b/scripts/get_default_versions.py index d47522a..43b2ade 100755 --- a/scripts/get_default_versions.py +++ b/scripts/get_default_versions.py @@ -20,4 +20,4 @@ def main(): print(f"CLANG_TIDY_VERSION={DEFAULT_CLANG_TIDY_VERSION}") if __name__ == "__main__": - main() \ No newline at end of file + main() From 9f9be32e476921a167b975df42d6e09ec5be40f1 Mon Sep 17 00:00:00 2001 From: Xianpeng Shen Date: Fri, 19 Sep 2025 09:28:29 +0300 Subject: [PATCH 4/9] Update .github/release-drafter.yml --- .github/release-drafter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index 0e49037..755984d 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -11,7 +11,7 @@ template: | - **clang-format**: `$CLANG_FORMAT_VERSION` - **clang-tidy**: `$CLANG_TIDY_VERSION` - Users can override these versions by specifying a different version in their hook configuration. + Users can specify the desired version by adding the `--version` argument under `args` in their pre-commit configuration. See: [Custom Clang Tool Version](https://github.com/cpp-linter/cpp-linter-hooks?tab=readme-ov-file#custom-clang-tool-version) $CHANGES From 948d02075c90cb9cb347c02962f6d67599a16aa8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 19 Sep 2025 06:34:13 +0000 Subject: [PATCH 5/9] Remove unused script and tests, update release template title Co-authored-by: shenxianpeng <3353385+shenxianpeng@users.noreply.github.com> --- .github/release-drafter.yml | 2 +- scripts/get_default_versions.py | 23 ----------------------- tests/test_util.py | 29 ----------------------------- 3 files changed, 1 insertion(+), 53 deletions(-) delete mode 100755 scripts/get_default_versions.py diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index 755984d..15dd578 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -5,7 +5,7 @@ _extends: .github template: | - ## Default Tool Versions + ## Default Clang Tools Versions This release uses the following default versions: - **clang-format**: `$CLANG_FORMAT_VERSION` diff --git a/scripts/get_default_versions.py b/scripts/get_default_versions.py deleted file mode 100755 index 43b2ade..0000000 --- a/scripts/get_default_versions.py +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env python3 -"""Script to extract default clang-format and clang-tidy versions from pyproject.toml.""" - -import sys -from pathlib import Path - -# Add the project root to Python path -project_root = Path(__file__).parent.parent -sys.path.insert(0, str(project_root)) - -from cpp_linter_hooks.util import DEFAULT_CLANG_FORMAT_VERSION, DEFAULT_CLANG_TIDY_VERSION - -def main(): - """Print the default tool versions.""" - print(f"Default clang-format version: {DEFAULT_CLANG_FORMAT_VERSION}") - print(f"Default clang-tidy version: {DEFAULT_CLANG_TIDY_VERSION}") - - # Also output in a format suitable for GitHub Actions - print(f"CLANG_FORMAT_VERSION={DEFAULT_CLANG_FORMAT_VERSION}") - print(f"CLANG_TIDY_VERSION={DEFAULT_CLANG_TIDY_VERSION}") - -if __name__ == "__main__": - main() diff --git a/tests/test_util.py b/tests/test_util.py index a99c044..9ce5b21 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -262,35 +262,6 @@ def test_version_lists_not_empty(): assert all(isinstance(v, str) for v in CLANG_TIDY_VERSIONS) -@pytest.mark.benchmark -def test_get_default_versions_script(): - """Test that the get_default_versions script works correctly.""" - import subprocess - import sys - from pathlib import Path - - script_path = Path(__file__).parent.parent / "scripts" / "get_default_versions.py" - assert script_path.exists(), "get_default_versions.py script should exist" - - result = subprocess.run( - [sys.executable, str(script_path)], - capture_output=True, - text=True - ) - - assert result.returncode == 0, f"Script failed with: {result.stderr}" - output_lines = result.stdout.strip().split('\n') - - # Should have 4 lines of output - assert len(output_lines) >= 4 - - # Check that it contains expected format - assert any(line.startswith("Default clang-format version:") for line in output_lines) - assert any(line.startswith("Default clang-tidy version:") for line in output_lines) - assert any(line.startswith("CLANG_FORMAT_VERSION=") for line in output_lines) - assert any(line.startswith("CLANG_TIDY_VERSION=") for line in output_lines) - - @pytest.mark.benchmark def test_resolve_install_with_none_default_version(): """Test _resolve_install when DEFAULT versions are None.""" From 415e40d2e97e2a40e04e9a1382581177ab2be635 Mon Sep 17 00:00:00 2001 From: Xianpeng Shen Date: Fri, 19 Sep 2025 09:45:24 +0300 Subject: [PATCH 6/9] Update .github/workflows/release-drafter.yml --- .github/workflows/release-drafter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index 3aea0be..8bec431 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -17,7 +17,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - name: Set up Python uses: actions/setup-python@v5 From 8a73ee7672286b42cf8166cc349fd48a8e88f254 Mon Sep 17 00:00:00 2001 From: Xianpeng Shen Date: Fri, 19 Sep 2025 09:45:32 +0300 Subject: [PATCH 7/9] Update .github/workflows/release-drafter.yml --- .github/workflows/release-drafter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index 8bec431..06a3afc 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -20,7 +20,7 @@ jobs: uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - name: Set up Python - uses: actions/setup-python@v5 + uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0 with: python-version: "3.12" From 5ff47d5a999fc636326d5a532f0f4bc064b514bb Mon Sep 17 00:00:00 2001 From: Xianpeng Shen Date: Fri, 19 Sep 2025 06:48:45 +0000 Subject: [PATCH 8/9] chore: fix from pre-commit --- .github/release-drafter.yml | 8 ++++---- .github/workflows/release-drafter.yml | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index 15dd578..027979c 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -4,15 +4,15 @@ _extends: .github # Override the template to include default tool versions template: | - + ## Default Clang Tools Versions - + This release uses the following default versions: - **clang-format**: `$CLANG_FORMAT_VERSION` - **clang-tidy**: `$CLANG_TIDY_VERSION` - + Users can specify the desired version by adding the `--version` argument under `args` in their pre-commit configuration. See: [Custom Clang Tool Version](https://github.com/cpp-linter/cpp-linter-hooks?tab=readme-ov-file#custom-clang-tool-version) - + $CHANGES **Full Changelog**: https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...v$RESOLVED_VERSION diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index 06a3afc..e733d71 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -18,17 +18,17 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - + - name: Set up Python uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0 with: python-version: "3.12" - + - name: Install dependencies run: | python -m pip install --upgrade pip python -m pip install -e . - + - name: Extract default tool versions id: versions run: | @@ -38,7 +38,7 @@ jobs: echo "CLANG_TIDY_VERSION=$CLANG_TIDY_VERSION" >> $GITHUB_OUTPUT echo "Default clang-format version: $CLANG_FORMAT_VERSION" echo "Default clang-tidy version: $CLANG_TIDY_VERSION" - + # Draft your next Release notes as Pull Requests are merged into the default branch - uses: release-drafter/release-drafter@b1476f6e6eb133afa41ed8589daba6dc69b4d3f5 #v6 with: From 020053733147bafa88d397e4c1b754f7ed2c8ca9 Mon Sep 17 00:00:00 2001 From: Xianpeng Shen Date: Fri, 19 Sep 2025 06:56:08 +0000 Subject: [PATCH 9/9] docs: revise template --- .github/release-drafter.yml | 5 ++--- .github/workflows/release-drafter.yml | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index 027979c..67f4c57 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -5,13 +5,12 @@ _extends: .github template: | - ## Default Clang Tools Versions + ## Default Clang Tools Versions for this release - This release uses the following default versions: - **clang-format**: `$CLANG_FORMAT_VERSION` - **clang-tidy**: `$CLANG_TIDY_VERSION` - Users can specify the desired version by adding the `--version` argument under `args` in their pre-commit configuration. See: [Custom Clang Tool Version](https://github.com/cpp-linter/cpp-linter-hooks?tab=readme-ov-file#custom-clang-tool-version) + You can override the default versions by adding the `--version` argument under `args` in your pre-commit configuration. For details, see [Custom Clang Tool Version](https://github.com/cpp-linter/cpp-linter-hooks?tab=readme-ov-file#custom-clang-tool-version) $CHANGES diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index e733d71..58cf6b1 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -40,7 +40,7 @@ jobs: echo "Default clang-tidy version: $CLANG_TIDY_VERSION" # Draft your next Release notes as Pull Requests are merged into the default branch - - uses: release-drafter/release-drafter@b1476f6e6eb133afa41ed8589daba6dc69b4d3f5 #v6 + - uses: release-drafter/release-drafter@b1476f6e6eb133afa41ed8589daba6dc69b4d3f5 # v6.1.0 with: commitish: 'main' env: