Skip to content

Commit

Permalink
Fix linux issues
Browse files Browse the repository at this point in the history
  • Loading branch information
visose committed Dec 6, 2021
1 parent dc95ff4 commit f4e1883
Show file tree
Hide file tree
Showing 15 changed files with 192 additions and 96 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Publish

on:
workflow_dispatch:

jobs:
publish:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-dotnet@v1
with:
dotnet-version: '6.0.x'
- run: /home/runner/.dotnet/dotnet build "build/Robots.Build/Robots.Build.csproj"
- run: sudo /home/runner/.dotnet/dotnet run --no-build --project "build/Robots.Build/Robots.Build.csproj" test build package publish release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
YAK_TOKEN: ${{ secrets.YAK_TOKEN }}
15 changes: 8 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
.DS_Store
nupkg/
secrets*

# Build results
artifacts/

# Visual Studio Code
.vscode

# Rider
.idea

# Visual Studio
.vs/

# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates

# Build results
artifacts/

# Visual Studio 2015
.vs/
*.sln.docstates
6 changes: 3 additions & 3 deletions Directory.Build.Props → Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

<PropertyGroup>
<Product>Robots</Product>
<Version>1.0.1</Version>
<Description>Create and simulate programs for ABB, KUKA, UR and Staubli robots.</Description>
<Version>1.0.2</Version>
<Description>Create and simulate ABB, KUKA, UR and Staubli robot programs.</Description>
<Copyright>Copyright (c) 2021</Copyright>
<Authors>Robots Authors</Authors>
<Url>https://github.com/visose/robots/discussions</Url>
<Url>https://github.com/visose/robots</Url>
<Tags>Robots;ABB;KUKA;UR;Staubli</Tags>
<IconUrl>https://github.com/visose/robots/raw/master/build/Assets/iconRobot.png</IconUrl>
<Company>$(Authors) - $(Url)</Company>
Expand Down
2 changes: 1 addition & 1 deletion Robots.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{101C8522-302F-4233-A875-F76C3758F693}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
Directory.Build.Props = Directory.Build.Props
Directory.Build.props = Directory.Build.props
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Robots.Tests", "tests\Robots.Tests\Robots.Tests.csproj", "{16C2E987-7825-42F8-A2C7-8695F7964335}"
Expand Down
64 changes: 56 additions & 8 deletions build/Robots.Build/Commands.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using static Robots.Build.Util;
using Octokit;
using static Robots.Build.Util;

namespace Robots.Build;

Expand All @@ -14,7 +15,7 @@ public static int Build()
return Run("dotnet", "build src/Robots.Grasshopper/Robots.Grasshopper.csproj -c Release");
}

public static int Package()
public static async Task<int> PackageAsync()
{
// Pacakge folder
if (Directory.Exists(PackageFolder))
Expand All @@ -40,23 +41,70 @@ public static int Package()
Manifest.CreateAndSave(path);

// Build package
string yak = GetYakPath();
string yak = await GetYakPathAsync();
return Run(yak, "build", PackageFolder);
}

public static int Publish()
public static async Task<int> PublishAsync()
{
string packagePath = Directory.EnumerateFiles(PackageFolder)
.Single(f => Path.GetExtension(f) == ".yak");

string packageFile = Path.GetFileName(packagePath);
string yak = GetYakPath();
string yak = await GetYakPathAsync();
return Run(yak, $"push {packageFile}", PackageFolder);
}

static string GetYakPath()
public static async Task<int> ReleaseAsync()
{
// Download: http://files.mcneel.com/yak/tools/latest/yak.exe
return "C:/Program Files/Rhino 7/System/Yak.exe";
string version = Manifest.GetVersion();

var client = new GitHubClient(new ProductHeaderValue("visose"))
{
Credentials = new Credentials(GetSecret("GITHUB_TOKEN"))
};

var latest = await client.Repository.Release.GetLatest("visose", "Robots");

if (latest.TagName == version)
{
Log($"Error: Release {version} already exists.");
return 1;
}

const string body = @"This **release** can only be installed through the package manager in **Rhino 7** using the `_PackageManager` command.
> Check the [readme](../../blob/master/.github/README.md) for more details.";

var release = new NewRelease(version)
{
Name = version,
Body = body,
Prerelease = false
};

var result = await client.Repository.Release.Create("visose", "Robots", release);
Log($"Created release id: {result.Id}");
return 0;
}

