Skip to content

Commit

Permalink
Merge pull request #67 from DNNCommunity/release/1.4.0
Browse files Browse the repository at this point in the history
Merge `release/1.4.0` into `main` for `1.4.0` release
  • Loading branch information
david-poindexter authored Mar 9, 2024
2 parents 48181a5 + 422c80a commit 2d9ea91
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Dnn.CommunityMetrics.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Dnn.CommunityMetrics</RootNamespace>
<AssemblyName>Dnn.CommunityMetrics</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<FileUpgradeFlags>
</FileUpgradeFlags>
Expand Down Expand Up @@ -172,7 +172,7 @@
<Version>9.11.1</Version>
</PackageReference>
<PackageReference Include="Octokit">
<Version>0.32.0</Version>
<Version>10.0.0</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
9 changes: 7 additions & 2 deletions Dnn.CommunityMetrics.dnn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<dotnetnuke type="Package" version="5.0">
<packages>
<package name="Dnn.CommunityMetrics" type="Module" version="01.03.00">
<package name="Dnn.CommunityMetrics" type="Module" version="01.03.01">
<friendlyName>Dnn.CommunityMetrics</friendlyName>
<description>Community Metrics</description>
<iconFile>~/images/icon_extensions_32px.png</iconFile>
Expand All @@ -17,7 +17,7 @@
<dependency type="CoreVersion">09.11.01</dependency>
</dependencies>
<components>
<component type="Cleanup" version="01.03.00" glob="DesktopModules/Dnn.CommunityMetrics/**/*" />
<component type="Cleanup" version="01.03.01" glob="DesktopModules/Dnn.CommunityMetrics/**/*" />
<component type="Script">
<scripts>
<basePath>DesktopModules\Dnn.CommunityMetrics</basePath>
Expand Down Expand Up @@ -78,6 +78,11 @@
<name>Dnn.CommunityMetrics.dll</name>
<path>bin</path>
</assembly>
<assembly>
<name>Octokit.dll</name>
<path>bin</path>
<version>10.0.0</version>
</assembly>
</assemblies>
</component>
<component type="ResourceFile">
Expand Down
30 changes: 26 additions & 4 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using BuildHelpers;
using Microsoft.Build.Tasks;
using Nuke.Common;
using Nuke.Common.ChangeLog;
Expand Down Expand Up @@ -99,8 +100,15 @@ class Build : NukeBuild
.DependsOn(Compile)
.Executes(() =>
{
var assembly = RootDirectory / "bin" / Configuration / $"{ProjectName}.dll";
CopyFileToDirectory(assembly, DnnBinDirectory, policy: FileExistsPolicy.Overwrite);
var files = RootDirectory.GlobFiles(
$"bin/Debug/*{ProjectName}*.dll",
$"bin/Debug/*{ProjectName}*.pdb",
"bin/Debug/Octokit.dll");
foreach (var file in files)
{
Helpers.CopyFileToDirectoryIfChanged(file, DnnBinDirectory);
}

});

Target Package => _ => _
Expand All @@ -112,7 +120,6 @@ class Build : NukeBuild
var stagingDirectory = RootDirectory / "staging";
var rootFiles = RootDirectory.GlobFiles("*.dnn", "LICENSE");
var rootResourceFiles = RootDirectory.GlobFiles("*.ascx", "*.css");
var assembly = RootDirectory / "bin" / Configuration / $"{ProjectName}.dll";
var appFolder = RootDirectory / "app";
var pluginsFolder = RootDirectory / "plugins";
var scriptsFolder = RootDirectory / "Scripts";
Expand All @@ -123,7 +130,22 @@ class Build : NukeBuild
CopyDirectoryRecursively(scriptsFolder, stagingDirectory / "Scripts", directoryPolicy: DirectoryExistsPolicy.Merge, filePolicy: FileExistsPolicy.Overwrite);
CopyDirectoryRecursively(appFolder, resourcesDirectory / "app", directoryPolicy: DirectoryExistsPolicy.Merge, filePolicy: FileExistsPolicy.Overwrite);
CopyDirectoryRecursively(pluginsFolder, resourcesDirectory / "plugins", directoryPolicy: DirectoryExistsPolicy.Merge, filePolicy: FileExistsPolicy.Overwrite);
CopyFileToDirectory(assembly, stagingDirectory / "bin", policy: FileExistsPolicy.Overwrite, createDirectories: true);

