- Notifications
You must be signed in to change notification settings - Fork261
fix(version): increaseversion_variable flexibility w/ quotes (ie. json, yaml, etc)#1028
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
codejedi365 merged 6 commits intopython-semantic-release:masterfromcodejedi365:fix/version-variable-quote-flexibilitySep 27, 2024
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
6 commits Select commitHold shift + click to select a range
9f2ef35 fix(version): increase `version_variable` flexibility with quotations…
codejedi365fcee573 docs(configuration): add clarity to `version_variables` usage & limit…
codejedi365a6eb868 fix(version-cmd): ensure `version_variables` do not match partial var…
codejedi36520993c2 build(deps-test): add `PyYAML` as a test dependency
codejedi365ed2d272 test(fixtures): refactor location of fixture for global use of cli ru…
codejedi365b339b6d test(stamp-version): add test cases to stamp json, python, & yaml files
codejedi365File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
29 changes: 29 additions & 0 deletionsdocs/configuration.rst
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
5 changes: 3 additions & 2 deletionspyproject.toml
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
13 changes: 12 additions & 1 deletionsemantic_release/cli/config.py
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
6 changes: 0 additions & 6 deletionstests/command_line/conftest.py
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
6 changes: 6 additions & 0 deletionstests/conftest.py
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
219 changes: 219 additions & 0 deletionstests/scenario/test_version_stamp.py
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,219 @@ | ||
| from __future__ import annotations | ||
| import importlib.util | ||
| import json | ||
| from pathlib import Path | ||
| from textwrap import dedent | ||
| from typing import TYPE_CHECKING | ||
| import pytest | ||
| import yaml | ||
| from semantic_release.cli.commands.main import main | ||
| from tests.const import MAIN_PROG_NAME, VERSION_SUBCMD | ||
| from tests.fixtures.repos.trunk_based_dev.repo_w_no_tags import ( | ||
| repo_with_no_tags_angular_commits, | ||
| ) | ||
| from tests.util import assert_successful_exit_code | ||
| if TYPE_CHECKING: | ||
| from click.testing import CliRunner | ||
| from tests.fixtures.example_project import UpdatePyprojectTomlFn | ||
| @pytest.mark.usefixtures(repo_with_no_tags_angular_commits.__name__) | ||
| def test_stamp_version_variables_python( | ||
| cli_runner: CliRunner, | ||
| update_pyproject_toml: UpdatePyprojectTomlFn, | ||
| ) -> None: | ||
| new_version = "0.1.0" | ||
| target_file = Path("src/example/_version.py") | ||
| # Set configuration to modify the python file | ||
| update_pyproject_toml( | ||
| "tool.semantic_release.version_variables", [f"{target_file}:__version__"] | ||
| ) | ||
| # Use the version command and prevent any action besides stamping the version | ||
| cli_cmd = [ | ||
| MAIN_PROG_NAME, | ||
| VERSION_SUBCMD, | ||
| "--no-changelog", | ||
| "--no-commit", | ||
| "--no-tag", | ||
| ] | ||
| # Act | ||
| result = cli_runner.invoke(main, cli_cmd[1:]) | ||
| # Check the result | ||
| assert_successful_exit_code(result, cli_cmd) | ||
| # Load python module for reading the version (ensures the file is valid) | ||
| spec = importlib.util.spec_from_file_location("example._version", str(target_file)) | ||
| module = importlib.util.module_from_spec(spec) # type: ignore | ||
| spec.loader.exec_module(module) # type: ignore | ||
| # Check the version was updated | ||
| assert new_version == module.__version__ | ||
| @pytest.mark.usefixtures(repo_with_no_tags_angular_commits.__name__) | ||
| def test_stamp_version_variables_yaml( | ||
| cli_runner: CliRunner, | ||
| update_pyproject_toml: UpdatePyprojectTomlFn, | ||
| ) -> None: | ||
| orig_version = "0.0.0" | ||
| new_version = "0.1.0" | ||
| target_file = Path("example.yml") | ||
| orig_yaml = dedent( | ||
| f"""\ | ||
| --- | ||
| package: example | ||
| version: {orig_version} | ||
| date-released: 1970-01-01 | ||
| """ | ||
| ) | ||
| # Write initial text in file | ||
| target_file.write_text(orig_yaml) | ||
| # Set configuration to modify the yaml file | ||
| update_pyproject_toml( | ||
| "tool.semantic_release.version_variables", [f"{target_file}:version"] | ||
| ) | ||
| # Use the version command and prevent any action besides stamping the version | ||
| cli_cmd = [ | ||
| MAIN_PROG_NAME, | ||
| VERSION_SUBCMD, | ||
| "--no-changelog", | ||
| "--no-commit", | ||
| "--no-tag", | ||
| ] | ||
| # Act | ||
| result = cli_runner.invoke(main, cli_cmd[1:]) | ||
| # Check the result | ||
| assert_successful_exit_code(result, cli_cmd) | ||
| # Read content | ||
| resulting_yaml_obj = yaml.safe_load(target_file.read_text()) | ||
| # Check the version was updated | ||
| assert new_version == resulting_yaml_obj["version"] | ||
| # Check the rest of the content is the same (by reseting the version & comparing) | ||
| resulting_yaml_obj["version"] = orig_version | ||
| assert yaml.safe_load(orig_yaml) == resulting_yaml_obj | ||
| @pytest.mark.usefixtures(repo_with_no_tags_angular_commits.__name__) | ||
| def test_stamp_version_variables_yaml_cff( | ||
| cli_runner: CliRunner, | ||
| update_pyproject_toml: UpdatePyprojectTomlFn, | ||
| ) -> None: | ||
| orig_version = "0.0.0" | ||
| new_version = "0.1.0" | ||
| target_file = Path("CITATION.cff") | ||
| # Derived format from python-semantic-release/python-semantic-release#962 | ||
| orig_yaml = dedent( | ||
| f"""\ | ||
| --- | ||
| cff-version: 1.2.0 | ||
| message: "If you use this software, please cite it as below." | ||
| authors: | ||
| - family-names: Doe | ||
| given-names: Jon | ||
| orcid: https://orcid.org/1234-6666-2222-5555 | ||
| title: "My Research Software" | ||
| version: {orig_version} | ||
| date-released: 1970-01-01 | ||
| """ | ||
| ) | ||
| # Write initial text in file | ||
| target_file.write_text(orig_yaml) | ||
| # Set configuration to modify the yaml file | ||
| update_pyproject_toml( | ||
| "tool.semantic_release.version_variables", [f"{target_file}:version"] | ||
| ) | ||
| # Use the version command and prevent any action besides stamping the version | ||
| cli_cmd = [ | ||
| MAIN_PROG_NAME, | ||
| VERSION_SUBCMD, | ||
| "--no-changelog", | ||
| "--no-commit", | ||
| "--no-tag", | ||
| ] | ||
| # Act | ||
| result = cli_runner.invoke(main, cli_cmd[1:]) | ||
| # Check the result | ||
| assert_successful_exit_code(result, cli_cmd) | ||
| # Read content | ||
| resulting_yaml_obj = yaml.safe_load(target_file.read_text()) | ||
| # Check the version was updated | ||
| assert new_version == resulting_yaml_obj["version"] | ||
| # Check the rest of the content is the same (by reseting the version & comparing) | ||
| resulting_yaml_obj["version"] = orig_version | ||
| assert yaml.safe_load(orig_yaml) == resulting_yaml_obj | ||
| @pytest.mark.usefixtures(repo_with_no_tags_angular_commits.__name__) | ||
| def test_stamp_version_variables_json( | ||
| cli_runner: CliRunner, | ||
| update_pyproject_toml: UpdatePyprojectTomlFn, | ||
| ) -> None: | ||
| orig_version = "0.0.0" | ||
| new_version = "0.1.0" | ||
| target_file = Path("plugins.json") | ||
| orig_json = { | ||
| "id": "test-plugin", | ||
| "version": orig_version, | ||
| "meta": { | ||
| "description": "Test plugin", | ||
| }, | ||
| } | ||
| # Write initial text in file | ||
| target_file.write_text(json.dumps(orig_json, indent=4)) | ||
| # Set configuration to modify the json file | ||
| update_pyproject_toml( | ||
| "tool.semantic_release.version_variables", [f"{target_file}:version"] | ||
| ) | ||
| # Use the version command and prevent any action besides stamping the version | ||
| cli_cmd = [ | ||
| MAIN_PROG_NAME, | ||
| VERSION_SUBCMD, | ||
| "--no-changelog", | ||
| "--no-commit", | ||
| "--no-tag", | ||
| ] | ||
| # Act | ||
| result = cli_runner.invoke(main, cli_cmd[1:]) | ||
| # Check the result | ||
| assert_successful_exit_code(result, cli_cmd) | ||
| # Read content | ||
| resulting_json_obj = json.loads(target_file.read_text()) | ||
| # Check the version was updated | ||
| assert new_version == resulting_json_obj["version"] | ||
| # Check the rest of the content is the same (by reseting the version & comparing) | ||
| resulting_json_obj["version"] = orig_version | ||
| assert orig_json == resulting_json_obj |
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.