Skip to content

Commit

Permalink
Merge pull request #12 from atc-net/feature/improve-workflow
Browse files Browse the repository at this point in the history
feat: WIP on pre-integration
  • Loading branch information
davidkallesen authored Nov 10, 2023
2 parents c060214 + 30381ce commit 9438f98
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 113 deletions.
37 changes: 16 additions & 21 deletions .github/workflows/post-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,27 @@ jobs:
- name: 🔁 Restore packages
run: dotnet restore Atc.Installer-WithoutSetup.sln

# - name: 🛠️ Build
# run: dotnet build Atc.Installer-WithoutSetup.sln -c Release --no-restore /p:UseSourceLink=true

# - name: 🧪 Run unit tests
# run: dotnet test Atc.Installer-WithoutSetup.sln -c Release --no-build --filter "Category!=Integration"

# - name: 🌩️ SonarCloud install scanner
# run: dotnet tool install --global dotnet-sonarscanner
- name: 🛠️ Building library in release mode with MSBuild
run: |
$vsWhereExePath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
$vsInstallationPath = & $vsWhereExePath -latest -products * -requires Microsoft.Component.MSBuild -property installationPath
$msBuildExePath = Join-Path $vsInstallationPath "MSBuild\Current\Bin\MSBuild.exe"
& $msBuildExePath Atc.Installer-WithoutSetup.sln -p:Configuration=Release -p:Platform="Any CPU" -m
shell: pwsh

# - name: 🌩️ SonarCloud analyze
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# shell: pwsh
# run: |
# dotnet sonarscanner begin /k:"atc-wpf" /o:"atc-net" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io"
# dotnet build Atc.Installer-WithoutSetup.sln -c Release /p:UseSourceLink=true --no-restore
# dotnet sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}"
# - name: 🧪 Run unit tests with MSBuild
# run: |
# $vsWhereExePath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
# $vsInstallationPath = & $vsWhereExePath -latest -products * -requires Microsoft.Component.MSBuild -property installationPath
# $vstestPath = Join-Path $vsInstallationPath "Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe"
# $testAssemblies = (Get-ChildItem -Recurse -Filter *.Test.dll).FullName
# & $vstestPath $testAssemblies
# shell: pwsh

- name: ⏩ Merge to stable-branch
run: |
git config --local user.email ${{ env.ATC_EMAIL }}
git config --local user.name ${{ env.ATC_NAME }}
git checkout stable
git merge --ff-only main
git push origin stable
# - name: 🗳️ Creating library package for pre-release
# run: dotnet pack Atc.Installer-WithoutSetup.sln -c Release --no-restore -o ${GITHUB_WORKSPACE}/packages -p:RepositoryBranch=$BRANCH_NAME
git push origin stable
82 changes: 49 additions & 33 deletions .github/workflows/pre-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,45 +16,61 @@ jobs:
with:
fetch-depth: 0

# - name: ⚙️ Setup dotnet 7.0.x
# uses: actions/setup-dotnet@v1
# with:
# dotnet-version: '7.0.x'
- name: ⚙️ Setup dotnet 7.0.x
uses: actions/setup-dotnet@v1
with:
dotnet-version: '7.0.x'

# - name: 📐 Ensure nuget.org added as package source on Windows
# run: dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org --configfile $env:APPDATA\NuGet\NuGet.Config
# continue-on-error: true
- name: 📐 Ensure nuget.org added as package source on Windows
run: dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org --configfile $env:APPDATA\NuGet\NuGet.Config
continue-on-error: true

# - name: 🔁 Restore packages
# run: dotnet restore Atc.Installer-WithoutSetup.sln
- name: 🔁 Restore packages
run: dotnet restore Atc.Installer-WithoutSetup.sln

# - name: 🛠️ Building library in release mode
# run: dotnet build Atc.Installer-WithoutSetup.sln -c Release --no-restore
- name: 🛠️ Building library in release mode with MSBuild
run: |
$vsWhereExePath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
$vsInstallationPath = & $vsWhereExePath -latest -products * -requires Microsoft.Component.MSBuild -property installationPath
$msBuildExePath = Join-Path $vsInstallationPath "MSBuild\Current\Bin\MSBuild.exe"
& $msBuildExePath Atc.Installer-WithoutSetup.sln -p:Configuration=Release -p:Platform="Any CPU" -m
shell: pwsh

dotnet-test:
runs-on: windows-latest
needs:
- dotnet-build
steps:
- name: 🛒 Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 0
# dotnet-test:
# runs-on: windows-latest
# needs:
# - dotnet-build
# steps:
# - name: 🛒 Checkout repository
# uses: actions/checkout@v2
# with:
# fetch-depth: 0

# - name: ⚙️ Setup dotnet 7.0.x
# uses: actions/setup-dotnet@v1
# with:
# dotnet-version: '7.0.x'
# - name: ⚙️ Setup dotnet 7.0.x
# uses: actions/setup-dotnet@v1
# with:
# dotnet-version: '7.0.x'

