Skip to content
This repository has been archived by the owner on Feb 10, 2025. It is now read-only.

Commit

Permalink
9 create scaffolding cli for templates (#15)
Browse files Browse the repository at this point in the history
* cake build added

* Create draft PR for #3

* Create draft PR for #9

* scaffolding cli with basic functionality

* scafollding folder structure reorginized

* fixed folder names in test folder

* added inpch into option for wpf update

* additions to readme

* gh action files added

* build

* asp builds

* asp

* [mts-s-tempate][cake] fixed in issue with retrieval of ivc

* asp

* asp

* asp

* test onagent fixies

* relase only from dev branch

* asp

* wip

* [mts-s-template][fix] cu create script fixed paths

* cake unified into single project

* [wip] scaffolder runs using updater

* various improvement to build, version bump for further updater testing

* um batch file added to .tools folder

* [mts-s-tempalte] implements embedded ravendb

* raven directed to bin folder

* [mts-s-template][test-fix] after raven embedded

* [scaffolder] gets location form executing assembly instead of entry assembly to determine the location.

* [scaffold][fix] attempt to solve updater path

Co-authored-by: PTKu <[email protected]>
  • Loading branch information
PTKu and PTKu authored May 23, 2022
1 parent 264cecc commit f03dd6d
Show file tree
Hide file tree
Showing 37 changed files with 679 additions and 262 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ jobs:
path : '.'
fetch-depth: 0
- name: Cake
env:
gh-public-repos: ${{ secrets.TCOPENTEMPLATESPAT }}
run: >
.\build.ps1
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,7 @@ nugets/

# VSCode
.vscode/

# CI/CD
artifacts/
.tools/
30 changes: 30 additions & 0 deletions .tools/um/3.1/TcRegistry.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0"?>
<TcRegistry>
<Key Name="HKLM">
<Key Name="Software">
<Key Name="Beckhoff">
<Key Name="TwinCAT3">
<Value Name="CurrentVersion" Type="SZ">3.1</Value>
<Key Name="System">
<Value Name="RunAsDevice" Type="DW">1</Value>
<Value Name="AmsNetId" Type="BIN">C0A804010101</Value>
<Value Name="LockedMemSize" Type="DW">33554432</Value>
</Key>
<Key Name="3.1">
<Value Name="BootDir" Type="SZ">.\3.1\Boot\</Value>
<Value Name="ConfigDir" Type="SZ">.\3.1\Config\</Value>
<Value Name="InstallDir" Type="SZ">.\3.1\</Value>
<Value Name="TargetDir" Type="SZ">.\3.1\Target\</Value>
<Value Name="DriverAutoLoadDir" Type="SZ">.\3.1\Driver\AutoLoad\</Value>
</Key>
<Key Name="EventLogger">
<Value Name="LastUniqueId" Type="DW">0</Value>
</Key>
</Key>
</Key>
</Key>
<Key Name="Ident">
<Value Name="DeviceType" Type="SZ">PC-WIN-U</Value>
</Key>
</Key>
</TcRegistry>
7 changes: 7 additions & 0 deletions .tools/um/Start.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@echo off

set TC_RT_INST_NETID=192.168.4.1.1.1
set TC_RT_INST_BUILD=4024.22

for %%I in (.) do set TC_INST_NAME=%%~nxI
%TWINCAT3DIR%Runtimes\bin\Build_%TC_RT_INST_BUILD%\TcSystemServiceUm.exe -i %TC_RT_INST_NETID% -n %TC_INST_NAME% -c ".\3.1"
2 changes: 1 addition & 1 deletion GitVersion.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mode: ContinuousDeployment
next-version: 0.1.0
next-version: 0.1.1
branches: {}
ignore:
sha: []
Expand Down
17 changes: 10 additions & 7 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
$root = Get-Location
Set-Location .\templates\mts-s-template\
./build.ps1
Set-Location $root
# dotnet run --project cake/Build.csproj -- $args
# We need to use msbuild instead of dotnet due to COMrefs in the project.

Set-Location .\scaffolder\TcOpen.Scaffold\
./build.ps1
Set-Location $root
$msbuild =([System.Environment]::GetEnvironmentVariable('TcoMsbuild'))
cd cake
dotnet restore Build.csproj

& $msbuild Build.csproj /t:Rebuild /p:Configuration=Release /p:Platform=AnyCPU /p:TargetFramework=net5.0 /p:DefineConstants=Release $args
.\bin\Release\net5.0\Build.exe $args
cd ..
exit $LASTEXITCODE;
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
<ItemGroup>
<PackageReference Include="Cake.Frosting" Version="2.2.0" />
<PackageReference Include="envdte100" Version="17.2.32505.113" />
<PackageReference Include="Cake.Frosting" Version="2.2.0" />
<PackageReference Include="GitVersion.MsBuild" Version="5.10.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Octokit" Version="0.51.0" />
<PackageReference Include="Octokit.Extensions" Version="1.0.7" />
<PackageReference Include="System.IO.Compression.ZipFile" Version="4.3.0" />
<PackageReference Include="NuGet.CommandLine" Version="6.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,45 @@
using Build;
using Cake.Core;
using Cake.Core.Diagnostics;
using Cake.Frosting;
using EnvDTE;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.IO.Compression;
using TCatSysManagerLib;

namespace mts_s_template
namespace Build
{
public class BuildContext : FrostingContext
{
public string RootRepository => Path.GetFullPath(Path.Combine(Environment.WorkingDirectory.FullPath, ".."));
public string TemplateDirectory => Path.GetFullPath(Path.Combine(Environment.WorkingDirectory.FullPath, "../t"));

public bool CleanEnabled { get; private set; }

public string TemplateTestsDirectory => Path.GetFullPath(Path.Combine(TemplateDirectory, "tests"));
public void ZipFolder(string sourceFolder, string destinationFile)
{
var outputDirectory = new FileInfo(destinationFile).Directory;

if (!outputDirectory.Exists)
{
outputDirectory.Create();
}

System.IO.Compression.ZipFile.CreateFromDirectory(sourceFolder, destinationFile);
}

private readonly string _artifactsFolder;
private readonly string _toolsFolder;

public string ArtifactsFolder => _artifactsFolder;

public string ToolsFolder => _toolsFolder;

public string ProjectRootDirectory { get; set; }
public string TemplateDirectory => System.IO.Path.Combine(ProjectRootDirectory, "t");

public string TemplateTestsDirectory => System.IO.Path.GetFullPath(System.IO.Path.Combine(TemplateDirectory, "tests"));

public IEnumerable<string> TemplateTestFiles => Directory.EnumerateFiles(TemplateTestsDirectory, "*test*.dll", SearchOption.AllDirectories)
.Concat(Directory.EnumerateFiles(TemplateTestsDirectory, "*Test*.dll", SearchOption.AllDirectories));
Expand All @@ -32,7 +55,7 @@ public void RunIvc(string solutionFile)
EnvDTE.DTE dte = GetVsInstance(solutionFile);

var solutionFileInfo = new FileInfo(solutionFile).Directory;
var pathToIvc = Path.Combine(solutionFileInfo.FullName, "_Vortex\\builder\\vortex.compiler.console.exe");
var pathToIvc = System.IO.Path.Combine(solutionFileInfo.FullName, "_Vortex\\builder\\vortex.compiler.console.exe");
// var vsProcess = ProcessRunner.Start($"{Environment.GetEnvironmentVariable("TcoDevenv")}", new Cake.Core.IO.ProcessSettings() { Arguments = $"{solutionFile}" });
var ivcProcess = ProcessRunner.Start(pathToIvc, new Cake.Core.IO.ProcessSettings() { Arguments = $"-s {solutionFile}" });

Expand Down Expand Up @@ -141,6 +164,7 @@ private EnvDTE80.DTE2 GetVsInstance(string solutionPath)

return DTE;
}

public void Clean()
{
// Clean directories
Expand All @@ -152,11 +176,12 @@ public void Clean()
.Concat(Directory.EnumerateDirectories(TemplateDirectory, "_meta", SearchOption.AllDirectories))
.ToList().ForEach(dir => { Directory.Delete(dir, true); });
}

public BuildContext(ICakeContext context)
: base(context)
{

}
_artifactsFolder = Path.GetFullPath(Path.Combine(Environment.WorkingDirectory.FullPath, "..//artifacts"));
_toolsFolder = Path.GetFullPath(Path.Combine(Environment.WorkingDirectory.FullPath, "..//.tools"));
}
}
}
13 changes: 13 additions & 0 deletions cake/DefaultTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Cake.Frosting;
using System;
using System.Linq;

