Skip to content

Commit aa74a6f

Browse files
committed
feat: implement custom version calculation with build metadata
- Calculate version as base_version+build_number (e.g., 2.327.1+1) - Build number increments for each release of the same base version - Bypasses GitVersion tag conflicts with old v1.x tags - Docker images use base version, releases use full version with build metadata
1 parent a01523a commit aa74a6f

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

.github/workflows/pipeline.yaml

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ jobs:
4343
gitVersion_InformationalVersion: ${{ steps.gitversion.outputs.GitVersion_InformationalVersion }}
4444
gitVersion_AssemblySemFileVer: ${{ steps.gitversion.outputs.GitVersion_AssemblySemFileVer }}
4545
base_version: ${{ steps.extract_base_version.outputs.version }}
46+
full_version: ${{ steps.extract_base_version.outputs.full_version }}
4647
build: ${{ steps.evaluate_build.outputs.result }}
4748
build_push: ${{ steps.evaluate_build_push.outputs.result }}
4849
build_configuration: ${{ steps.evaluate_build_configuration.outputs.result }}
@@ -64,20 +65,34 @@ jobs:
6465
versionSpec: "6.x"
6566
preferLatestVersion: true
6667

67-
- name: extract - base version from Dockerfile
68+
- name: extract - base version from Dockerfile and calculate version
6869
id: extract_base_version
6970
run: |
7071
BASE_VERSION=$(grep "^FROM ghcr.io/actions/actions-runner:" ${{ env.container_image_build_dockerfile }} | cut -d':' -f2)
7172
echo "Extracted base version: $BASE_VERSION"
7273
echo "version=$BASE_VERSION" >> $GITHUB_OUTPUT
74+
75+
# Calculate build number based on commits since last tag with this base version
76+
BUILD_NUMBER=1
77+
LAST_TAG=$(git tag --list "v${BASE_VERSION}+*" 2>/dev/null | sort -V | tail -1 || echo "")
78+
if [ -n "$LAST_TAG" ]; then
79+
# Extract the build number from the last tag and increment
80+
LAST_BUILD=$(echo "$LAST_TAG" | sed "s/v${BASE_VERSION}+//")
81+
BUILD_NUMBER=$((LAST_BUILD + 1))
82+
else
83+
# Count commits since we started using this base version
84+
BUILD_NUMBER=$(git rev-list --count HEAD 2>/dev/null || echo 1)
85+
fi
86+
87+
FULL_VERSION="${BASE_VERSION}+${BUILD_NUMBER}"
88+
echo "Full version with build metadata: $FULL_VERSION"
89+
echo "full_version=$FULL_VERSION" >> $GITHUB_OUTPUT
7390
7491
- name: gitversion - execute
7592
id: gitversion
7693
uses: gittools/actions/gitversion/execute@v4.0.1
7794
with:
7895
configFilePath: GitVersion.yaml
79-
overrideConfig: |
80-
next-version: ${{ steps.extract_base_version.outputs.version }}
8196

8297
- name: tools - detect changes
8398
id: pathsFilter
@@ -243,6 +258,7 @@ jobs:
243258
gitVersion_InformationalVersion: ${{ needs.discovery.outputs.gitVersion_InformationalVersion }}
244259
gitVersion_AssemblySemFileVer: ${{ needs.discovery.outputs.gitVersion_AssemblySemFileVer }}
245260
base_version: ${{ needs.discovery.outputs.base_version }}
261+
full_version: ${{ needs.discovery.outputs.full_version }}
246262
steps:
247263
- name: tools - docker - login ghcr.io
248264
uses: docker/login-action@v3
@@ -272,11 +288,11 @@ jobs:
272288
uses: softprops/action-gh-release@v2
273289
with:
274290
repository: ${{ github.repository }}
275-
name: v${{ env.gitVersion_InformationalVersion }}
276-
tag_name: v${{ env.gitVersion_InformationalVersion }}
291+
name: v${{ env.full_version }}
292+
tag_name: v${{ env.full_version }}
277293
body: |
278294
Docker image version: `${{ env.base_version }}`
279-
Release version: `${{ env.gitVersion_InformationalVersion }}`
295+
Release version: `${{ env.full_version }}`
280296
281297
The release process is automated.
282298
generate_release_notes: true

GitVersion.yaml

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
assembly-versioning-scheme: MajorMinorPatchTag
22
assembly-file-versioning-scheme: MajorMinorPatchTag
3-
mode: ContinuousDeployment
3+
mode: Mainline
44
tag-prefix: '[vV]'
55
major-version-bump-message: '\+semver:\s?(breaking|major)'
66
minor-version-bump-message: '\+semver:\s?(feature|minor)'
@@ -11,20 +11,8 @@ commit-message-incrementing: Enabled
1111

1212
branches:
1313
main:
14-
mode: ContinuousDeployment
15-
label: ''
16-
increment: None
17-
track-merge-target: false
1814
regex: ^master$|^main$
19-
source-branches:
20-
- develop
21-
- release
22-
- feature
23-
- hotfix
24-
tracks-release-branches: false
25-
is-release-branch: true
2615
is-main-branch: true
27-
pre-release-weight: 55000
2816

2917
develop:
3018
mode: ContinuousDeployment

0 commit comments

Comments
 (0)