# - name: 📐 Ensure nuget.org added as package source on Windows
# run: dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org --configfile $env:APPDATA\NuGet\NuGet.Config
# continue-on-error: true
# - name: 📐 Ensure nuget.org added as package source on Windows
# run: dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org --configfile $env:APPDATA\NuGet\NuGet.Config
# continue-on-error: true

# - name: 🔁 Restore packages
# run: dotnet restore Atc.Installer-WithoutSetup.sln
# - name: 🔁 Restore packages
# run: dotnet restore Atc.Installer-WithoutSetup.sln

# - name: 🛠️ Build
# run: dotnet build Atc.Installer-WithoutSetup.sln -c Release --no-restore /p:UseSourceLink=true
# - name: 🛠️ Building library in release mode with MSBuild
# run: |
# $vsWhereExePath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
# $vsInstallationPath = & $vsWhereExePath -latest -products * -requires Microsoft.Component.MSBuild -property installationPath
# $msBuildExePath = Join-Path $vsInstallationPath "MSBuild\Current\Bin\MSBuild.exe"
# & $msBuildExePath Atc.Installer-WithoutSetup.sln -p:Configuration=Release -p:Platform="Any CPU" -m
# shell: pwsh

# - name: 🧪 Run unit tests
# run: dotnet test Atc.Installer-WithoutSetup.sln -c Release --no-build --filter "Category!=Integration"
# - name: 🧪 Run unit tests with MSBuild
# run: |
# $vsWhereExePath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
# $vsInstallationPath = & $vsWhereExePath -latest -products * -requires Microsoft.Component.MSBuild -property installationPath
# $vstestPath = Join-Path $vsInstallationPath "Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe"
# $testAssemblies = (Get-ChildItem -Recurse -Filter *.Test.dll).FullName
# & $vstestPath $testAssemblies
# shell: pwsh
23 changes: 17 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,27 @@ jobs:
- name: 🔁 Restore packages
run: dotnet restore Atc.Installer-WithoutSetup.sln

- name: 🛠️ Building library in release mode
run: dotnet build Atc.Installer-WithoutSetup.sln -c Release --no-restore /p:UseSourceLink=true
- name: 🛠️ Building library in release mode with MSBuild
run: |
$vsWhereExePath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
$vsInstallationPath = & $vsWhereExePath -latest -products * -requires Microsoft.Component.MSBuild -property installationPath
$msBuildExePath = Join-Path $vsInstallationPath "MSBuild\Current\Bin\MSBuild.exe"
& $msBuildExePath Atc.Installer-WithoutSetup.sln -p:Configuration=Release -p:Platform="Any CPU" -m
shell: pwsh

# - name: 🧪 Run unit tests with MSBuild
# run: |
# $vsWhereExePath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
# $vsInstallationPath = & $vsWhereExePath -latest -products * -requires Microsoft.Component.MSBuild -property installationPath
# $vstestPath = Join-Path $vsInstallationPath "Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe"
# $testAssemblies = (Get-ChildItem -Recurse -Filter *.Test.dll).FullName
# & $vstestPath $testAssemblies
# shell: pwsh

- name: ⏩ Merge to release-branch
run: |
git config --local user.email ${{ env.ATC_EMAIL }}
git config --local user.name ${{ env.ATC_NAME }}
git checkout release
git merge --ff-only stable
git push origin release
- name: 🗳️ Creating library package for release
run: dotnet pack Atc.Installer-WithoutSetup.sln -c Release --no-restore -o ${GITHUB_WORKSPACE}/packages -p:RepositoryBranch=$BRANCH_NAME /p:PublicRelease=true
git push origin release
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,13 @@ public static IList<FileInfo> SearchForFiles(

return result;
}

public static long GetTotalFilesLength(
this DirectoryInfo directoryInfo,
string searchPattern = "*",
bool useRecursive = true)
{
var files = SearchForFiles(directoryInfo, searchPattern, useRecursive);
return files.Sum(file => file.Length);
}
}
62 changes: 62 additions & 0 deletions src/Atc.Installer.Integration/Helpers/VersionHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
namespace Atc.Installer.Integration.Helpers;

public static class VersionHelper
{
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "OK.")]
public static bool IsSourceNewerThanDestination(
string? sourceVersion,
string? destinationVersion)
{
if (sourceVersion is null ||
destinationVersion is null ||
sourceVersion == destinationVersion)
{
return false;
}

try
{
return IsSourceNewerThanDestination(
new Version(sourceVersion),
new Version(destinationVersion));
}
catch
{
var sortedSet = new SortedSet<string>(StringComparer.Ordinal)
{
sourceVersion,
destinationVersion,
};

return destinationVersion == sortedSet.First();
}
}

public static bool IsSourceNewerThanDestination(
Version? sourceVersion,
Version? destinationVersion)
{
if (sourceVersion is null ||
destinationVersion is null ||
sourceVersion == destinationVersion)
{
return false;
}

return sourceVersion.IsNewerThan(destinationVersion);
}