namespace Build
{
[TaskName("Default")]
[IsDependentOn(typeof(Scaffolder.LastTask))]
public class DefaultTask : FrostingTask
{

}
}
24 changes: 24 additions & 0 deletions cake/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Cake.Common.Tools.MSBuild;
using Cake.Core;
using Cake.Core.IO;
using Cake.Frosting;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Cake.Common.Tools.DotNet;


namespace Build
{
public static class Program
{
public static int Main(string[] args)
{
return new CakeHost()
.UseContext<BuildContext>()
.Run(args);

}
}
}
File renamed without changes.
145 changes: 145 additions & 0 deletions cake/scaffolder/Scaffolder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
using Cake.Common.Tools.DotNet;
using Cake.Core;
using Cake.Frosting;
using Octokit;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Build.Scaffolder
{
public class Const
{
public const string BuildGroupName = " : Scaffolder";
}

[TaskName("Startup" + Const.BuildGroupName)]
[IsDependentOn(typeof(mts_s_template.LastTask))]
public sealed class StartUpTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{

}
}

[TaskName("Setup" + Const.BuildGroupName)]
[IsDependentOn(typeof(StartUpTask))]
public sealed class SetupTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
context.ProjectRootDirectory = Path.GetFullPath(Path.Combine(context.Environment.WorkingDirectory.FullPath, "..//scaffolder//TcOpen.Scaffold"));
}
}

