Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ pipeline {
env.GIT_COMMIT = bat(script: '@git rev-parse HEAD', returnStdout: true).trim()
}
powershell "powershell.exe -File .\\Scripts\\Versioning.ps1 -VersionFile './Scripts/PQBrowser.version' -Commit false"
powershell "powershell.exe -File .\\Scripts\\PackageVersioning.ps1 -VersionFile './PQBrowser/package.json'"
bat(script: "@git add Scripts/PQBrowser.version")
bat(script: "@git add PQBrowser/package.json")
bat(script: "git diff --cached --quiet || git commit -m \"Updated Version Number\"")
}
}
Expand Down
6 changes: 1 addition & 5 deletions PQBrowser/PQBrowser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,7 @@
<Content Update="wwwroot\Scripts\PQBrowser.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="package.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup>
</ItemGroup>

<ItemGroup>
<Compile Remove="DynamicAssemblies\**" />
Expand Down
5 changes: 0 additions & 5 deletions PQBrowser/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
using PQBrowser.Security;
using System;
using System.IO;
using System.Text.Json;
namespace PQBrowser;

public class Startup
Expand All @@ -52,9 +51,6 @@ public Startup(IConfiguration configuration, IWebHostEnvironment env)
SetupTempPath();
Configuration = configuration;
Env = env;

using JsonDocument package = JsonDocument.Parse(File.ReadAllText(Path.Combine(env.ContentRootPath, "package.json")));
UIVersion = package.RootElement.GetProperty("version").GetString()!;
}

public static class Policies
Expand All @@ -65,7 +61,6 @@ public static class Policies

public IWebHostEnvironment Env { get; set; }
public IConfiguration Configuration { get; }
public static string UIVersion { get; private set; } = "";

public void ConfigureServices(IServiceCollection services)
{
Expand Down
6 changes: 5 additions & 1 deletion PQBrowser/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
//*******************************************************************************************************@
@using Gemstone.Data
@using Gemstone.Configuration;
@using Gemstone.Reflection
@using Microsoft.AspNetCore.Antiforgery
@using Microsoft.AspNetCore.Authentication.Cookies
@using Microsoft.Extensions.Options
Expand All @@ -40,6 +41,9 @@
@{
Layout = "";

Version assemblyVersionInfo = AssemblyInfo.EntryAssembly.Version;
string applicationVersion = assemblyVersionInfo.Major + "." + assemblyVersionInfo.Minor + "." + assemblyVersionInfo.Build;

try {
using (AdoDataConnection connection = new AdoDataConnection(Settings.Default))
{
Expand Down Expand Up @@ -123,6 +127,6 @@

<script src="@Url.Content("~/js/jquery-3.6.0.min.js")"></script>
<script src="@Url.Content("~/js/moment.min.js")"></script>
<script src="@Url.Content($"~/Scripts/PQBrowser.js?v={PQBrowser.Startup.UIVersion}")"></script>
<script src="@Url.Content($"~/Scripts/PQBrowser.js?v={applicationVersion}")"></script>
</body>
</html>
86 changes: 86 additions & 0 deletions Scripts/PackageVersioning.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
param(
[string]$VersionFile
)

#Compare Versions
function CompareVersions {
param(
[string]$Version1,
[string]$Version2
)

$array1 = $Version1.Split(".")
$array2 = $Version2.Split(".")

$i = 0
while ($i -lt [Math]::Max($array1.Count, $array2.Count)) {
if ($i -ge $array1.Count) {
$v1 = 0
} else {
$v1 = [int]$array1[$i]
}
if ($i -ge $array2.Count) {
$v2 = 0
} else {
$v2 = [int]$array2[$i]
}
if ($v1 -gt $v2) {
return 1
}
if ($v2 -gt $v1) {
return -1
}
$i++
}
return 0
}

#Increment Version
function IncrementVersion {
param(
[string]$prevVersion
)
$array = $prevVersion.Split(".")
$array[$array.Count - 1] = [int]$array[$array.Count - 1] + 1
return $array -join '.'
}

#Get Latest Version on Github
git fetch origin master:refs/remotes/origin/master
$commit = git rev-parse origin/master
$tag = git describe --tags --abbrev=0 $commit

if ([String]::IsNullOrEmpty($tag)) {
Write-Host "No previous tag found"
$tag = "v3.0.0"
}

$tag = $tag.TrimStart("v")

Write-Host "Last Published Version Found: $tag"


# Get Current Version
$currentVersion = $((Get-Content -Path $VersionFile | ConvertFrom-Json).version)
Write-Host "Current Version in Repository: $currentVersion"

# Check if Update is needed
if ((CompareVersions -Version1 $currentVersion -Version2 $tag) -gt 0) {
Write-Host "No Version update neccesarry"
return;
}

# Update Version
$updatedVersion = IncrementVersion -prevVersion $tag

Write-Host "Updating to $updatedVersion"

$content = [System.IO.File]::ReadAllText($VersionFile)
$versionPattern = [regex]'(?m)(^\s*"version"\s*:\s*")[^"]+("\s*,)'
$content = $versionPattern.Replace($content, {
param($match)
return $match.Groups[1].Value + $updatedVersion + $match.Groups[2].Value
}, 1)

$utf8WithoutBom = New-Object System.Text.UTF8Encoding($false)
[System.IO.File]::WriteAllText($VersionFile, $content, $utf8WithoutBom)