Skip to content

Commit

Permalink
GitHubSync update
Browse files Browse the repository at this point in the history
  • Loading branch information
GeertvanHorrik committed Feb 24, 2021
1 parent 2058639 commit 19d2e73
Show file tree
Hide file tree
Showing 9 changed files with 646 additions and 10 deletions.
9 changes: 9 additions & 0 deletions deployment/cake/apps-wpf-tasks.cake
Expand Up @@ -232,6 +232,15 @@ public class WpfProcessor : ProcessorBase

BuildContext.CakeContext.LogSeparator($"Deploying WPF app '{wpfApp}'");

// TODO: Respect the deploy settings per category, requires changes to AzureStorageSync
if (!BuildContext.Wpf.DeployUpdatesToAlphaChannel ||
!BuildContext.Wpf.DeployUpdatesToBetaChannel ||
!BuildContext.Wpf.DeployUpdatesToStableChannel ||
!BuildContext.Wpf.DeployInstallers)
{
throw new Exception("Not deploying a specific channel is not yet supported, please implement");
}

//%DeploymentsShare%\%ProjectName% /%ProjectName% -c %AzureDeploymentsStorageConnectionString%
var deploymentShare = BuildContext.Wpf.GetDeploymentShareForProject(wpfApp);
var projectSlug = GetProjectSlug(wpfApp, "-");
Expand Down
22 changes: 21 additions & 1 deletion deployment/cake/apps-wpf-variables.cake
Expand Up @@ -16,6 +16,13 @@ public class WpfContext : BuildContextWithItemsBase
public bool UpdateDeploymentsShare { get; set; }
public string AzureDeploymentsStorageConnectionString { get; set; }

public bool GenerateDeploymentCatalog { get; set; }
public bool GroupUpdatesByMajorVersion { get; set; }
public bool DeployUpdatesToAlphaChannel { get; set; }
public bool DeployUpdatesToBetaChannel { get; set; }
public bool DeployUpdatesToStableChannel { get; set; }
public bool DeployInstallers { get; set; }

protected override void ValidateContext()
{

Expand All @@ -24,6 +31,13 @@ public class WpfContext : BuildContextWithItemsBase
protected override void LogStateInfoForContext()
{
CakeContext.Information($"Found '{Items.Count}' wpf projects");

CakeContext.Information($"Generate Deployment Catalog: '{GenerateDeploymentCatalog}'");
CakeContext.Information($"Group updates by major version: '{GroupUpdatesByMajorVersion}'");
CakeContext.Information($"Deploy updates to alpha channel: '{DeployUpdatesToAlphaChannel}'");
CakeContext.Information($"Deploy updates to beta channel: '{DeployUpdatesToBetaChannel}'");
CakeContext.Information($"Deploy updates to stable channel: '{DeployUpdatesToStableChannel}'");
CakeContext.Information($"Deploy installers: '{DeployInstallers}'");
}

public string GetDeploymentShareForProject(string projectName)
Expand All @@ -46,7 +60,13 @@ private WpfContext InitializeWpfContext(BuildContext buildContext, IBuildContext
Channel = buildContext.BuildServer.GetVariable("Channel", showValue: true),
AppendDeploymentChannelSuffix = buildContext.BuildServer.GetVariableAsBool("AppendDeploymentChannelSuffix", false, showValue: true),
UpdateDeploymentsShare = buildContext.BuildServer.GetVariableAsBool("UpdateDeploymentsShare", true, showValue: true),
AzureDeploymentsStorageConnectionString = buildContext.BuildServer.GetVariable("AzureDeploymentsStorageConnectionString")
AzureDeploymentsStorageConnectionString = buildContext.BuildServer.GetVariable("AzureDeploymentsStorageConnectionString"),
GenerateDeploymentCatalog = buildContext.BuildServer.GetVariableAsBool("WpfGenerateDeploymentCatalog", true, showValue: true),
GroupUpdatesByMajorVersion = buildContext.BuildServer.GetVariableAsBool("WpfGroupUpdatesByMajorVersion", false, showValue: true),
DeployUpdatesToAlphaChannel = buildContext.BuildServer.GetVariableAsBool("WpfDeployUpdatesToAlphaChannel", true, showValue: true),
DeployUpdatesToBetaChannel = buildContext.BuildServer.GetVariableAsBool("WpfDeployUpdatesToBetaChannel", true, showValue: true),
DeployUpdatesToStableChannel = buildContext.BuildServer.GetVariableAsBool("WpfDeployUpdatesToStableChannel", true, showValue: true),
DeployInstallers = buildContext.BuildServer.GetVariableAsBool("WpfDeployInstallers", true, showValue: true),
};

if (string.IsNullOrWhiteSpace(data.Channel))
Expand Down
27 changes: 27 additions & 0 deletions deployment/cake/generic-variables.cake
Expand Up @@ -125,6 +125,33 @@ public class VersionContext : BuildContextBase
}

