diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 384a5dc..c54cd94 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,6 +3,8 @@ minimum_pre_commit_version: 3.3.0 default_install_hook_types: [pre-commit, commit-msg] default_stages: [commit] +exclude: '^tests/__snapshots__/' + repos: - repo: meta hooks: @@ -30,6 +32,8 @@ repos: rev: v1.11.2 hooks: - id: mypy + args: ['--config-file', 'pyproject.toml'] + exclude: 'tests/' - repo: https://github.com/asottile/pyupgrade rev: v3.17.0 @@ -66,18 +70,13 @@ repos: args: - --base64-limit=4 - --hex-limit=3 + exclude: 'tests/' - repo: https://github.com/lyz-code/yamlfix/ rev: 1.17.0 hooks: - id: yamlfix - - repo: https://github.com/espressif/cz-plugin-espressif - rev: v1.0.1 - hooks: - - id: update-changelog - files: ^pyproject\.toml$ - - repo: local hooks: - id: pip-compile diff --git a/CHANGELOG.md b/CHANGELOG.md index 5be43ec..54210ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,23 +1,33 @@ + + + + # CHANGELOG > All notable changes to this project are documented in this file. > This list is not exhaustive - only important changes, fixes, and new features in the code are reflected here. -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) - - ---- +
+ Static Badge + Static Badge + Static Badge +
+
## Unreleased ### ๐Ÿ› Bug fixes -- **changelog**: fix double title, header and footer on 'cz bump' *(Tomas Sebestik - f715e63)* +- **changelog**: fix double title, header and footer on 'cz bump' *(Tomas Sebestik - cce3c00)* ### ๐Ÿ“– Documentation - **docker-example**: add run_command.txt for running demo container *(Tomas Sebestik - 0fa8c2e)* +### ๐Ÿ”ง Code refactoring + +- **python-3.9**: refactor syntax and typing for python 3.9 *(Tomas Sebestik - 8de6c1d)* + --- ## v1.1.0 (2024-09-24) @@ -54,7 +64,14 @@ --- -**[Espressif Systems CO LTD. (2024)](https://www.espressif.com/)** - -- [Commitizen tools plugin with Espressif code style](https://www.github.com/espressif/cz-plugin-espressif) -- [Espressif Coding Standards and Best Practices](https://www.github.com/espressif/standards) +
+ + + Commitizen Espressif plugin + ยท + Espressif Standards + +
+ Espressif Systems CO LTD. (2024) +
+
diff --git a/Justfile b/Justfile index d7b80d5..132768b 100644 --- a/Justfile +++ b/Justfile @@ -14,27 +14,15 @@ gitstyle := '%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s # Helper function for quick menu [private] -default: - @just --list +@default: + just --list -# .Edit this Justfile -edit-just: +# ... Edit this Justfile +@edit-just: $EDITOR ./Justfile -# PROJECT: Install development environment -install: - pip uninstall -y czespressif commitizen - pip install --require-virtualenv -e '.[dev]' - pip install --require-virtualenv --upgrade pip - - -# PROJECT: Re-compile requirements.txt from dev-dependencies in pyproject.toml -lock-requirements: - pip-compile --strip-extras --output-file=requirements.txt pyproject.toml > /dev/null - - # PROJECT: Release version info and list of commits since last release @version: cz bump --dry-run | grep -E 'change\(bump\)|tag to create|increment detected'; \ @@ -42,9 +30,15 @@ lock-requirements: git log -n 30 --graph --pretty="{{gitstyle}}" v{{current_version}}..HEAD -# PROJECT: Run pre-commit linter(s)/formatter(s) on entire codebase -repo-pre-commit hook="": - pre-commit run {{hook}} --all-files +# PROJECT: Install development environment +@install: + pip install --require-virtualenv -e '.[dev,test]' + pip install --require-virtualenv --upgrade pip + + +# PROJECT: Re-compile requirements.txt from dev-dependencies in pyproject.toml +@lock-requirements: + pip-compile --strip-extras --output-file=requirements.txt pyproject.toml > /dev/null # PROJECT: Remove caches, builds, reports and other generated files @@ -57,26 +51,52 @@ repo-pre-commit hook="": .ruff_cache \ *.egg-info \ **/__pycache__/ \ - **/*.test.md \ build \ demo \ dist \ - output/* \ : -# GIT: Revert the last commit - keeping changes staged -uncommit: - git reset --soft HEAD~1 +# PROJECT: Build and check distribution package +@build: + just clean + python -m build + twine check dist/* + + +# PROJECT: +@bump-test: + clear + pre-commit run --all-files + cz bump --dry-run + + +# PYTEST: Run tests with coverage report +@test: + pytest + +# PYTEST: Updade snapshots (known results) for pytest +@update-snapshots: + pytest --snapshot-update + + +# DOCKER: Test Build Docker image for demo +@docker-test-buildx: + cd docker && docker buildx build --platform linux/arm64,linux/amd64 -t tomasad/czespressif-demo . && cd - -# GIT: Unstage files without modifying them -unstage: - git reset HEAD -- +# DOCKER: Build and push Docker image for demo +@docker-push-buildx: + cd docker && docker buildx build --platform linux/arm64,linux/amd64 -t tomasad/czespressif-demo --push . && cd - + + +# DOCKER: Run Docker image for demo +@docker-run directory=".": + pushd {{directory}} && docker run --rm -v $(pwd):/app -u $(id -u):$(id -g) tomasad/czespressif-demo && popd # GIT: Show commits only on current branch -branch-commits base="master": +@branch-commits base="master": @if git rev-parse --verify "{{base}}" > /dev/null 2>&1; then \ git log --first-parent --no-merges --graph --pretty="{{gitstyle}}" {{base}}..HEAD; \ else \ @@ -86,92 +106,48 @@ branch-commits base="master": # GIT: Try commit again, open failed commit message it in the editor for corrections -recommit: +@recommit: git commit --edit --file=$(git rev-parse --git-dir)/COMMIT_EDITMSG # GIT: Run interactive "git rebase" command -rebase base="master": +@rebase base="master": git fetch origin {{base}} git rebase -i origin/{{base}} -# PROJECT: Build and pip install -@build: - just clean - pip uninstall -y czespressif commitizen - python -m build - twine check dist/* - pip install -e . - cz example >> /dev/null - +# ---------------------------------------------- -# TEST: Test the output of `cz bump` command -@test-cz-bump: +@generate-cz-bump: clear cz bump --dry-run | tee "output/cz-bump.test.md" -# TEST: Test the output of `cz example` command -@test-cz-example: +@generate-cz-example: clear cz example | tee "output/cz-example.test.md" -# TEST: Test the output of `cz info` command -@test-cz-info: +@generate-cz-info: clear cz info | tee "output/cz-info.test.md" -# TEST: Test the output of `cz schema` command -@test-cz-schema: +@generate-cz-schema: clear cz schema | tee "output/cz-schema.test.md" -# TEST: Test the output of `cz changelog` command -@test-changelog: +@generate-changelog: clear cz changelog --dry-run | tee "output/CHANGELOG.test.md" -# TEST: Test the output of `cz changelog --incremental` command -@test-changelog-incremental: +@generate-changelog-incremental: clear cz changelog --incremental --dry-run | tee "output/CHANGELOG-incremental.test.md" -# TEST: Test the output of `cz changelog v1.0.0` command -@test-release-notes: +@generate-release-notes: clear - cz changelog v1.0.0 --template="RELEASE_NOTES.md.j2" --dry-run | tee "output/RELEASE_NOTES.test.md" - - -# TEST GROUP: Screen test to see the output, generate all files to 'output' directory -test: - just version - echo "Maximize terminal ...." && sleep 5; clear - just test-cz-bump && sleep 2; clear - just test-cz-info && sleep 2; clear - just test-cz-example && sleep 2; clear - just test-cz-schema && sleep 2; clear - just test-changelog && sleep 5; clear - just test-changelog-incremental && sleep 5; clear - just test-release-notes && sleep 5; clear - echo "Resize terminal, tests ends ...." && sleep 2; clear - - -# DOCKER: Build and push Docker image for demo -docker-buildx-test: - cd docker && docker buildx build --platform linux/arm64,linux/amd64 -t tomasad/czespressif-demo . && cd - - - -# DOCKER: Build and push Docker image for demo -docker-buildx-push: - cd docker && docker buildx build --platform linux/arm64,linux/amd64 -t tomasad/czespressif-demo --push . && cd - - - -# DOCKER: Run Docker image for demo -docker-run go_dir=".": - pushd {{go_dir}} && docker run --rm -v $(pwd):/app -u $(id -u):$(id -g) tomasad/czespressif-demo && popd + cz changelog v1.1.0 --template="RELEASE_NOTES.md.j2" --dry-run | tee "output/RELEASE_NOTES.test.md" diff --git a/czespressif/templates/CHANGELOG.md.j2 b/czespressif/templates/CHANGELOG.md.j2 index 5302c29..a5dd517 100644 --- a/czespressif/templates/CHANGELOG.md.j2 +++ b/czespressif/templates/CHANGELOG.md.j2 @@ -51,6 +51,7 @@ {# Render the footer only for full changelog, not for cz bump #} {% if config.changelog_footer and config.changelog_footer|length > 0 %}{# ---CHANGELOG FOOTER #} ---{# Add horizontal line before the footer, only if the footer is not empty #} + {% if not config.incremental %} {{ config.changelog_footer }}{# CHANGELOG FOOTER--- #} {% endif %} diff --git a/pyproject.toml b/pyproject.toml index ec70744..1e33332 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,14 +26,14 @@ dependencies = ["commitizen>=3.29.0"] [project.optional-dependencies] - dev = [ - "just-bin~=1.26.0", - "pip-tools~=7.3", + dev = ["just-bin~=1.26.0", "pip-tools~=7.3", "pre-commit~=3.3.0", "twine~=5.1.1"] + test = [ "pytest-cov~=4.1.0", + "pytest-mock~=3.14.0", + "pytest-sugar~=1.0.0", "pytest~=7.4.0", - "twine~=5.1.1", + "syrupy~=4.7.0", ] - test = ["pytest-cov~=4.1.0", "pytest~=7.4.0"] [project.entry-points."commitizen.plugin"] czespressif = "czespressif:CzPluginEspressif" @@ -61,9 +61,15 @@ skip = 'tests/*' [tool.ruff] - extend-exclude = ["tests/.*"] + extend-exclude = [] line-length = 160 + [tool.ruff.per-file-ignores] + "tests/*" = [ + "PLR0913", # PYLINT: Ignore Too many arguments in tests directory + "S101", # BANDIT: Ignore use of assert in tests directory + ] + [tool.ruff.format] quote-style = "single" @@ -75,7 +81,7 @@ lines-between-types = 1 [tool.mypy] - exclude = ["venv"] + exclude = ["^__init__.py$", "^build/.*", "^dist/.*", "^docs/.*", "^tests/.*"] ignore_missing_imports = true packages = "czespressif" pretty = true @@ -84,7 +90,7 @@ warn_return_any = true [tool.pytest.ini_options] - addopts = "-s --log-cli-level DEBUG --cov=sample_python_app --cov-report=term" + addopts = "--log-cli-level DEBUG --cov=czespressif --cov-report=term" [tool.coverage.run] omit = ["*/tests/*", "__*__.py"] diff --git a/tests/__snapshots__/test_czespressif/test_changelog[False].md b/tests/__snapshots__/test_czespressif/test_changelog[False].md new file mode 100644 index 0000000..18443cb --- /dev/null +++ b/tests/__snapshots__/test_czespressif/test_changelog[False].md @@ -0,0 +1,45 @@ + + + + +# CHANGELOG + +> All notable changes to this project are documented in this file. +> This list is not exhaustive - only important changes, fixes, and new features in the code are reflected here. + +
+ Static Badge + Static Badge + Static Badge +
+
+ +## v1.2.0 (2019-04-19) + +### โœจ New features + +- custom cz plugins now support bump version *(Commitizen - ddd220a)* + +### ๐Ÿ“– Documentation + +- how to create custom bumps *(Commitizen - 6c49485)* +- added bump gif *(Commitizen - ad17acf)* + +--- + +## v1.1.1 (2019-04-18) + +--- + +
+ + + Commitizen Espressif plugin + ยท + Espressif Standards + +
+ Espressif Systems CO LTD. (2024) +
+
+ diff --git a/tests/__snapshots__/test_czespressif/test_changelog[True].md b/tests/__snapshots__/test_czespressif/test_changelog[True].md new file mode 100644 index 0000000..868a3cb --- /dev/null +++ b/tests/__snapshots__/test_czespressif/test_changelog[True].md @@ -0,0 +1,41 @@ + + + + +# CHANGELOG + +> All notable changes to this project are documented in this file. +> This list is not exhaustive - only important changes, fixes, and new features in the code are reflected here. + +
+ Static Badge + Static Badge + Static Badge +
+
+ +## v1.2.0 (2019-04-19) + +### โœจ New features + +- custom cz plugins now support bump version *(Commitizen - ddd220a)* + +### ๐Ÿ“– Documentation + +- how to create custom bumps *(Commitizen - 6c49485)* +- added bump gif *(Commitizen - ad17acf)* + +--- + +
+ + + Commitizen Espressif plugin + ยท + Espressif Standards + +
+ Espressif Systems CO LTD. (2024) +
+
+ diff --git a/tests/test_czespressif.py b/tests/test_czespressif.py index e69de29..a04afa0 100644 --- a/tests/test_czespressif.py +++ b/tests/test_czespressif.py @@ -0,0 +1,109 @@ +from __future__ import annotations + +import pytest + +from commitizen.changelog import Metadata +from commitizen.commands.changelog import Changelog +from commitizen.config import BaseConfig +from commitizen.exceptions import DryRunExit +from commitizen.git import GitCommit +from commitizen.git import GitTag +from syrupy.extensions.single_file import SingleFileSnapshotExtension +from syrupy.extensions.single_file import WriteMode + + +# Using Syrupy to compare markdown snapshots +class MarkdownSnapshotExtension(SingleFileSnapshotExtension): + _file_extension = 'md' + _write_mode = WriteMode.TEXT + + +@pytest.fixture +def snapshot(snapshot): + return snapshot.use_extension(MarkdownSnapshotExtension) + + +COMMITS_DATA = [ + { + 'rev': '141ee441c9c9da0809c554103a558eb17c30ed17', + 'title': 'bump: version 1.1.1 โ†’ 1.2.0', + 'body': '', + 'author': 'Commitizen', + 'author_email': 'author@cz.dev', + }, + { + 'rev': '6c4948501031b7d6405b54b21d3d635827f9421b', + 'title': 'docs: how to create custom bumps', + 'body': '', + 'author': 'Commitizen', + 'author_email': 'author@cz.dev', + }, + { + 'rev': 'ddd220ad515502200fe2dde443614c1075d26238', + 'title': 'feat: custom cz plugins now support bump version', + 'body': '', + 'author': 'Commitizen', + 'author_email': 'author@cz.dev', + }, + { + 'rev': 'ad17acff2e3a2e141cbc3c6efd7705e4e6de9bfc', + 'title': 'docs: added bump gif', + 'body': '', + 'author': 'Commitizen', + 'author_email': 'author@cz.dev', + }, + { + 'rev': '56c8a8da84e42b526bcbe130bd194306f7c7e813', + 'title': 'bump: version 1.1.0 โ†’ 1.1.1', + 'body': '', + 'author': 'Commitizen', + 'author_email': 'author@cz.dev', + }, +] + +TAGS_DATA = [ + ('v1.2.0', '141ee441c9c9da0809c554103a558eb17c30ed17', '2019-04-19'), + ('v1.1.1', '56c8a8da84e42b526bcbe130bd194306f7c7e813', '2019-04-18'), + ('v1.1.0', '17efb44d2cd16f6621413691a543e467c7d2dda6', '2019-04-14'), +] + + +@pytest.fixture +def gitcommits() -> list[GitCommit]: + return [GitCommit(**commit) for commit in COMMITS_DATA] + + +@pytest.fixture +def tags() -> list[GitTag]: + return [GitTag(*tag) for tag in TAGS_DATA] + + +def render_changelog(config, gitcommits, tags, capsys, mocker, incremental: bool) -> str: + mocker.patch('commitizen.git.get_commits', return_value=gitcommits[:4] if incremental else gitcommits) + mocker.patch('commitizen.git.get_tags', return_value=tags) + + kwargs = {'dry_run': True, 'incremental': incremental, 'unreleased_version': True} + cmd = Changelog(config, kwargs) + + mocker.patch.object(cmd.changelog_format, 'get_metadata').return_value = Metadata(latest_version='1.1.1') + capsys.readouterr() + + try: + cmd() + except DryRunExit: + pass + + return capsys.readouterr().out + + +@pytest.mark.parametrize('incremental', [False, True]) +def test_changelog(snapshot, incremental, mocker, gitcommits, tags, capsys): + # Create config for changelog + config = BaseConfig() + config.settings.update({'name': 'czespressif'}) + + # Render the changelog using the provided fixture + changelog = render_changelog(config, gitcommits, tags, capsys, mocker, incremental) + + # Compare the output with the markdown snapshot (Syrupy automatically handles snapshot naming) + assert changelog == snapshot