feat(changelog): Add changelog.output_dir configuration option#1406
Open
bilelomrani1 wants to merge 4 commits intopython-semantic-release:masterfrom
Open
feat(changelog): Add changelog.output_dir configuration option#1406bilelomrani1 wants to merge 4 commits intopython-semantic-release:masterfrom
changelog.output_dir configuration option#1406bilelomrani1 wants to merge 4 commits intopython-semantic-release:masterfrom
Conversation
6 tasks
13cba46 to
c23985e
Compare
changelog.output_dir configuration optionchangelog.output_dir configuration option
Author
|
Just a note: this adds a It's a small, self-contained feature that shouldn't conflict with the v11 refactoring. See #1407 for the broader context on my use case. No rush on the review. |
c23985e to
9387cab
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Purpose
This PR adds a new
changelog.output_dirconfiguration option that allows users to specify the destination directory for changelog output.This feature is particularly valuable for monorepo setups where PSR runs from a package subdirectory but needs to write changelogs to a consolidated documentation directory, and also when users use shared remote templates (see #1404) across multiple projects but still want fine grained control over where the changelog is written.
Rationale
In monorepo environments, users often want to:
packages/pkg1/)docs/source/pkg1/changelog.md)Before this PR, achieving this required complex shell scripts to copy/move changelog files. The previous monorepo documentation reflected this complexity, requiring users to understand intricate template customization just to place changelogs in a different directory.
The new
output_diroption provides a simple way to specify the changelog destination:This single line replaces what previously required custom templates and shell scripts. The Advanced Example in the monorepo documentation has been completely rewritten to use
output_dir, reducing complexity significantly while enabling the same (and more) functionality.Bug Fix: Custom Templates Now Render to CWD
This PR also fixes an inconsistency when using custom template directories from a subdirectory.
Before:
After:
The old behavior was inconsistent: when running from a subdirectory (e.g.,
packages/pkg1/),template_dirwas resolved relative to CWD, butdestination_dirwas always hardcoded to the repository root. This caused templates to be read from the subdirectory but output to be written to the repo root.With this fix, both template reading and output writing are consistent: relative to CWD when
output_dir="."(default), or to the explicitly configuredoutput_dir. I'm expecting this to be related to #845, and could potentially fix it.How did you test?
Unit Tests (
tests/unit/semantic_release/cli/test_config.py)test_output_dir_default_resolves_to_repo_root- Default behaviortest_output_dir_inside_repo_accepted- Valid paths acceptedtest_output_dir_outside_repo_rejected- Security: paths outside repo rejectedtest_output_dir_with_parent_traversal_rejected- Security: path traversal blockedtest_output_dir_and_changelog_file_with_dir_rejected- Ambiguous config rejectedtest_output_dir_with_bare_changelog_filename_from_subdirectory_accepted- Monorepo scenario worksEnd-to-End Tests (
tests/e2e/cmd_changelog/test_changelog.py)test_changelog_generated_in_output_dir- Changelog written to specified directorytest_changelog_update_mode_reads_from_output_dir- Update mode reads existing changelog from correct locationtest_changelog_file_with_directory_component_backward_compatibility- Existingchangelog_filewith directory component still worksBackward Compatibility
changelog_file = "docs/CHANGELOG.md"(directory component) continue to work unchangedoutput_diris explicitly set alongside achangelog_filewith directory componentHow to Verify
Basic usage: Set
output_dirin config and runsemantic-release changelogVerify changelog is written to
docs/CHANGELOG.mdMonorepo scenario: From a package subdirectory with:
Run
semantic-release changelogand verify output locationUpdate mode: Create an existing changelog in
output_dir, run withmode = "update", verify it reads and updates the correct fileBackward compatibility: Existing config with
changelog_file = "docs/CHANGELOG.md"(nooutput_dir) should continue workingPR Completion Checklist
Reviewed & followed the Contributor Guidelines
Changes Implemented & Validation pipeline succeeds
Commits follow the Conventional Commits standard
and are separated into the proper commit type and scope (recommended order: test, build, feat/fix, docs)
Appropriate Unit tests added/updated
Appropriate End-to-End tests added/updated
Appropriate Documentation added/updated and syntax validated for sphinx build (see Contributor Guidelines)