-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: include additional changes in release commits
Add new config keys, `pre_commit_command` and `commit_additional_files`, to allow custom file changes alongside the release commits.
- Loading branch information
1 parent
09af5f1
commit 3e34f95
Showing
8 changed files
with
289 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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,20 @@ | ||
"""Run commands prior to the release commit | ||
""" | ||
import logging | ||
|
||
from invoke import run | ||
|
||
from .settings import config | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def should_run_pre_commit(): | ||
command = config.get("pre_commit_command") | ||
return bool(command) | ||
|
||
|
||
def run_pre_commit(): | ||
command = config.get("pre_commit_command") | ||
logger.debug(f"Running {command}") | ||
run(command) |
This file contains 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
This file contains 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
This file contains 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,46 @@ | ||
from semantic_release.pre_commit import run_pre_commit, should_run_pre_commit | ||
|
||
import pytest | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"commands", | ||
["make do-stuff", "echo hello > somefile.txt"], | ||
) | ||
def test_pre_commit_command(mocker, commands): | ||
mocker.patch("semantic_release.pre_commit.config.get", lambda *a: commands) | ||
mock_run = mocker.patch("semantic_release.pre_commit.run") | ||
run_pre_commit() | ||
mock_run.assert_called_once_with(commands) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"config,expected", | ||
[ | ||
( | ||
{ | ||
"pre_commit_command": "make generate_some_file", | ||
}, | ||
True, | ||
), | ||
( | ||
{ | ||
"pre_commit_command": "cmd", | ||
}, | ||
True, | ||
), | ||
( | ||
{ | ||
"pre_commit_command": "", | ||
}, | ||
False, | ||
), | ||
( | ||
{}, | ||
False, | ||
), | ||
], | ||
) | ||
def test_should_run_pre_commit_command(config, expected, mocker): | ||
mocker.patch("semantic_release.cli.config.get", lambda key: config.get(key)) | ||
assert should_run_pre_commit() == expected |
This file contains 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