Skip to content

Commit

Permalink
Add husky and csharpier
Browse files Browse the repository at this point in the history
  • Loading branch information
sibartlett committed Oct 2, 2024
1 parent c7a4425 commit e4c37bc
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 17 deletions.
18 changes: 18 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"version": 1,
"isRoot": true,
"tools": {
"husky": {
"version": "0.7.1",
"commands": [
"husky"
]
},
"csharpier": {
"version": "0.29.2",
"commands": [
"dotnet-csharpier"
]
}
}
}
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ jobs:
.nuke/temp
~/.nuget/packages
key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj', '**/Directory.Packages.props') }}
- name: 'Run: Test'
run: ./build.cmd Test
- name: 'Run: CheckForUncommittedChanges, Test'
run: ./build.cmd CheckForUncommittedChanges Test
22 changes: 22 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

## husky task runner examples -------------------
## Note : for local installation use 'dotnet' prefix. e.g. 'dotnet husky'

## run all tasks
#husky run

### run all tasks with group: 'group-name'
#husky run --group group-name

## run task with name: 'task-name'
#husky run --name task-name

## pass hook arguments to task
#husky run --args "$1" "$2"

## or put your custom commands -------------------
#echo 'Husky.Net is awesome!'

dotnet husky run --group pre-commit
18 changes: 18 additions & 0 deletions .husky/task-runner.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"tasks": [
{
"name": "Run csharpier on staged files",
"group": "pre-commit",
"command": "dotnet",
"args": ["csharpier", "${staged}"],
"include": ["**/*.cs"]
},
{
"name": "Check csharpier on entire repository",
"group": "verify",
"command": "dotnet",
"args": ["csharpier", "."],
"include": ["**/*.cs"]
}
]
}
1 change: 1 addition & 0 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"ExecutableTarget": {
"type": "string",
"enum": [
"CheckForUncommittedChanges",
"Clean",
"Compile",
"Publish",
Expand Down
6 changes: 6 additions & 0 deletions Geo/Geo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,10 @@
<Link>README.md</Link>
</Content>
</ItemGroup>

<Target Name="Husky" BeforeTargets="Restore;CollectPackageReferences" Condition="'$(HUSKY)' != 0">
<Exec Command="dotnet tool restore" StandardOutputImportance="Low" StandardErrorImportance="High" />
<Exec Command="dotnet husky install" StandardOutputImportance="Low" StandardErrorImportance="High" WorkingDirectory=".." />
</Target>

</Project>
48 changes: 33 additions & 15 deletions build/Build.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using Nuke.Common;
using Nuke.Common.CI.GitHubActions;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.DotNet;

[GitHubActions(
"ci",
GitHubActionsImage.UbuntuLatest,
On = new[] { GitHubActionsTrigger.Push },
InvokedTargets = new[] { nameof(Test) }
InvokedTargets = new[] { nameof(CheckForUncommittedChanges), nameof(Test) }
)]
class Build : NukeBuild
{
Expand All @@ -17,20 +18,39 @@ class Build : NukeBuild
/// - Microsoft VisualStudio https://nuke.build/visualstudio
/// - Microsoft VSCode https://nuke.build/vscode

public static int Main () => Execute<Build>(x => x.Compile);
public static int Main() => Execute<Build>(x => x.Compile);

[Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;
readonly Configuration Configuration = IsLocalBuild
? Configuration.Debug
: Configuration.Release;

[Solution]
readonly Solution Solution;

[PathVariable]
readonly Tool Git;

Target CheckForUncommittedChanges =>
_ =>
_.Executes(() =>
{
DotNetTasks.DotNet("husky run --group verify");
if (Git($"status --porcelain").Count > 0)
{
Assert.Fail("Uncommitted changes - run csharpier and prettier");
}
});

Target Clean =>
_ =>
_.Before(Restore)
.Executes(() =>
{
DotNetTasks.DotNetClean(_ => _.SetProject(Solution).SetConfiguration(Configuration));
DotNetTasks.DotNetClean(_ =>
_.SetProject(Solution).SetConfiguration(Configuration)
);
});

Target Restore =>
Expand All @@ -45,11 +65,10 @@ class Build : NukeBuild
_.DependsOn(Restore)
.Executes(() =>
{
DotNetTasks.DotNetBuild(
_ =>
_.SetProjectFile(Solution)
.SetNoRestore(InvokedTargets.Contains(Restore))
.SetConfiguration(Configuration)
DotNetTasks.DotNetBuild(_ =>
_.SetProjectFile(Solution)
.SetNoRestore(InvokedTargets.Contains(Restore))
.SetConfiguration(Configuration)
);
});

Expand All @@ -61,8 +80,10 @@ class Build : NukeBuild
var projects = Solution.GetAllProjects("*.Tests");
foreach (var project in projects)
{
DotNetTasks.DotNetTest(
_ => _.SetProjectFile(project.Path).SetConfiguration(Configuration).EnableNoBuild()
DotNetTasks.DotNetTest(_ =>
_.SetProjectFile(project.Path)
.SetConfiguration(Configuration)
.EnableNoBuild()
);
}
});
Expand All @@ -71,9 +92,6 @@ class Build : NukeBuild
_ =>
_.Executes(() =>
{
DotNetTasks.DotNetPublish(
_ => _.SetConfiguration("Release")
);
DotNetTasks.DotNetPublish(_ => _.SetConfiguration("Release"));
});

}

0 comments on commit e4c37bc

Please sign in to comment.