Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

563 fix cake to do not touch catalog version #566

Merged
merged 17 commits into from
Jan 30, 2025
Merged
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
1 change: 0 additions & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ on:
- dev
schedule:
- cron: '0 0 * * *'

jobs:
nightly:
runs-on: [self-hosted, Windows, X64, AX, APP]
Expand Down
112 changes: 112 additions & 0 deletions cake/ApaxFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// Copyright (c) 2023 MTS spol. s r.o, and Contributors. All Rights Reserved.
// Contributors: https://github.com/inxton/AXOpen/graphs/contributors
// See the LICENSE file in the repository root for more information.
// https://github.com/inxton/AXOpen/blob/master/LICENSE
// Third party licenses: https://github.com/inxton/AXOpen/blob/master/notices.md

using System.Collections.Generic;
using System.IO;
using YamlDotNet.Serialization.NamingConventions;
using YamlDotNet.Serialization;


public class ApaxFile
{
//
// Summary:
// Gets or sets ax project name.
public string? Name { get; set; }

//
// Summary:
// Ax project type.
public string? Type { get; set; }

//
// Summary:
// Gets or sets the version of the AX project.
public string? Version { get; set; }

//
// Summary:
// Gets or sets ax targets.
public IEnumerable<string>? Targets { get; set; }

//
// Summary:
// Gets or sets ax project files to include in package.
public IEnumerable<string>? Files { get; set; }

//
// Summary:
// Gets or sets ax projects development dependencies.
public IDictionary<string, string>? DevDependencies { get; set; }

//
// Summary:
// Gets or sets ax projects dependencies.
public IDictionary<string, string>? Dependencies { get; set; }


public IDictionary<string, string>? Catalogs { get; set; }

public string? Registries { get; set; }

public string InstallStrategy { get; set; }

public string ApaxVersion { get; set; }

public Dictionary<string, string> Scripts { get; set; }

//
// Summary:
// Creates new instance of AXSharp.Compiler.Apax.
//
// Parameters:
// projectFile:
// Project file from which the ApaxFile object will be created.
//
// Exceptions:
// T:System.IO.FileNotFoundException:
public static ApaxFile CreateApaxDto(string projectFile)
{
try
{
return new DeserializerBuilder().WithNamingConvention(CamelCaseNamingConvention.Instance).IgnoreUnmatchedProperties().Build()
.Deserialize<ApaxFile>(File.ReadAllText(projectFile));
}
catch (FileNotFoundException)
{
throw new FileNotFoundException("'apax.yml' file was not found in the working directory. Make sure your current directory is simatic-ax project directory or provide source directory argument (for details see ixc --help)");
}
}

public static void UpdateDependencyVersions(string apaxFile, string version)
{
try
{
var apax = CreateApaxDto(apaxFile);


foreach (var dependency in apax.Dependencies)
{
// dependency = new KeyValuePair<string, string>(dependency.Key, version);
}


using (var tw = new StreamWriter(apaxFile))
{
var serializer = new SerializerBuilder()
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.Build();

serializer.Serialize(tw, apax);
}
}
catch (FileNotFoundException)
{
throw new FileNotFoundException(
"'apax.yml' file was not found in the working directory. Make sure your current directory is simatic-ax project directory or provide source directory argument (for details see ixc --help)");
}
}
}
6 changes: 3 additions & 3 deletions cake/Build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CliWrap" Version="3.6.4" />
<PackageReference Include="CliWrap" Version="3.6.7" />
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="Octokit" Version="8.0.0" />
<PackageReference Include="Octokit.Extensions" Version="1.0.7" />
<PackageReference Include="Cake.Frosting" Version="4.0.0" />
<PackageReference Include="Cake.Powershell" Version="4.0.0" />
<PackageReference Include="Polly" Version="7.2.4" />
<PackageReference Include="Polly" Version="8.5.0" />
<PackageReference Include="GitVersion.MsBuild" Version="5.12.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="YamlDotNet" Version="15.1.0" />
<PackageReference Include="YamlDotNet" Version="16.2.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="FilteredSolution\" />
Expand Down
26 changes: 16 additions & 10 deletions cake/BuildContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
using System;
using YamlDotNet.RepresentationModel;

public class BuildContext : FrostingContext

public partial class BuildContext : FrostingContext
{

public bool IsGitHubActions { get; set; }
Expand All @@ -41,7 +42,14 @@ public void UpdateApaxVersion(string file, string version)
foreach (var line in System.IO.File.ReadLines(file))
{
var newLine = line;

if (line.Trim().StartsWith("name"))
{
// Do not change the version of the catalog in the declaration field
if (line.Contains(".catalog"))
{
return;
}
}
if (line.Trim().StartsWith("version"))
{
var semicPosition = line.IndexOf(":");
Expand All @@ -55,22 +63,20 @@ public void UpdateApaxVersion(string file, string version)
System.IO.File.WriteAllText(file, sb.ToString());
}

public void UpdateApaxDependencies(string file, IEnumerable<string> dependencies, string version)
public void UpdateApaxDependencies(string file, string version)
{
var sb = new StringBuilder();
foreach (var line in System.IO.File.ReadLines(file))
{
var newLine = line;

foreach (var dependency in dependencies.Select(p => $"\"@{ApaxRegistry}/{p}\""))
// Do not change the version of the catalog when used
if (line.Trim().StartsWith($"\"@{ApaxRegistry}/") && line.Contains(":") && !line.Contains(".catalog"))
{
if (line.Trim().StartsWith($"\"@{ApaxRegistry}/") && line.Contains(":"))
{
var semicPosition = line.IndexOf(":");
var lenght = line.Length - semicPosition;
var semicPosition = line.IndexOf(":");
var lenght = line.Length - semicPosition;

newLine = $"{line.Substring(0, semicPosition)} : '{version}'";
}
newLine = $"{line.Substring(0, semicPosition)} : '{version}'";
}

sb.AppendLine(newLine);
Expand Down
29 changes: 2 additions & 27 deletions cake/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,33 +134,8 @@ private static void ProvisionTools(BuildContext context)
}
}

[TaskName("ApaxUpdate")]
[IsDependentOn(typeof(ProvisionTask))]
public sealed class ApaxUpdateTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
if (context.BuildParameters.PublishOnly)
{
context.Log.Information("Skipping. Publish only.");
return;
}

if (!context.BuildParameters.DoApaxUpdate)
return;

context.Libraries.ToList().ForEach(lib =>
{
context.ApaxUpdate(lib);
});

context.DotNetBuild(Path.Combine(context.RootDir, "AXOpen.proj"), context.DotNetBuildSettings);
}
}


[TaskName("CatalogInstall")]
[IsDependentOn(typeof(ApaxUpdateTask))]
[IsDependentOn(typeof(ProvisionTask))]
public sealed class CatalogInstallTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
Expand Down Expand Up @@ -202,7 +177,7 @@ public override void Run(BuildContext context)
foreach (var apaxfile in context.GetApaxFiles(lib))
{
context.UpdateApaxVersion(apaxfile, GitVersionInformation.SemVer);
context.UpdateApaxDependencies(apaxfile, context.Libraries.Select(p => context.GetApaxFile(p)), GitVersionInformation.SemVer);
context.UpdateApaxDependencies(apaxfile, GitVersionInformation.SemVer);
}
});

Expand Down
Loading