// Libraries
var manifest = RootDirectory.GlobFiles("*.dnn").FirstOrDefault();
var binDirectory = RootDirectory / "bin" / Configuration;
var assemblies = binDirectory.GlobFiles("*.dll");
var manifestAssemblies = Helpers.GetAssembliesFromManifest(manifest);
assemblies.ForEach(assembly =>
{
var assemblyFile = new FileInfo(assembly);
var assemblyIncludedInManifest = manifestAssemblies.Any(a => a == assemblyFile.Name);

if (assemblyIncludedInManifest)
{
CopyFileToDirectory(assembly, stagingDirectory / "bin", FileExistsPolicy.Overwrite);
}
});

resourcesDirectory.ZipTo(stagingDirectory / "resources.zip");
resourcesDirectory.DeleteDirectory();
Expand Down
117 changes: 117 additions & 0 deletions build/Helpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
using Newtonsoft.Json;
using Nuke.Common;
using Nuke.Common.IO;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Xml;
using static Nuke.Common.IO.FileSystemTasks;

namespace BuildHelpers
{
public class Helpers : NukeBuild
{
public static void CopyFileToDirectoryIfChanged(string source, string target)
{
var sourceFile = new FileInfo(source);
var destinationFile = new FileInfo(Path.Combine(target, sourceFile.Name));
var destinationExists = destinationFile.Exists;
var sameSize = destinationExists ? sourceFile.Length == destinationFile.Length : false;
var sameContent = true;

Serilog.Log.Debug("{0} is {1} Bytes", sourceFile.FullName, sourceFile.Length);
if (destinationExists)
{
Serilog.Log.Debug("{0} exists and is {1} Bytes", destinationFile.FullName, destinationFile.Length);
}

if (destinationExists && sameSize)
{
sameContent = FilesAreEqual(sourceFile, destinationFile);
Serilog.Log.Debug(sameContent ? "Both files have the same content" : "The files have different contents");
}

if (!destinationExists || !sameSize || !sameContent)
{
CopyFileToDirectory(source, target, Nuke.Common.IO.FileExistsPolicy.OverwriteIfNewer);
Serilog.Log.Information("Copied {0} to {1}", sourceFile.Name, destinationFile.DirectoryName);
Serilog.Log.Debug("\n");
}
else
{
Serilog.Log.Information("Skipped {0} since it is unchanged.", sourceFile.Name);
Serilog.Log.Debug("\n");
}
}

// Fast but accurate way to check if two files are difference (safer than write time for when rebuilding without changes).
private static bool FilesAreEqual(FileInfo first, FileInfo second)
{
const int BYTES_TO_READ = sizeof(long);
if (first.Length != second.Length)
{
return false;
}

if (string.Equals(first.FullName, second.FullName, StringComparison.OrdinalIgnoreCase))
{
return true;
}

int iterations = (int)Math.Ceiling((double)first.Length / BYTES_TO_READ);

using (FileStream fs1 = first.OpenRead())
{
using (FileStream fs2 = second.OpenRead())
{
byte[] one = new byte[BYTES_TO_READ];
byte[] two = new byte[BYTES_TO_READ];

for (int i = 0; i < iterations; i++)
{
fs1.Read(one, 0, BYTES_TO_READ);
fs2.Read(two, 0, BYTES_TO_READ);

if (BitConverter.ToInt64(one, 0) != BitConverter.ToInt64(two, 0))
{
return false;
}
}
}
}
return true;
}

public static void AddFilesToZip(string zipPath, IReadOnlyCollection<AbsolutePath> files)
{
if (files == null || files.Count == 0)
{
return;
}

using (var zipArchive = ZipFile.Open(zipPath, ZipArchiveMode.Update))
{
foreach (var file in files)
{
var fileInfo = new FileInfo(file);
zipArchive.CreateEntryFromFile(fileInfo.FullName, fileInfo.Name);
}
}
}

public static IEnumerable<string> GetAssembliesFromManifest(string manifestFilePath)
{
var doc = new XmlDocument();
doc.Load(manifestFilePath);
var nodes = doc.SelectNodes("dotnetnuke/packages/package/components/component[@type='Assembly']/assemblies/assembly/name");
List<string> assemblies = new List<string>();
foreach (XmlNode node in nodes)
{
assemblies.Add(node.InnerText);
}

return assemblies;
}
}
}

0 comments on commit 2d9ea91

Please sign in to comment.