Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
# Configuration for Release Drafter: https://github.com/toolmantim/release-drafter
_extends: .github

# Override the template to include default tool versions
template: |
<!-- Optional: add a release summary here -->

## Default Tool 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
40 changes: 39 additions & 1 deletion .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
23 changes: 23 additions & 0 deletions scripts/get_default_versions.py
Original file line number Diff line number Diff line change
@@ -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()
29 changes: 29 additions & 0 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
Loading