From f24eb02ca10bd4c19e22df9891ec178e13b7e223 Mon Sep 17 00:00:00 2001 From: Macocian Alexandru Victor Date: Sat, 13 Aug 2022 00:24:54 +0200 Subject: [PATCH] Pipeline to check that version is updated (#43) * Pipeline to check that version is updated --- .github/workflows/version_check.yaml | 45 ++++++++++++++++++++++++++++ Daybreak.sln | 10 ++++++- Daybreak/Daybreak.csproj | 2 +- Scripts/CompareVersions.ps1 | 22 ++++++++++++++ 4 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/version_check.yaml create mode 100644 Scripts/CompareVersions.ps1 diff --git a/.github/workflows/version_check.yaml b/.github/workflows/version_check.yaml new file mode 100644 index 00000000..77de3467 --- /dev/null +++ b/.github/workflows/version_check.yaml @@ -0,0 +1,45 @@ +name: Daybreak Version Check + +on: + pull_request: + branches: + - master + +jobs: + + build: + + strategy: + matrix: + targetplatform: [x64] + + runs-on: windows-latest + + env: + Configuration: Release + Solution_Path: Daybreak.sln + Actions_Allow_Unsecure_Commands: true + + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Get Latest Tag + id: getLatestTag + uses: WyriHaximus/github-action-get-previous-tag@v1 + + - name: Build Daybreak project + run: dotnet build Daybreak -c $env:Configuration + + - name: Set version variable + run: | + $version = .\Scripts\GetBuildVersion.ps1 + echo "::set-env name=Version::$version" + + - name: Check version difference + run: | + .\Scripts\CompareVersions -currentVersion ${{ env.Version }} -lastVersion ${{ env.LatestReleaseTag }} + env: + LatestReleaseTag: ${{ steps.getLatestTag.outputs.tag }} \ No newline at end of file diff --git a/Daybreak.sln b/Daybreak.sln index 474ab6f4..3bcf4bb4 100644 --- a/Daybreak.sln +++ b/Daybreak.sln @@ -11,9 +11,17 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Pipelines", "Pipelines", "{ ProjectSection(SolutionItems) = preProject .github\workflows\cd.yaml = .github\workflows\cd.yaml .github\workflows\ci.yaml = .github\workflows\ci.yaml + .github\workflows\version_check.yaml = .github\workflows\version_check.yaml EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Daybreak.Installer", "Daybreak.Installer\Daybreak.Installer.csproj", "{4E2BB805-135D-4F02-8C53-3D8B6876D323}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Daybreak.Installer", "Daybreak.Installer\Daybreak.Installer.csproj", "{4E2BB805-135D-4F02-8C53-3D8B6876D323}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Scripts", "Scripts", "{41AE8C5D-25E1-4B08-8D65-868552421A63}" + ProjectSection(SolutionItems) = preProject + Scripts\BuildRelease.ps1 = Scripts\BuildRelease.ps1 + Scripts\GetBuildVersion.ps1 = Scripts\GetBuildVersion.ps1 + Scripts\CompareVersions.ps1 = Scripts\CompareVersions.ps1 + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/Daybreak/Daybreak.csproj b/Daybreak/Daybreak.csproj index 8aeeb32e..c239c6cb 100644 --- a/Daybreak/Daybreak.csproj +++ b/Daybreak/Daybreak.csproj @@ -10,7 +10,7 @@ preview Daybreak.ico true - 0.9.3.4 + 0.9.3.5 diff --git a/Scripts/CompareVersions.ps1 b/Scripts/CompareVersions.ps1 new file mode 100644 index 00000000..f03b5115 --- /dev/null +++ b/Scripts/CompareVersions.ps1 @@ -0,0 +1,22 @@ +Param( + [Parameter(Mandatory=$true)] + [string]$currentVersion, + [Parameter(Mandatory=$true)] + [string]$lastVersion +) + +if ($currentVersion.StartsWith("v")){ + $currentVersion = $currentVersion.Substring(1) +} + +if ($lastVersion.StartsWith("v")){ + $lastVersion = $lastVersion.Substring(1) +} + +$isNewer = $currentVersion.CompareTo($lastVersion) -eq 1 +if ($isNewer -eq $false){ + throw "Version is not incremented. Current version " + $currentVersion + ". Last version " + $lastVersion +} +else{ + Write-Host "Version has been incremented" +} \ No newline at end of file