static async Task<string> GetYakPathAsync()
{
const string yak = "Yak.exe";
const string rhino = "C:/Program Files/Rhino 7/System/Yak.exe";

if (File.Exists(rhino))
return rhino;

if (File.Exists(yak))
return Path.GetFullPath(yak);

var http = new HttpClient();
var response = await http.GetAsync($"http://files.mcneel.com/yak/tools/latest/yak.exe");
response.EnsureSuccessStatusCode();
await using var ms = await response.Content.ReadAsStreamAsync();
await using var fs = File.Create(yak);
ms.Seek(0, SeekOrigin.Begin);
ms.CopyTo(fs);
return Path.GetFullPath(yak);
}
}
6 changes: 5 additions & 1 deletion build/Robots.Build/Manifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public static void CreateAndSave(string fileName)
var text = manifest.ToYaml();
File.WriteAllText(fileName, text);
}
public static string GetVersion()
{
return new Manifest().Version;
}

public string Name { get; private set; }
public string Version { get; private set; }
Expand All @@ -28,7 +32,7 @@ public static void CreateAndSave(string fileName)

private Manifest()
{
var doc = XDocument.Load("Directory.Build.Props");
var doc = XDocument.Load("Directory.Build.props");
XElement props = doc.Root?.Descendants().First() ??
throw new NullReferenceException();

Expand Down
27 changes: 17 additions & 10 deletions build/Robots.Build/Program.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,41 @@
using Robots.Build;
using static Robots.Build.Util;

var commandList = new Dictionary<string, Func<int>>
var commandList = new Dictionary<string, Delegate>
{
{ "test", Commands.Test },
{ "build", Commands.Build },
{ "package", Commands.Package },
{ "publish", Commands.Publish },
{ "package", Commands.PackageAsync },
{ "publish", Commands.PublishAsync },
{ "release", Commands.ReleaseAsync }
};

if (args.Length == 0)
{
Console.WriteLine($"Specify a command: {string.Join(", ", commandList.Keys)}");
Log($"Specify a command: {string.Join(", ", commandList.Keys)}");
return 1;
}

foreach (var arg in args)
{
if (!commandList.TryGetValue(arg, out var action))
{
Console.WriteLine($"Command '{arg}' doesn't exist.");
Log($"Command '{arg}' doesn't exist.");
return 1;
}

Console.WriteLine($"Starting {arg}...");
int result = action();
Log($"Starting {arg}...");

if (result != 0)
var result = action.DynamicInvoke() ?? throw new NullReferenceException();

int code = action.Method.ReturnType == typeof(int)
? (int)result
: await (Task<int>)result;

if (code != 0)
{
Console.WriteLine("Premature exit.");
return result;
Log("Premature exit.");
return code;
}
}

Expand Down
15 changes: 8 additions & 7 deletions build/Robots.Build/Robots.Build.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="YamlDotNet" Version="11.2.1" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="YamlDotNet" Version="11.2.1" />
<PackageReference Include="Octokit" Version="0.50.0" />
</ItemGroup>

</Project>
25 changes: 22 additions & 3 deletions build/Robots.Build/Util.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
using System.Diagnostics;
using System.Text.Json;

namespace Robots.Build;

static class Util
{
public static string ArtifactsFolder => "Artifacts";
public static string ArtifactsFolder => "artifacts";
public static string BuildFolder => Path.Combine(ArtifactsFolder, "bin", "Robots.Grasshopper", "net48");
public static string PackageFolder => Path.Combine(ArtifactsFolder, "package");

public static void Log(string? text)
{
Console.WriteLine(text);
}

public static int Run(string file, string args, string? setCurrentDir = null)
{
var currentDir = Directory.GetCurrentDirectory();
Expand All @@ -27,8 +33,8 @@ public static int Run(string file, string args, string? setCurrentDir = null)
StartInfo = startInfo
};

process.OutputDataReceived += (o, e) => Console.WriteLine(e.Data);
process.ErrorDataReceived += (o, e) => Console.WriteLine(e.Data);
process.OutputDataReceived += (o, e) => Log(e.Data);
process.ErrorDataReceived += (o, e) => Log(e.Data);
process.Start();
process.BeginErrorReadLine();
process.BeginOutputReadLine();
Expand All @@ -37,4 +43,17 @@ public static int Run(string file, string args, string? setCurrentDir = null)
Directory.SetCurrentDirectory(currentDir);
return process.ExitCode;
}

public static string GetSecret(string key)
{
string? value = Environment.GetEnvironmentVariable(key);

if (value is not null)
return value;

var json = File.ReadAllText("build/Robots.Build/secrets.json");
var doc = JsonDocument.Parse(json);
var prop = doc.RootElement.GetProperty(key);
return prop.GetString() ?? throw new NullReferenceException($"Secret {key} not found.");
}
}
Binary file added lib/ABB.Robotics.Controllers.PC.dll
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit f4e1883

Please sign in to comment.