Skip to content

Commit

Permalink
Adding some options and a few fixes [release]
Browse files Browse the repository at this point in the history
  • Loading branch information
timheuer committed Feb 16, 2022
1 parent 89f771b commit 3dcaa5d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 8 deletions.
2 changes: 2 additions & 0 deletions AddActionsWorkflow/AddActionsWorkflow.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Compile Include="Options\General.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Commands\MyCommand.cs" />
<Compile Include="AddActionsWorkflowPackage.cs" />
Expand Down Expand Up @@ -83,6 +84,7 @@
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Design" />
</ItemGroup>
<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions AddActionsWorkflow/AddActionsWorkflowPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
global using Task = System.Threading.Tasks.Task;
using System.Runtime.InteropServices;
using System.Threading;
using AddActionsWorkflow.Options;

namespace AddActionsWorkflow
{
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
[InstalledProductRegistration(Vsix.Name, Vsix.Description, Vsix.Version)]
[ProvideMenuResource("Menus.ctmenu", 1)]
[Guid(PackageGuids.AddActionsWorkflowString)]
[ProvideOptionPage(typeof(OptionsProvider.GeneralOptions), "GitHub Actions Workflow", "General", 0, 0, true)]
[ProvideProfile(typeof(OptionsProvider.GeneralOptions), "GitHub Actions Workflow", "General", 0, 0, true)]
public sealed class AddActionsWorkflowPackage : ToolkitPackage
{
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
Expand Down
22 changes: 14 additions & 8 deletions AddActionsWorkflow/Commands/MyCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics;
using AddActionsWorkflow.Options;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;

Expand All @@ -21,8 +22,10 @@ protected override async Task ExecuteAsync(OleMenuCmdEventArgs e)
proc.StartInfo.WorkingDirectory = repoRoot;
proc.StartInfo.FileName = "dotnet";

var workflowName = $"build-{Guid.NewGuid().ToString().Substring(0, 5)}";
proc.StartInfo.Arguments = $"new workflow -n {workflowName} --no-update-check";
var general = await General.GetLiveInstanceAsync();
var workflowName = general.RandomizeFileName ? $"{general.DefaultName}-{Guid.NewGuid().ToString().Substring(0, 5)}" : general.DefaultName;
var overwriteFile = general.OverwriteExisting ? "--force" : "";
proc.StartInfo.Arguments = $"new workflow -n {workflowName} --no-update-check {overwriteFile}";
proc.Start();

// add solution folder
Expand All @@ -33,16 +36,16 @@ protected override async Task ExecuteAsync(OleMenuCmdEventArgs e)
// if the folder exists, use it otherwise create
foreach (var item in sln.Children)
{
if (item.Name.ToLower() == "solution items")
if (item.Name.ToLower() == general.SolutionFolderName.ToLower())
{
proj = item as SolutionFolder;
folderExists = true;
break;
}
break;
}

if (!folderExists)
proj = await sln.AddSolutionFolderAsync("Solution Items");
proj = await sln.AddSolutionFolderAsync(general.SolutionFolderName);

_ = await proj?.AddExistingFilesAsync(Path.Combine(slnDir, @$".github\workflows\{workflowName}.yaml"));
}
Expand All @@ -60,12 +63,15 @@ internal async Task<String> GetGitRootDirAsync(string workingDirectory)
git.StartInfo.Arguments = "rev-parse --show-toplevel";
git.Start();

rootGitDir = await git.StandardOutput.ReadToEndAsync();

if (git.ExitCode == 0)
{
rootGitDir = await git.StandardOutput.ReadToEndAsync();
rootGitDir = rootGitDir.Replace('/', '\\').Replace("\n", "");
}
else
{
git.Kill();
}

return rootGitDir;
}
Expand Down
36 changes: 36 additions & 0 deletions AddActionsWorkflow/Options/General.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.ComponentModel;

namespace AddActionsWorkflow.Options
{
internal partial class OptionsProvider
{
public class GeneralOptions : BaseOptionPage<General> { }
}

public class General : BaseOptionModel<General>
{
[Category("Generator")]
[DisplayName("Default file name")]
[Description("The base name of the workflow (.yaml) file to be generated")]
[DefaultValue("build-")]
public string DefaultName { get; set; } = "build-";

[Category("Generator")]
[DisplayName("Randomize file name")]
[Description("If true, a suffix is added to the Default file name to avoid conflicts")]
[DefaultValue(true)]
public bool RandomizeFileName { get; set; } = true;

[Category("Generator")]
[DisplayName("Overwrite if exists")]
[Description("If true, this will overwrite same-named workflow files if exists")]
[DefaultValue(false)]
public bool OverwriteExisting { get; set; } = false;

[Category("Generator")]
[DisplayName("Solution Folder")]
[Description("The Solution Items folder to add these to in the Visual Studio solution")]
[DefaultValue("Solution Items")]
public string SolutionFolderName { get; set; } = "Solution Items";
}
}

0 comments on commit 3dcaa5d

Please sign in to comment.