[TaskName("Clean" + Const.BuildGroupName)]
[IsDependentOn(typeof(SetupTask))]
public sealed class CleanTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
context.ProjectRootDirectory = Path.GetFullPath(Path.Combine(context.Environment.WorkingDirectory.FullPath, "..//scaffolder//TcOpen.Scaffold"));
// delete artifacts folder
var artifactsFolder = context.FileSystem.GetDirectory(context.ArtifactsFolder);
if (artifactsFolder.Exists)
{
artifactsFolder.Delete(true);
}

context.DotNetClean($"{context.ProjectRootDirectory}\\TcOpen.Scaffold.sln");
}
}

[TaskName("Build" + Const.BuildGroupName)]
[IsDependentOn(typeof(CleanTask))]
public sealed class BuildTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
context.DotNetBuild($"{context.ProjectRootDirectory}\\TcOpen.Scaffold.sln", new Cake.Common.Tools.DotNet.Build.DotNetBuildSettings()
{
Configuration = "Release"
});
}
}

[TaskName("Create artifacts" + Const.BuildGroupName)]
[IsDependentOn(typeof(BuildTask))]
public sealed class ArtifactTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
PublishArtifact(context, "net5.0-windows", "TcOpen.Scaffold.UI.zip", $"{context.ProjectRootDirectory}\\src\\TcOpen.Scaffold.UI\\TcOpen.Scaffold.UI.csproj", $"{context.ProjectRootDirectory}\\src\\TcOpen.Scaffold.UI\\Publish");
PublishArtifact(context, "net5.0", "TcOpen.Scaffold.Runner.zip", $"{context.ProjectRootDirectory}\\src\\TcOpen.Scaffold.Runner\\TcOpen.Scaffold.Runner.csproj", $"{context.ProjectRootDirectory}\\src\\TcOpen.Scaffold.Runner\\Publish");
}

private static void PublishArtifact(BuildContext context,
string framework,
string name,
string projectFile,
string outputFolder)
{

context.DotNetPublish(projectFile,
new Cake.Common.Tools.DotNet.Publish.DotNetPublishSettings()
{
Configuration = "Release",
Framework = framework ,
PublishSingleFile = true,
SelfContained = false,
PublishReadyToRun = true,
Runtime = "win10-x64",
OutputDirectory = outputFolder
});

context.ZipFolder(outputFolder, Path.GetFullPath(Path.Combine(context.ArtifactsFolder, name)));
}
}

[TaskName("Publish release" + Const.BuildGroupName)]
[IsDependentOn(typeof(ArtifactTask))]
public sealed class PublishReleaseTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
//var githubActionsProvider = new Cake.Common.Build.GitHubActions.GitHubActionsProvider(context.Environment, context.FileSystem);

//if (GitVersionInformation.BranchName == "dev")
{
var githubToken = context.Environment.GetEnvironmentVariable("gh-public-repos");
var githubClient = new GitHubClient(new ProductHeaderValue("TcOpen.Scaffold.UI"));
githubClient.Credentials = new Credentials(githubToken);

var release = githubClient.Repository.Release.Create(
"TcOpenGroup",
"tcopen-app-templates",
new NewRelease($"{GitVersionInformation.SemVer}")
{
Name = $"{GitVersionInformation.SemVer}",
TargetCommitish = GitVersionInformation.Sha,
Body = $"Release v{GitVersionInformation.SemVer}",
Draft = true,
Prerelease = true
}
).Result;


foreach (var artifact in Directory.EnumerateFiles(context.ArtifactsFolder, "*.zip").Select(p => new FileInfo(p)))
{
var asset = new ReleaseAssetUpload(artifact.Name, "application/zip", new StreamReader(artifact.FullName).BaseStream, TimeSpan.FromSeconds(3600));
githubClient.Repository.Release.UploadAsset(release, asset).Wait();
}
}
}
}

[TaskName("Default" + Const.BuildGroupName)]
[IsDependentOn(typeof(PublishReleaseTask))]
public class LastTask : FrostingTask
{
}
}
Loading

0 comments on commit f03dd6d

Please sign in to comment.