Skip to content

Commit e8b341d

Browse files
committed
Merge branch 'move-to-tailwind' of https://github.com/ix-ax/axsharp into move-to-tailwind
2 parents d7d151d + 0c62146 commit e8b341d

11 files changed

Lines changed: 361 additions & 4 deletions

File tree

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,4 +406,7 @@ ix/.g/**
406406
/src/apax/stc-generic-x64
407407
TestResults/
408408

409-
operon/
409+
operon/
410+
411+
# Apax packages
412+
*.apax.tgz

GitVersion.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
mode: ContinuousDeployment
2-
next-version: 0.24.0
2+
next-version: 0.30.0
33
branches:
44
main:
55
regex: ^master$|^main$

cake/ApaxCmd.cs

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// Build
2+
// Copyright (c) 2023 MTS spol. s r.o, and Contributors. All Rights Reserved.
3+
// Contributors: https://github.com/inxton/AXOpen/graphs/contributors
4+
// See the LICENSE file in the repository root for more information.
5+
// https://github.com/inxton/AXOpen/blob/master/LICENSE
6+
// Third party licenses: https://github.com/inxton/AXOpen/blob/master/notices.md
7+
8+
using System;
9+
using System.IO;
10+
using System.Text;
11+
using Cake.Core.IO;
12+
using Path = System.IO.Path;
13+
14+
public static class ApaxCmd
15+
{
16+
public static void UpdateApaxVersion(this BuildContext context, string file, string version)
17+
{
18+
var sb = new StringBuilder();
19+
foreach (var line in System.IO.File.ReadLines(file))
20+
{
21+
var newLine = line;
22+
23+
if (line.Trim().StartsWith("version"))
24+
{
25+
var semicPosition = line.IndexOf(":");
26+
var lenght = line.Length - semicPosition;
27+
28+
newLine = $"{line.Substring(0, semicPosition)} : '{version}'";
29+
}
30+
31+
sb.AppendLine(newLine);
32+
}
33+
34+
System.IO.File.WriteAllText(file, sb.ToString());
35+
}
36+
37+
public static void ApaxPack(this BuildContext context, string apaxFolder)
38+
{
39+
{
40+
context.ProcessRunner.Start(Helpers.GetApaxCommand(), new ProcessSettings()
41+
{
42+
Arguments = $"pack --key={context.ApaxSignKey}",
43+
WorkingDirectory = apaxFolder,
44+
RedirectStandardOutput = false,
45+
RedirectStandardError = false,
46+
Silent = false
47+
}).WaitForExit();
48+
}
49+
}
50+
51+
public static void ApaxCopyArtifacts(this BuildContext context, string folder, string name)
52+
{
53+
var packageFile = $"{context.ApaxRegistry}-{name}-{GitVersionInformation.SemVer}.apax.tgz";
54+
var sourceFile = Path.Combine(folder, packageFile);
55+
File.Copy(sourceFile, Path.Combine(context.ArtifactsApax, packageFile));
56+
}
57+
58+
public static void ApaxPublishAllArtefacts(this BuildContext context)
59+
{
60+
context.ProcessRunner.Start(Helpers.GetApaxCommand(), new ProcessSettings()
61+
{
62+
Arguments =
63+
$"login --registry https://npm.pkg.github.com --username {context.GitHubUser} --password {context.GitHubToken}",
64+
WorkingDirectory = context.ArtifactsApax,
65+
RedirectStandardOutput = false,
66+
RedirectStandardError = false,
67+
Silent = false
68+
}).WaitForExit();
69+
70+
foreach (var apaxPackageFile in Directory.EnumerateFiles(context.ArtifactsApax))
71+
{
72+
var process = context.ProcessRunner.Start(Helpers.GetApaxCommand(), new ProcessSettings()
73+
{
74+
Arguments = $"publish -p {apaxPackageFile} -r https://npm.pkg.github.com",
75+
WorkingDirectory = context.ArtifactsApax,
76+
RedirectStandardOutput = false,
77+
RedirectStandardError = false,
78+
Silent = false
79+
});
80+
81+
process.WaitForExit();
82+
83+
if (process.GetExitCode() != 0)
84+
{
85+
throw new PublishFailedException();
86+
}
87+
}
88+
}
89+
}
90+
91+
public class PublishFailedException : Exception
92+
{
93+
}

cake/ApaxFile.cs

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// Copyright (c) 2023 MTS spol. s r.o, and Contributors. All Rights Reserved.
2+
// Contributors: https://github.com/inxton/AXOpen/graphs/contributors
3+
// See the LICENSE file in the repository root for more information.
4+
// https://github.com/inxton/AXOpen/blob/master/LICENSE
5+
// Third party licenses: https://github.com/inxton/AXOpen/blob/master/notices.md
6+
7+
using System.Collections.Generic;
8+
using System.IO;
9+
using YamlDotNet.Serialization.NamingConventions;
10+
using YamlDotNet.Serialization;
11+
12+
13+
public class ApaxFile
14+
{
15+
//
16+
// Summary:
17+
// Gets or sets ax project name.
18+
public string? Name { get; set; }
19+
20+
//
21+
// Summary:
22+
// Ax project type.
23+
public string? Type { get; set; }
24+
25+
//
26+
// Summary:
27+
// Gets or sets the version of the AX project.
28+
public string? Version { get; set; }
29+
30+
//
31+
// Summary:
32+
// Gets or sets ax targets.
33+
public IEnumerable<string>? Targets { get; set; }
34+
35+
//
36+
// Summary:
37+
// Gets or sets ax project files to include in package.
38+
public IEnumerable<string>? Files { get; set; }
39+
40+
//
41+
// Summary:
42+
// Gets or sets ax projects development dependencies.
43+
public IDictionary<string, string>? DevDependencies { get; set; }
44+
45+
//
46+
// Summary:
47+
// Gets or sets ax projects dependencies.
48+
public IDictionary<string, string>? Dependencies { get; set; }
49+
50+
51+
public IDictionary<string, string>? Catalogs { get; set; }
52+
53+
public string? Registries { get; set; }
54+
55+
public string InstallStrategy { get; set; }
56+
57+
public string ApaxVersion { get; set; }
58+
59+
public Dictionary<string, string> Scripts { get; set; }
60+
61+
//
62+
// Summary:
63+
// Creates new instance of AXSharp.Compiler.Apax.
64+
//
65+
// Parameters:
66+
// projectFile:
67+
// Project file from which the ApaxFile object will be created.
68+
//
69+
// Exceptions:
70+
// T:System.IO.FileNotFoundException:
71+
public static ApaxFile CreateApaxDto(string projectFile)
72+
{
73+
try
74+
{
75+
return new DeserializerBuilder().WithNamingConvention(CamelCaseNamingConvention.Instance).IgnoreUnmatchedProperties().Build()
76+
.Deserialize<ApaxFile>(File.ReadAllText(projectFile));
77+
}
78+
catch (FileNotFoundException)
79+
{
80+
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)");
81+
}
82+
}
83+
84+
public static void UpdateDependencyVersions(string apaxFile, string version)
85+
{
86+
try
87+
{
88+
var apax = CreateApaxDto(apaxFile);
89+
90+
91+
foreach (var dependency in apax.Dependencies)
92+
{
93+
// dependency = new KeyValuePair<string, string>(dependency.Key, version);
94+
}
95+
96+
97+
using (var tw = new StreamWriter(apaxFile))
98+
{
99+
var serializer = new SerializerBuilder()
100+
.WithNamingConvention(CamelCaseNamingConvention.Instance)
101+
.Build();
102+
103+
serializer.Serialize(tw, apax);
104+
}
105+
}
106+
catch (FileNotFoundException)
107+
{
108+
throw new FileNotFoundException(
109+
"'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)");
110+
}
111+
}
112+
}

cake/Build.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
<PackageReference Include="Cake.Powershell" />
1616
<PackageReference Include="Polly" />
1717
<PackageReference Include="System.IO.Packaging" />
18-
<PackageReference Include="System.Text.Json" />
18+
<PackageReference Include="System.Text.Json" />
19+
<PackageReference Include="YamlDotNet"/>
1920
</ItemGroup>
2021
<ItemGroup>
2122
<ProjectReference Include="..\src\AXSharp.tools\src\AXSharp.nuget.update\AXSharp.nuget.update.csproj" />

cake/BuildContext.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
using Cake.Core.Diagnostics;
2323
using Cake.Core.IO;
2424
using Cake.Frosting;
25+
using System.Formats.Tar;
26+
using System.IO.Compression;
2527
using Polly;
2628
using static NuGet.Packaging.PackagingConstants;
2729
using Path = System.IO.Path;
@@ -30,8 +32,13 @@ public class BuildContext : FrostingContext
3032
{
3133
public string Artifacts => Path.Combine(Environment.WorkingDirectory.FullPath, "..//artifacts//");
3234

35+
public string ArtifactsApax => Path.Combine(Environment.WorkingDirectory.FullPath, "..//artifacts//apax//");
36+
3337
public string TestResults => Path.Combine(Environment.WorkingDirectory.FullPath, "..//TestResults//");
3438

39+
public string RootDir => Path.GetFullPath(Path.Combine(Environment.WorkingDirectory.FullPath, "..//src//"));
40+
public string ApaxRegistry => "inxton";
41+
3542
public string WorkDirName => Environment.WorkingDirectory.GetDirectoryName();
3643

3744
public string DocumentationOutputDir => Path.GetFullPath(Path.Combine(Environment.WorkingDirectory.FullPath, "..//docs//"));
@@ -179,6 +186,11 @@ public void PushNugetPackages(string artifactDirectory)
179186
}
180187

181188
public IEnumerable<string> TargetFrameworks { get; } = new List<string>() { "net9.0", "net8.0" };
189+
public string ApaxSignKey { get; set; } = System.Environment.GetEnvironmentVariable("APAX_KEY");
190+
public string GitHubUser { get; set; } = System.Environment.GetEnvironmentVariable("GH_USER");
191+
public string GitHubToken { get; set; } = System.Environment.GetEnvironmentVariable("GH_TOKEN");
192+
193+
182194

183195
public IEnumerable<(string ax, string approject, string solution)> GetTemplateProjects()
184196
{
@@ -258,5 +270,38 @@ public void CheckLicenseComplianceInArtifacts()
258270
Directory.Delete(ouptutDir, true);
259271
}
260272
}
273+
274+
try
275+
{
276+
foreach (var apaxPackageFile in Directory.EnumerateFiles(this.Artifacts, "*.apax.tgz", SearchOption.AllDirectories))
277+
{
278+
var outputDir = Path.Combine(this.Artifacts, "apax-verif");
279+
// ensure clean folder
280+
if (Directory.Exists(outputDir))
281+
Directory.Delete(outputDir, true);
282+
Directory.CreateDirectory(outputDir);
283+
284+
// open .tgz, gunzip it, then untar into outputDir
285+
using var fs = File.OpenRead(apaxPackageFile);
286+
using var gz = new GZipStream(fs, CompressionMode.Decompress);
287+
TarFile.ExtractToDirectory(gz, outputDir, true);
288+
289+
// now scan extracted files
290+
if (Directory.EnumerateFiles(outputDir, "*.*", SearchOption.AllDirectories)
291+
.Select(p => new FileInfo(p))
292+
.Any(p => licensedFiles.Any(l => l.Name == p.Name)))
293+
{
294+
throw new Exception("License violation detected in .apax.tgz");
295+
}
296+
297+
Directory.Delete(outputDir, true);
298+
}
299+
}
300+
catch (Exception e)
301+
{
302+
Console.WriteLine(e);
303+
throw;
304+
}
305+
261306
}
262307
}

cake/Program.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,26 @@ private static void PackPackages(BuildContext context, string solutionToPack)
236236
NoRestore = true,
237237
NoBuild = false,
238238
});
239+
240+
var apaxConstributedToPack = new (string folder, string name)[]
241+
{
242+
(Path.Combine(context.ScrDir, "AXSharp.compiler\\src\\ixc\\"), "axsharp-ixc"),
243+
(Path.Combine(context.ScrDir, "AXSharp.compiler\\src\\ixr\\"), "axsharp-ixr"),
244+
(Path.Combine(context.ScrDir, "AXSharp.compiler\\src\\ixd\\"), "axsharp-ixd"),
245+
};
246+
247+
// Ensure articfats directory exists
248+
if (!Directory.Exists(context.ArtifactsApax))
249+
{
250+
context.CreateDirectory(context.ArtifactsApax);
251+
}
252+
253+
254+
apaxConstributedToPack.ToList().ForEach(p =>
255+
context.UpdateApaxVersion(Path.Combine(p.folder, "apax.yml"), GitVersionInformation.SemVer));
256+
apaxConstributedToPack.ToList().ForEach(p => context.ApaxPack(p.folder));
257+
apaxConstributedToPack.ToList().ForEach(p => context.ApaxCopyArtifacts(p.folder, p.name));
258+
239259
}
240260
}
241261

@@ -284,6 +304,7 @@ public override void Run(BuildContext context)
284304
}
285305

286306
context.PushNugetPackages("nugets");
307+
context.ApaxPublishAllArtefacts();
287308
}
288309
}
289310

src/AXSharp.compiler/src/ixc/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ private static void DisplayInfo()
111111

112112

113113
Console.ForegroundColor = ConsoleColor.Magenta;
114-
Console.WriteLine($"Using version '{LegalAcrobatics.StcVersion}' of stc.");
114+
Console.WriteLine($"Using version '> {LegalAcrobatics.StcVersion}' of stc.");
115115
Console.ForegroundColor = originalColor;
116116

117117
if (int.Parse(GitVersionInformation.Major) < 1 || string.IsNullOrEmpty(GitVersionInformation.PreReleaseLabel))
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: "@inxton/axsharp-ixc"
2+
description: "AX#Sharp twin compiler"
3+
version : '0.0.0-dev.0'
4+
type: generic
5+
keywords:
6+
- "compiler"
7+
- "twin"
8+
- "AX#"
9+
- "SIMATIC-AX"
10+
- "PLC"
11+
- "IT-OT"
12+
homepage: "https://inxton.github.io/axsharp/articles/compiler/README.html"
13+
repository:
14+
type: "git"
15+
url: "https://github.com/Inxton/axsharp"
16+
bugs:
17+
url: "https://github.com/Inxton/axsharp/issues?q=is%3Aissue%20state%3Aopen%20label%3Abug"
18+
license: "MIT"
19+
author: "https://github.com/Inxton/axsharp/graphs/contributors"
20+
files:
21+
- "bin/Release/net9.0/**"
22+
- "!bin/Release/net9.0/.apax/.apax/**"
23+
contributedCommands:
24+
ixc:
25+
bin: "bin/Release/net9.0/AXSharp.ixc.exe"
26+
description: "AX#Sharp twin compiler"
27+
hidden: false
28+

0 commit comments

Comments
 (0)