Skip to content

Repository files navigation

Project:License

Package:PyPI - Python VersionPyPI - VersionPyPI - Downloads

Development:uvrufftypytestCICode CoverageGitHub commit activity

Contents

Overview

AutoGitSemVer uses commits in a git repository to calculate a semantic version. A commit's title and/or description can be used to increment a specific part of the semantic version and configuration files can be applied to control how the semantic version is generated. Finally, multiple, distinct semantic versions can be generated from different directories within the source tree.

How to use AutoGitSemVer

Running the Executable

From a terminal window, run:

ScenarioCommand LineOutput
Standardautogitsemver
Loading AutoGitSemVer configuration...DONE! (0, 0:00:00.001464, default configuration info will be used)
Enumerating changes...DONE! (0, 0:00:00.193258, 1 change processed, no changes applied [0.00%])
Calculating semantic version...
0.6.1+20240318122529.BROWNELL08
DONE! (0, 0:00:00.054236)
Results: DONE! (0, 0:00:00.267488)
Without Metadataautogitsemver --no-metadata
Loading AutoGitSemVer configuration...DONE! (0, 0:00:00.001468, default configuration info will be used)
Enumerating changes...DONE! (0, 0:00:00.201744, 1 change processed, no changes applied [0.00%])
Calculating semantic version...
0.6.1
DONE! (0, 0:00:00.060190)
Results: DONE! (0, 0:00:00.281524)
Quietautogitsemver --quiet
0.6.1+20240318122751.BROWNELL08
Verboseautogitsemver --verbose
Loading AutoGitSemVer configuration...DONE! (0, 0:00:00.001416, default configuration info will be used)
Enumerating changes...
VERBOSE: Processing '11c41919cb2ed8ef26542665fc9caa6544081457' (2024-03-09 11:53:11-05:00)...DONE! (0, 0:00:00.000049, 0.6.1)
DONE! (0, 0:00:00.192439, 1 change processed, no changes applied [0.00%])
Calculating semantic version...
0.6.1+20240318122836.BROWNELL08
DONE! (0, 0:00:00.053696)
Results: DONE! (0, 0:00:00.265691)
Display Helpautogitsemver --help
 Usage: autogitsemver [OPTIONS] [PATH]
Automatically generates semantic versions based on changes in a git repository.
┌─ Arguments ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ path [PATH] Generate a semantic version based on changes that impact the specified path. [default: C:\Code\AutoGitSemVer] │
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
┌─ Options ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ --style [Standard|AllPrerelease|AllMetadata] Specifies the way in which the semantic version is generated; this is useful when targets using the generated │
│ semantic version do not fully support the semantic version specification. │
│ [default: GenerateStyle.Standard] │
│ --prerelease-name TEXT Create a semantic version string with this prerelease name. [default: None] │
│ --no-prefix Do not include the prefix in the generated semantic version. │
│ --no-branch-name Do not include the branch name in the prerelease section of the generated semantic version. │
│ --no-metadata Do not include the build metadata section of the generated semantic version. │
│ --verbose Write verbose information to the terminal. │
│ --debug Write debug information to the terminal. │
│ --quiet Do not display any information other than the generated semantic version. │
│ --version Display the version of this tool and exit. │
│ --install-completion [bash|zsh|fish|powershell|pwsh] Install completion for the specified shell. [default: None] │
│ --show-completion [bash|zsh|fish|powershell|pwsh] Show completion for the specified shell, to copy it or customize the installation. [default: None] │
│ --help Show this message and exit. │
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
Versionautogitsemver --version
autogitsemver v0.7.0

Running with Python

fromioimportStringIOfrompathlibimportPathfromAutoGitSemVerimportGetSemanticVersionfromdbrownell_Common.Streams.DoneManagerimportDoneManagerwithDoneManager.Create(StringIO(), "") asdm:
path=Path.cwd()
result=GetSemanticVersion(dm, path)
print(result.semantic_version_string)

Updating the Version

A simplified semantic version is defined by a major number, a minor number, and a patch number in the form:

<major>.<minor>.<patch>

Changes to each of these numbers convey different meanings to those who have taken a dependency on the solution decorated by a semantic version:

  • Changes to a major number indicate that backwards-incompatible functionality was introduced.
  • Changes to a minor number indicate that backwards-compatible functionality was introduced.
  • Changes to a patch number indicate that changes were introduced (but those changes did not introduce new functionality).

By default, AutoGitSemVer will increment the patch number for each git commit encountered.

Customizing the Update

The following tokens can be added anywhere in a git commit's title or description to increment the major, minor, or patch numbers:

Semantic Version NumberGit Comment Token(s)Example
major+major1.2.3 -> 2.0.0
minor+minor, +feature1.2.3 -> 1.3.0
patch+patch1.2.3 -> 1.2.4
Examples
Modifier in the Description
Git Commit Title:Added feature Foo
Git Commit Description:Foo lets a user... +minor
Modifier in the Title
Git Commit Title:Added feature Foo (+minor)
Git Commit Description:Foo lets a user...

Advanced Configuration

Configuration Files

The way in which semantic versions are generated can be customized through configuration files named:

  • AutoGitSemVer.json
  • AutoGitSemVer.yaml
  • AutoGitSemVer.yml

These configuration files will impact the semantic versions generated for any changes in files or directories in the directory or its children. For example, given the directory structure:

<root>
|- File1.txt
|- DirectoryA
|- AutoGitSemVer.json
|- FileA.txt
|- DirectoryA.1
|- FileA1.txt
|- DirectoryB
|- AutoGitSemVer.yaml
|- FileB.txt
File with ChangesConfiguration Filename
File1.txtNone
FileA.txtDirectoryA/AutoGitSemVer.json
FileA1.txtDirectoryA/AutoGitSemVer.json
FileB.txtDirectoryB/AutoGitSemVer.yaml

The configuration file used when generating the semantic version is displayed when running AutoGitSemVer.

Information about the contents of these configuration files can be found in AutoGitSemVerSchema.SimpleSchema.

A simple example of a configuration file can be found here.

Installation

Installation MethodCommand
Via uvuv add AutoGitSemVer
Via pippip install AutoGitSemVer

Verifying Signed Artifacts

Artifacts are signed and verified using py-minisign and the public key in the file ./minisign_key.pub.

To verify that an artifact is valid, visit the latest release and download the .minisign signature file that corresponds to the artifact, then run the following command, replacing <filename> with the name of the artifact to be verified:

uv run --with py-minisign python -c "import minisign; minisign.PublicKey.from_file('minisign_key.pub').verify_file('<filename>'); print('The file has been verified.')"

Development

Please visit Contributing and Development for information on contributing to this project.

Additional Information

Additional information can be found at these locations.

TitleDocumentDescription
Code of ConductCODE_OF_CONDUCT.mdInformation about the norms, rules, and responsibilities we adhere to when participating in this open source community.
ContributingCONTRIBUTING.mdInformation about contributing to this project.
DevelopmentDEVELOPMENT.mdInformation about development activities involved in making changes to this project.
GovernanceGOVERNANCE.mdInformation about how this project is governed.
MaintainersMAINTAINERS.mdInformation about individuals who maintain this project.
SecuritySECURITY.mdInformation about how to privately report security issues associated with this project.

License

AutoGitSemVer is licensed under the MIT license.

About

Generate a semantic version based on commits made to a git repository.

Resources

Code of conduct

Contributing

Security policy

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages