Skip to content

Commit d8a3bc7

Browse files
committed
ci(versioning): Enhance GitVersion update logic in workflows
Dynamically extract current version and update to major.minor.x format across expanded file types.
1 parent a7cf940 commit d8a3bc7

3 files changed

Lines changed: 32 additions & 3 deletions

File tree

.github/workflows/examples-version.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ jobs:
2424
fetch-depth: 1
2525

2626
- run: |
27+
. .\utilities.ps1 # Import the functions
28+
2729
$oldTag = "${{ github.event.client_payload.oldTag }}"
2830
$newTag = "${{ github.event.client_payload.newTag }}"
2931
echo "Updating examples version to $newTag"
3032
echo "Old version: $oldTag"
3133
echo "New version: $newTag"
3234
33-
. .\utilities.ps1 # Import the functions
3435
dir -r .\package.json | % { update-files $_ -OldVersion $oldTag -NewVersion $newTag }
3536
dir -r .\docs\**\*.md | % { update-files $_ -OldVersion $oldTag -NewVersion $newTag }
3637
dir -r .github\**\*.yml | % { update-files $_ -OldVersion $oldTag -NewVersion $newTag }

.github/workflows/gitversion-published.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,21 @@ jobs:
2424
fetch-depth: 1
2525

2626
- run: |
27-
$newTag = "${{ github.event.client_payload.tag }}"
28-
$newTag = "${{ github.event.client_payload.newTag }}"
27+
. ./utilities.ps1 # Import the functions
28+
29+
$version = "${{ github.event.client_payload.newTag }}"
30+
31+
$oldTag = extract-version
32+
$newTag = ($version -split '\.')[0,1] -join '.' | % { "$_.x" }
33+
2934
echo "Updating GitVersion version to $newTag"
35+
echo "Old version: $oldTag"
36+
echo "New version: $newTag"
37+
38+
dir -r .\docs\**\*.md | % { update-files $_ -OldVersion $oldTag -NewVersion $newTag }
39+
dir -r .github\**\*.yml | % { update-files $_ -OldVersion $oldTag -NewVersion $newTag }
40+
dir -r .azure\**\*.yml | % { update-files $_ -OldVersion $oldTag -NewVersion $newTag }
41+
3042
name: Update GitVersion version
3143
3244
- uses: gittools/cicd/git-commit-push@main

utilities.ps1

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,19 @@ function publish-vsix()
5252

5353
echo "vsix=$vsix" >> $env:GITHUB_OUTPUT
5454
}
55+
56+
function extract-version()
57+
{
58+
$filePath = ".github/workflows/ci.yml"
59+
if (Test-Path $filePath) {
60+
$content = Get-Content $filePath -Raw
61+
if ($content -match "versionSpec:\s*'([^']+)'") {
62+
$version = $Matches[1]
63+
Write-Output $version
64+
} else {
65+
Write-Error "Could not find versionSpec in $filePath"
66+
}
67+
} else {
68+
Write-Error "File not found: $filePath"
69+
}
70+
}

0 commit comments

Comments
 (0)