-
-
Notifications
You must be signed in to change notification settings - Fork 5
62 lines (51 loc) · 2.14 KB
/
handle-versioning-accross-branches.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
name: Handle versioning accros branches
on:
push:
# todo: add file paths of the files with version numbers
jobs:
extension-versioning:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: git-actions/set-user@v1
- name: Prevent branch warnings
run: |
# config git advice.detachedHead to false
git config advice.detachedHead false
- name: Get highest version number accross all branches
id: get-version
shell: pwsh
run: |
# SemVer code
function Parse-SemVer ($version) {
$parts = $version.Split('.')
return @{
Major = [int]$parts[0]
Minor = [int]$parts[1]
Patch = [int]$parts[2]
}
}
$highestVersion = @{
Major = 0
Minor = 0
Patch = 0
}
# loop over all branches
$highestVersion = 0
foreach ($branch in $(git branch -r --format='%(refname:short)')) {
# checkout the branch
git checkout $branch
# get the semantic version number from the vss-extension-dev.json file
$version = Get-Content -Path "vss-extension.json" | ConvertFrom-Json | Select-Object -ExpandProperty version
Write-Host "Found version: [$version] in branch: [$branch]"
# check if the version is semantically higher than the highest version using SemVer
$version = Parse-SemVer $version
if ($version.Major -gt $highestVersion.Major -or
($version.Major -eq $highestVersion.Major -and $version.Minor -gt $highestVersion.Minor) -or
($version.Major -eq $highestVersion.Major -and $version.Minor -eq $highestVersion.Minor -and $version.Patch -gt $highestVersion.Patch))
{
$highestVersion = $version
Write-Host "New highest version: [$($highestVersion.Major).$($highestVersion.Minor).$($highestVersion.Patch)]"
}
}
Write-Host "Highest version: [$($highestVersion.Major).$($highestVersion.Minor).$($highestVersion.Patch)]"