diff --git a/.github/workflows/ci-develop.yml b/.github/workflows/ci-develop.yml new file mode 100644 index 0000000..e7a83b9 --- /dev/null +++ b/.github/workflows/ci-develop.yml @@ -0,0 +1,16 @@ +name: CI on Develop +on: + push: + branches: [ develop ] + workflow_dispatch: + +jobs: + create-new-tag: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Create and Push new tag + shell: pwsh + run: | + . ./Scripts/VersionManager.ps1 + New-Tag -Branch "develop" \ No newline at end of file diff --git a/.github/workflows/ci-master.yml b/.github/workflows/ci-master.yml new file mode 100644 index 0000000..b9c6a43 --- /dev/null +++ b/.github/workflows/ci-master.yml @@ -0,0 +1,16 @@ +name: CI on Master +on: + push: + branches: [ master ] + workflow_dispatch: + +jobs: + create-new-tag: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Create and Push new tag + shell: pwsh + run: | + . ./Scripts/VersionManager.ps1 + New-Tag -Branch "master" \ No newline at end of file diff --git a/Readme.md b/Readme.md index ec25114..abbd2c3 100644 --- a/Readme.md +++ b/Readme.md @@ -1,3 +1,3 @@ -#PowerSell Versioning Script +# PowerSell Versioning Script This script contains functions to manage git tags for software versions \ No newline at end of file diff --git a/VersionManager.ps1 b/Scripts/VersionManager.ps1 similarity index 54% rename from VersionManager.ps1 rename to Scripts/VersionManager.ps1 index 7acf21e..f1b515c 100644 --- a/VersionManager.ps1 +++ b/Scripts/VersionManager.ps1 @@ -1,6 +1,40 @@ ################################# # This script contains funtions to create git tags following GitFlow ################################# +function New-Tag +{ + param ( + [Parameter(Mandatory=$true)] + [string]$Branch + ) + + $version = Get-CurrentVersion + $patch = Get-NewPatch + $prefix = "" + + if ($Branch -eq "release") + { + $version = ([decimal]$currentVersion + 0.1).ToString() + $prefix = "Beta-" + } + if ($Branch -eq "develop") + { + $version = ([decimal]$currentVersion + 0.1).ToString() + $prefix = "Dev-" + } + if ($Branch -eq "hotfix") + { + $version = ([decimal]$currentVersion + 0.1).ToString() + $prefix = "HF-" + } + + $tag = "v$version.$prefix$patch" + + Invoke-Expression "git tag $tag" + Invoke-Expression "git push origin $tag" + + return $tag +} function Get-CurrentVersion { @@ -35,17 +69,17 @@ function Get-CurrentVersion function Get-NewPatch { - param ( + param ( [Parameter(Mandatory=$false)] [string]$Prefix = "" ) - if ($Prefix -ne "") + if ($Prefix -eq "") { - return $Prefix + "-" + (Get-Date).ToString("yyMMddhhmmss") + return (Get-Date).ToString("yyMMddhhmmss") } - return (Get-Date).ToString("yyMMddhhmmss") + return $Prefix + "-" + (Get-Date).ToString("yyMMddhhmmss") } function Get-NextVersion @@ -58,4 +92,4 @@ function Get-GitTags { $tags = Invoke-Expression "git tag --list" $tags -} +} \ No newline at end of file