public static bool IsDefault(
Version? sourceVersion,
Version? destinationVersion)
{
if (sourceVersion is null ||
destinationVersion is null)
{
return false;
}

return "1.0.0.0".Equals(sourceVersion.ToString(), StringComparison.Ordinal) &&
"1.0.0.0".Equals(destinationVersion.ToString(), StringComparison.Ordinal);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
global using System.Text.Json;
global using System.Windows;
global using System.Windows.Data;
global using System.Windows.Media;
global using System.Xml;

global using Atc.Helpers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1000,13 +1000,14 @@ private void WorkOnAnalyzeAndUpdateStatesForDotNetVersion()
installationMainFile = Path.Combine(installationMainPath, $"{Name}.dll");
}

if (!File.Exists(InstalledMainFilePath.GetValueAsString()))
var resolvedInstalledMainFilePath = InstalledMainFilePath.GetValueAsString();
if (!File.Exists(resolvedInstalledMainFilePath))
{
InstallationState = ComponentInstallationState.NotInstalled;
}

if (File.Exists(installationMainFile) &&
File.Exists(InstalledMainFilePath.GetValueAsString()))
File.Exists(resolvedInstalledMainFilePath))
{
Version? sourceVersion = null;
var installationMainFileVersion = FileVersionInfo.GetVersionInfo(installationMainFile);
Expand All @@ -1017,16 +1018,23 @@ private void WorkOnAnalyzeAndUpdateStatesForDotNetVersion()
}

Version? destinationVersion = null;
var installedMainFileVersion = FileVersionInfo.GetVersionInfo(InstalledMainFilePath.GetValueAsString());
var installedMainFileVersion = FileVersionInfo.GetVersionInfo(resolvedInstalledMainFilePath);
if (installedMainFileVersion?.FileVersion is not null)
{
destinationVersion = new Version(installedMainFileVersion.FileVersion);
InstalledVersion = installedMainFileVersion.FileVersion;
}

if (sourceVersion is not null &&
destinationVersion is not null &&
sourceVersion.IsNewerThan(destinationVersion))
if (VersionHelper.IsDefault(sourceVersion, destinationVersion))
{
var sourcePath = new DirectoryInfo(installationMainFile).Parent!;
var destinationPath = new DirectoryInfo(resolvedInstalledMainFilePath).Parent!;
if (sourcePath.GetTotalFilesLength("*.dll") != destinationPath.GetTotalFilesLength("*.dll"))
{
InstallationState = ComponentInstallationState.InstalledWithOldVersion;
}
}
else if (VersionHelper.IsSourceNewerThanDestination(sourceVersion, destinationVersion))
{
InstallationState = ComponentInstallationState.InstalledWithOldVersion;
}
Expand Down Expand Up @@ -1083,25 +1091,9 @@ private void WorkOnAnalyzeAndUpdateStatesForNodeJsVersion()
}
else
{
try
{
var isNewerThan = new Version(sourceVersion).IsNewerThan(new Version(destinationVersion));
InstallationState = isNewerThan
? ComponentInstallationState.InstalledWithOldVersion
: ComponentInstallationState.Installed;
}
catch
{
var sortedSet = new SortedSet<string>(StringComparer.Ordinal)
{
sourceVersion,
destinationVersion,
};

InstallationState = destinationVersion == sortedSet.First()
? ComponentInstallationState.InstalledWithOldVersion
: ComponentInstallationState.Installed;
}
InstallationState = VersionHelper.IsSourceNewerThanDestination(sourceVersion, destinationVersion)
? ComponentInstallationState.InstalledWithOldVersion
: ComponentInstallationState.Installed;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ HostingFrameworkType.DonNetFramework48 or
HostingFrameworkType.DotNet7 or
HostingFrameworkType.DotNet8)
{
return AnalyzeForForDotNet(vm);
return AnalyzeVersion(vm);
}

return vm.ComponentType == ComponentType.InternetInformationService
? AnalyzeForJsVersion(vm)
? AnalyzeVersion(vm)
: Visibility.Collapsed;
}

Expand All @@ -39,32 +39,9 @@ HostingFrameworkType.DotNet7 or
object? parameter,
CultureInfo culture) => null;

private static Visibility AnalyzeForJsVersion(
private static Visibility AnalyzeVersion(
ComponentProviderViewModel vm)
{
if (vm.InstallationVersion == vm.InstalledVersion)
{
return Visibility.Collapsed;
}

var sortedSet = new SortedSet<string>(StringComparer.Ordinal)
{
vm.InstallationVersion!,
vm.InstalledVersion!,
};

return vm.InstalledVersion == sortedSet.First()
=> VersionHelper.IsSourceNewerThanDestination(vm.InstallationVersion, vm.InstalledVersion)
? Visibility.Visible
: Visibility.Collapsed;
}

private static Visibility AnalyzeForForDotNet(
ComponentProviderViewModel vm)
{
var sourceVersion = new Version(vm.InstallationVersion!);
var destinationVersion = new Version(vm.InstalledVersion!);
return sourceVersion.IsNewerThan(destinationVersion)
? Visibility.Visible
: Visibility.Collapsed;
}
}

0 comments on commit 9438f98

Please sign in to comment.