Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 12, 2025

Purpose

Rationale

Users with simple version files (containing only 1.2.3 or v1.2.3) must currently define regex patterns matching variable assignments. For files with no structure—just the version string—this is unnecessarily complex. The * pattern triggers full file replacement: read, strip whitespace, write new version.

Implementation

New FileVersionDeclaration class implementing IVersionReplacer:

  • Replaces entire file content with version string
  • Strips input whitespace, writes clean output
  • Supports nf (number) and tf (tag) formats

Config parsing (cli/config.py):

  • Detects * in pattern position
  • Routes to FileVersionDeclaration instead of PatternVersionDeclaration
  • Zero breaking changes to existing pattern-based configs

Usage

[tool.semantic_release]
tag_format = "v{version}"
version_variables = [
    "src/__init__.py:__version__",  # Pattern-based (existing)
    "VERSION:*:nf",                  # File replacement (new) → "1.2.3"
    "VERSION_TAG:*:tf",              # File replacement (new) → "v1.2.3"
]

How did you test?

Unit tests (16): Valid/invalid definitions, format types, file operations, error cases, noop behavior
E2E tests (3): Number format, tag format, whitespace handling
Manual verification: Created test repo, configured both patterns, confirmed VERSION files updated correctly

How to Verify

  1. Create VERSION file with 0.1.0
  2. Add to config: version_variables = ["VERSION:*:nf"]
  3. Run semantic-release version --minor --no-commit --no-tag
  4. Verify VERSION contains 0.2.0 (no whitespace, no prefix)

PR 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)

Original prompt

please create an implementation to add this feature to PSR. You should add the appropriate tests and update the documentation accordingly. You will need to create a separate declaration for entire file replacement. The mechanism to trigger this variant of version variables will be an asterisk (*) in the place of the pattern spec. For example, to update the numeric version in the file src/VERSION then the configuration should be src/VERSION:*:nf. To set the tag version you would change the nf to tf but maintain the rest. This will resolve #1375.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Add feature for variant version variables in PSR feat(version): add file replacement variant for version_variables Dec 12, 2025
Copilot AI requested a review from codejedi365 December 12, 2025 08:31
@codejedi365 codejedi365 force-pushed the copilot/add-variant-version-variables branch from 1b83911 to 5fe054a Compare December 14, 2025 02:34
@codejedi365 codejedi365 marked this pull request as ready for review December 14, 2025 02:37
codejedi365 and others added 4 commits December 14, 2025 14:50
Add support for entire file replacement when pattern is specified as `*`.
This allows users to configure version stamping for files that contain
only a version number (e.g., VERSION files).

Configuration examples:
- `src/VERSION:*:nf` - Replace entire file with numeric version
- `src/VERSION:*:tf` - Replace entire file with tag version

Implements: #1375

Co-authored-by: codejedi365 <17354856+codejedi365@users.noreply.github.com>
@codejedi365 codejedi365 force-pushed the copilot/add-variant-version-variables branch from 5fe054a to ae1ebf5 Compare December 14, 2025 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow updates to version file containing only a version

2 participants