public bool ClearCache { get; set; }

private string _major;

public string Major
{
get
{
if (string.IsNullOrWhiteSpace(_major))
{
_major = string.Empty;

for (int i = 0; i < MajorMinorPatch.Length; i++)
{
var character = MajorMinorPatch[i];
if (!char.IsDigit(character))
{
break;
}

_major += character.ToString();
}
}

return _major;
}
}

public string MajorMinorPatch { get; set; }
public string FullSemVer { get; set; }
public string NuGet { get; set; }
Expand Down
122 changes: 122 additions & 0 deletions deployment/cake/installers-innosetup.cake
Expand Up @@ -21,6 +21,8 @@ public class InnoSetupInstaller : IInstaller

public bool IsAvailable { get; private set; }

//-------------------------------------------------------------

public async Task PackageAsync(string projectName, string channel)
{
if (!IsAvailable)
Expand Down Expand Up @@ -100,4 +102,124 @@ public class InnoSetupInstaller : IInstaller
BuildContext.CakeContext.CopyFile(installerSourceFile, System.IO.Path.Combine(installersOnDeploymentsShare, $"{projectName}{setupSuffix}.exe"));
}
}

//-------------------------------------------------------------

public async Task<DeploymentTarget> GenerateDeploymentTargetAsync(string projectName)
{
var deploymentTarget = new DeploymentTarget
{
Name = "Inno Setup"
};

var channels = new []
{
"alpha",
"beta",
"stable"
};

var deploymentGroupNames = new List<string>();
var projectDeploymentShare = BuildContext.Wpf.GetDeploymentShareForProject(projectName);

// Just a single group
deploymentGroupNames.Add("all");

foreach (var deploymentGroupName in deploymentGroupNames)
{
BuildContext.CakeContext.Information($"Searching for releases for deployment group '{deploymentGroupName}'");

var deploymentGroup = new DeploymentGroup
{
Name = deploymentGroupName
};

foreach (var channel in channels)
{
BuildContext.CakeContext.Information($"Searching for releases for deployment channel '{deploymentGroupName}/{channel}'");

var deploymentChannel = new DeploymentChannel
{
Name = channel
};

var targetDirectory = GetDeploymentsShareRootDirectory(projectName, channel);

BuildContext.CakeContext.Information($"Searching for release files in '{targetDirectory}'");

var filter = $"{projectName}_*{channel}*.exe";
if (channel == "stable")
{
filter = $"{projectName}_*.exe";
}

var installationFiles = System.IO.Directory.GetFiles(targetDirectory, filter);

foreach (var installationFile in installationFiles)
{
var releaseFileInfo = new System.IO.FileInfo(installationFile);
var relativeFileName = new DirectoryPath(projectDeploymentShare).GetRelativePath(new FilePath(releaseFileInfo.FullName)).FullPath.Replace("\\", "/");

var releaseVersion = releaseFileInfo.Name
.Replace($"{projectName}", string.Empty)
.Replace($".exe", string.Empty)
.Trim('_');

// Either empty or matching a release channel should be ignored
if (string.IsNullOrWhiteSpace(releaseVersion) ||
channels.Any(x => x == releaseVersion))
{
BuildContext.CakeContext.Information($"Ignoring '{installationFile}'");
continue;
}

// Special case for stable releases
if (channel == "stable")
{
if (releaseVersion.Contains("-alpha") ||
releaseVersion.Contains("-beta"))
{
BuildContext.CakeContext.Information($"Ignoring '{installationFile}'");
continue;
}
}

BuildContext.CakeContext.Information($"Applying release based on '{installationFile}'");

var release = new DeploymentRelease
{
Name = releaseVersion,
Timestamp = releaseFileInfo.CreationTimeUtc
};

// Full release
release.Full = new DeploymentReleasePart
{
RelativeFileName = relativeFileName,
Size = (ulong)releaseFileInfo.Length
};

deploymentChannel.Releases.Add(release);
}

deploymentGroup.Channels.Add(deploymentChannel);
}

deploymentTarget.Groups.Add(deploymentGroup);
}

return deploymentTarget;
}

//-------------------------------------------------------------

private string GetDeploymentsShareRootDirectory(string projectName, string channel)
{
var deploymentShare = BuildContext.Wpf.GetDeploymentShareForProject(projectName);

var installersOnDeploymentsShare = System.IO.Path.Combine(deploymentShare, "installer");
BuildContext.CakeContext.CreateDirectory(installersOnDeploymentsShare);

return installersOnDeploymentsShare;
}
}

0 comments on commit 19d2e73

Please sign in to comment.