def test_empty_unreleased_release(empty_unreleased_changelog): with pytest.raises(Exception) as exception_info: keepachangelog.release(empty_unreleased_changelog) assert ( str(exception_info.value) == "Release content must be provided within changelog Unreleased section." )
def test_non_semantic_release(non_semantic_changelog): with pytest.raises(Exception) as exception_info: keepachangelog.release(non_semantic_changelog) assert ( str(exception_info.value) == "20180531 is not following semantic versioning. Check https://semver.org for more information." )
def test_first_minor_release(first_minor_changelog, mock_date): assert keepachangelog.release(first_minor_changelog) == "0.1.0" with open(first_minor_changelog) as file: assert (file.read() == """# Changelog All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] ## [0.1.0] - 2021-03-19 ### Added - Enhancement 1 - sub enhancement 1 * sub enhancement 2 - Enhancement 2 ### Fixed - Bug fix 1 - sub bug 1 * sub bug 2 - Bug fix 2 ### Security * Known issue 1 - Known issue 2 ### Deprecated - Deprecated feature 1 * Future removal 2 [Unreleased]: https://github.test_url/test_project [0.1.0]: https://github.test_url/test_project """)
def bump_version(): if os.getenv('PLUGIN_SKIP_COMMIT_AUTHOR') == os.getenv( "DRONE_COMMIT_AUTHOR"): print( f"Skipping version bump as commit author ({os.getenv('DRONE_COMMIT_AUTHOR')}) is {os.getenv('PLUGIN_SKIP_COMMIT_AUTHOR')}." ) return changelog_path = os.getenv('PLUGIN_CHANGELOG_PATH', "CHANGELOG.md") # Compute the new version number and update CHANGELOG new_version = keepachangelog.release(changelog_path) if not new_version: print(f"Skipping version bump as there is nothing to release.") return files_to_commit = [changelog_path] # Update version in source code version_file_path = os.getenv('PLUGIN_VERSION_FILE_PATH') if version_file_path: update_version_in_file(version_file_path, new_version) files_to_commit.append(version_file_path) github = GitHub() github.commit_and_push( user_name=os.getenv('PLUGIN_USER_NAME', os.getenv("DRONE_COMMIT_AUTHOR_NAME")), user_email=os.getenv('PLUGIN_USER_EMAIL', os.getenv("DRONE_COMMIT_AUTHOR_EMAIL")), branch=os.getenv("DRONE_TARGET_BRANCH"), message=f"Release {new_version}", file_paths=files_to_commit)
def test_minor_release(minor_changelog, mock_date): assert keepachangelog.release(minor_changelog) == "1.2.0" with open(minor_changelog) as file: assert (file.read() == """# Changelog All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] ## [1.2.0] - 2021-03-19 ### Added - Enhancement 1 - sub enhancement 1 * sub enhancement 2 - Enhancement 2 ### Fixed - Bug fix 1 - sub bug 1 * sub bug 2 - Bug fix 2 ### Security * Known issue 1 - Known issue 2 ### Deprecated - Deprecated feature 1 * Future removal 2 ## [1.1.0] - 2018-05-31 ### Changed - Enhancement 1 (1.1.0) - sub *enhancement 1* - sub enhancement 2 - Enhancement 2 (1.1.0) ## [1.0.1] - 2018-05-31 ### Fixed - Bug fix 1 (1.0.1) - sub bug 1 - sub bug 2 - Bug fix 2 (1.0.1) ## [1.0.0] - 2017-04-10 ### Deprecated - Known issue 1 (1.0.0) - Known issue 2 (1.0.0) [Unreleased]: https://github.test_url/test_project/compare/v1.2.0...HEAD [1.2.0]: https://github.test_url/test_project/compare/v1.1.0...v1.2.0 [1.1.0]: https://github.test_url/test_project/compare/v1.0.1...v1.1.0 [1.0.1]: https://github.test_url/test_project/compare/v1.0.0...v1.0.1 [1.0.0]: https://github.test_url/test_project/releases/tag/v1.0.0 """)
def test_first_patch_release(first_patch_changelog, mock_date): assert keepachangelog.release(first_patch_changelog) == "0.0.1" with open(first_patch_changelog) as file: assert (file.read() == """# Changelog All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] ## [0.0.1] - 2021-03-19 ### Fixed - Bug fix 1 - sub bug 1 * sub bug 2 - Bug fix 2 [Unreleased]: https://github.test_url/test_project [0.0.1]: https://github.test_url/test_project """)
def test_first_stable_release(unstable_changelog, mock_date): assert keepachangelog.release(unstable_changelog) == "2.5.0" with open(unstable_changelog) as file: assert (file.read() == """# Changelog All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] ## [2.5.0] - 2021-03-19 ### Changed - Enhancement 1 (1.1.0) ## [2.5.0b51] - 2018-05-31 ### Changed - Enhancement 1 (1.1.0) - sub *enhancement 1* - sub enhancement 2 - Enhancement 2 (1.1.0) """)
def test_patch_digit_release(patch_digit_changelog, mock_date): assert keepachangelog.release(patch_digit_changelog) == "9.9.11" with open(patch_digit_changelog) as file: assert (file.read() == """# Changelog All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] ## [9.9.11] - 2021-03-19 ### Fixed - Enhancement ## [9.9.10] - 2018-05-31 ### Fixed - Enhancement ## [9.9.9] - 2018-05-31 ### Fixed - Enhancement """)
def test_empty_unreleased_release(empty_unreleased_changelog): assert not keepachangelog.release(empty_unreleased_changelog)
def test_non_semantic_release(non_semantic_changelog): with pytest.raises(Exception) as exception_info: keepachangelog.release(non_semantic_changelog) assert str(exception_info.value ) == "20180531 is not following semantic versioning."