-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds the '--add-all' option to the 'publish' command to include all changed files in the release commit. Signed-off-by: Eva Millán <[email protected]>
- Loading branch information
Showing
4 changed files
with
73 additions
and
15 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,9 @@ | |
help="Do not remove changelog entries from the repository.") | ||
@click.option('--remote-branch', 'remote_branch', default="master", | ||
help="Remote branch to push. Default 'master'.") | ||
def publish(version, author, remote, only_push, no_cleanup, remote_branch): | ||
@click.option('--add-all', is_flag=True, | ||
help="Add all changed files to the release commit.") | ||
def publish(version, author, remote, only_push, no_cleanup, remote_branch, add_all): | ||
"""Publish a new release. | ||
This script will generate a new release in the repository. | ||
|
@@ -71,6 +73,10 @@ def publish(version, author, remote, only_push, no_cleanup, remote_branch): | |
When '--no-cleanup' argument is specified, do not remove changelog | ||
entries. | ||
By default, the release commit will include the version, pyproject, | ||
release notes, news and authors files. To add all changed files to | ||
the release commit use the `--add-all` flag. | ||
VERSION: version of the new release. | ||
AUTHOR: author of the new release (e.g. John Smith <[email protected]>) | ||
|
@@ -88,7 +94,7 @@ def publish(version, author, remote, only_push, no_cleanup, remote_branch): | |
if not only_push: | ||
if not no_cleanup: | ||
remove_unreleased_changelog_entries(project) | ||
add_release_files(project, version) | ||
add_release_files(project, version, add_all) | ||
commit(project, version, author) | ||
|
||
if remote: | ||
|
@@ -126,28 +132,31 @@ def rollback_add_release_files(project): | |
pass | ||
|
||
|
||
def add_release_files(project, version): | ||
def add_release_files(project, version, add_all): | ||
"""Add to the repository all the files needed to publish a release.""" | ||
|
||
click.echo("Adding files to the release commit...", nl=False) | ||
|
||
# Add version file | ||
version_file = project.version_file | ||
if add_all: | ||
project.repo.add_all() | ||
else: | ||
# Add version file | ||
version_file = project.version_file | ||
|
||
if not version_file: | ||
rollback_add_release_files(project) | ||
raise click.ClickException("version file not found") | ||
if not version_file: | ||
rollback_add_release_files(project) | ||
raise click.ClickException("version file not found") | ||
|
||
project.repo.add(version_file) | ||
project.repo.add(version_file) | ||
|
||
# Add pyproject.toml file | ||
pyproject_file = project.pyproject_file | ||
# Add pyproject.toml file | ||
pyproject_file = project.pyproject_file | ||
|
||
if not pyproject_file: | ||
rollback_add_release_files(project) | ||
raise click.ClickException("pyproject file not found") | ||
if not pyproject_file: | ||
rollback_add_release_files(project) | ||
raise click.ClickException("pyproject file not found") | ||
|
||
project.repo.add(pyproject_file) | ||
project.repo.add(pyproject_file) | ||
|
||
# Add release notes file | ||
notes_file = os.path.join(project.releases_path, version + '.md') | ||
|
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
11 changes: 11 additions & 0 deletions
11
releases/unreleased/option-to-add-all-files-to-release-commit.yml
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,11 @@ | ||
--- | ||
title: Option to add all files to release commit | ||
category: added | ||
author: Eva Millán <[email protected]> | ||
issue: null | ||
notes: > | ||
To include all changed files in the release commit, | ||
add the `--add-all` flag to the `publish` command. | ||
This is useful for non-Python projects that may | ||
need to change the version number in files other | ||
than '_version.py'. |
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 |
---|---|---|
|
@@ -706,6 +706,40 @@ def test_publish_different_branch(self, mock_project): | |
mock_project.return_value.repo.push.assert_any_call('myremote', 'main') | ||
mock_project.return_value.repo.push.assert_any_call('myremote', '0.8.10') | ||
|
||
@unittest.mock.patch('release_tools.publish.read_changelog_entries') | ||
@unittest.mock.patch('release_tools.publish.Project') | ||
def test_add_all(self, mock_project, mock_read_changelog): | ||
"""Test if '--add-all' adds all files to the release commit.""" | ||
version_number = "0.8.10" | ||
|
||
runner = click.testing.CliRunner() | ||
|
||
with runner.isolated_filesystem() as fs: | ||
os.path.join(fs, 'package.json') | ||
os.path.join(fs, 'Dockerfile') | ||
notes_file = os.path.join(fs, version_number + '.md') | ||
news_file = os.path.join(fs, 'NEWS') | ||
authors_file = os.path.join(fs, 'AUTHORS') | ||
|
||
self.setup_release_notes(fs, notes_file, newsfile=news_file, authorsfile=authors_file) | ||
|
||
mock_project.return_value.unreleased_processed_entries_path = fs | ||
mock_project.return_value.releases_path = fs | ||
mock_project.return_value.news_file = news_file | ||
mock_project.return_value.authors_file = authors_file | ||
|
||
# Run the command | ||
result = runner.invoke(publish.publish, | ||
[version_number, "John Smith <[email protected]>", | ||
"--add-all"]) | ||
self.assertEqual(result.exit_code, 0) | ||
|
||
# Check mock calls | ||
mock_project.return_value.repo.add_all.assert_called() | ||
mock_project.return_value.repo.add.assert_any_call(notes_file) | ||
mock_project.return_value.repo.add.assert_any_call(news_file) | ||
mock_project.return_value.repo.add.assert_any_call(authors_file) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |