githubEdit

GitVersion

The DecSm.Atom.Module.GitVersion module integrates GitVersionarrow-up-right into your DecSm.Atom build process. GitVersion is a tool that generates a semantic version number based on your Git history, providing consistent and meaningful versioning for your builds and releases.

Features

  • Automatic Versioning: Automatically determines the semantic version of your project based on Git tags and branch conventions.

  • Build ID Generation: Uses the full semantic version as the build ID, ensuring unique and traceable build identifiers.

  • Build Version Provider: Provides detailed version components (major, minor, patch, pre-release) for use in your build logic.

  • Seamless Integration: Configures DecSm.Atom to use GitVersion's output for its internal build ID and versioning mechanisms.

Getting Started

To use the GitVersion module, you need to implement the IGitVersion interface in your build definition. This will automatically register the necessary services to use GitVersion for build ID and versioning.

Prerequisites

  • GitVersion.Tool: The GitVersion .NET tool must be installed. The module will attempt to install it automatically if it's not found.

  • Git Repository: Your project must be a Git repository with a commit history.

Implementation

Add the IGitVersion interface to your Build.cs file:

using DecSm.Atom.Build.Definition;
using DecSm.Atom.Module.GitVersion;

namespace Atom;

[BuildDefinition]
internal partial class Build : IGitVersion
{
    // Your build targets and other definitions
}

Usage

Once IGitVersion is implemented, DecSm.Atom will automatically use GitVersion to determine the build ID and version.

Accessing Build ID

The build ID will be the FullSemVer output from GitVersion. You can access it via the BuildId property of the IBuildIdProvider service.

Accessing Build Version

The build version, as a SemVersion object, can be accessed via the Version property of the IBuildVersionProvider service.

Controlling Build ID Generation

By default, implementing IGitVersion enables GitVersion for both build ID and versioning. If you need to explicitly control whether GitVersion is used for the build ID, you can use the UseGitVersionForBuildId workflow option.

How GitVersion Works

GitVersion analyzes your Git repository to determine the current version. It looks at:

  • Tags: Semantic version tags (e.g., v1.0.0) are used as base versions.

  • Branches: Branch names (e.g., main, develop, feature/my-feature) influence the pre-release tag.

  • Commits: The number of commits since the last tag and the commit SHA are used to increment the patch version and add build metadata.

For more detailed information on how GitVersion calculates versions, refer to the GitVersion documentationarrow-up-right.

Last updated

Was this helpful?