From 8ac6b3b51495f9d467710ecb2fb6ef7b9a8dfcf5 Mon Sep 17 00:00:00 2001 From: "Dylan R. E. Moonfire" Date: Sat, 2 Apr 2022 17:17:23 -0500 Subject: [PATCH] build: adding lefthook for hook management --- .gitignore | 1 + flake.nix | 2 +- lefthook.yml | 46 +++++-------------- package.json | 23 ---------- scripts/format.sh | 8 ++++ scripts/setup.sh | 15 +++++- .../Extensions/ParseResultExtensions.cs | 2 +- .../Extensions/StringCliExtensions.cs | 2 +- src/MfGames.ToolBuilder/ToolBuilderModule.cs | 2 +- tests/SampleTool/CrashCommand.cs | 2 +- tests/SampleTool/Program.cs | 2 +- tests/SampleTool/SampleToolModule.cs | 2 +- 12 files changed, 41 insertions(+), 66 deletions(-) delete mode 100644 package.json create mode 100755 scripts/format.sh diff --git a/.gitignore b/.gitignore index 43bed09..f7ff559 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ node_modules/ coverage TestResults/ tests/artifacts/ +.lefthook* diff --git a/flake.nix b/flake.nix index cfeb11e..18ce3b0 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ let pkgs = nixpkgs.legacyPackages.${system}; in { devShell = pkgs.mkShell { - buildInputs = [ pkgs.dotnet-sdk pkgs.nixfmt ]; + buildInputs = [ pkgs.dotnet-sdk pkgs.lefthook pkgs.convco pkgs.nixfmt ]; }; }); } diff --git a/lefthook.yml b/lefthook.yml index af073d4..78ce6de 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -1,34 +1,12 @@ -# EXAMPLE USAGE -# Refer for explanation to following link: -# https://github.com/evilmartians/lefthook/blob/master/docs/full_guide.md -# -# pre-push: -# commands: -# packages-audit: -# tags: frontend security -# run: yarn audit -# gems-audit: -# tags: backend security -# run: bundle audit -# -# pre-commit: -# parallel: true -# commands: -# eslint: -# glob: "*.{js,ts}" -# run: yarn eslint {staged_files} -# rubocop: -# tags: backend style -# glob: "*.rb" -# exclude: "application.rb|routes.rb" -# run: bundle exec rubocop --force-exclusion {all_files} -# govet: -# tags: backend style -# files: git ls-files -m -# glob: "*.go" -# run: go vet {files} -# scripts: -# "hello.js": -# runner: node -# "any.go": -# runner: go run +pre-push: + parallel: true + commands: + commit-check: + run: convco check -n 30 + +pre-commit: + parallel: true + commands: + dotnet-format: + glob: "*.cs" + run: dotnet format diff --git a/package.json b/package.json deleted file mode 100644 index d577bd4..0000000 --- a/package.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "mfgames-toolbuilder", - "version": "2.0.1", - "private": true, - "scripts": { - "prepare": "husky install", - "build": "dotnet build", - "test": "dotnet test" - }, - "devDependencies": { - "@commitlint/cli": "^15.0.0", - "@commitlint/config-conventional": "^15.0.0", - "@semantic-release/changelog": "^6.0.1", - "@semantic-release/git": "^10.0.1", - "@semantic-release/gitlab": "^7.0.4", - "@semantic-release/npm": "^8.0.3", - "commitlint-gitlab-ci": "^0.0.4", - "husky": "^7.0.2", - "semantic-release": "^18.0.1", - "semantic-release-dotnet": "^1.0.0", - "semantic-release-nuget": "^1.1.1" - } -} diff --git a/scripts/format.sh b/scripts/format.sh new file mode 100755 index 0000000..a3386a9 --- /dev/null +++ b/scripts/format.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env sh + +# Normalize our environment. +cd $(dirname $0)/.. +./scripts/setup.sh || exit 1 + +# Format the .NET code +dotnet format || exit 1 diff --git a/scripts/setup.sh b/scripts/setup.sh index 1763d1a..de738fd 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -2,10 +2,21 @@ cd $(dirname $0)/.. -# Make sure we have .NET installed - +# Make sure we have .NET installed. if ! which dotnet >& /dev/null then echo "Cannot find 'dotnet' in the path" exit 1 fi + +# Make sure we have lefthook.and it is installed. +if ! which lefthook >& /dev/null +then + echo "Cannot find 'lefthook' in the path" + exit 1 +fi + +lefthook install + +# Everything is good. +exit 0 diff --git a/src/MfGames.ToolBuilder/Extensions/ParseResultExtensions.cs b/src/MfGames.ToolBuilder/Extensions/ParseResultExtensions.cs index 6b1b848..68bb492 100644 --- a/src/MfGames.ToolBuilder/Extensions/ParseResultExtensions.cs +++ b/src/MfGames.ToolBuilder/Extensions/ParseResultExtensions.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.CommandLine; using System.CommandLine.Parsing; using System.Linq; diff --git a/src/MfGames.ToolBuilder/Extensions/StringCliExtensions.cs b/src/MfGames.ToolBuilder/Extensions/StringCliExtensions.cs index baa620d..07870e5 100644 --- a/src/MfGames.ToolBuilder/Extensions/StringCliExtensions.cs +++ b/src/MfGames.ToolBuilder/Extensions/StringCliExtensions.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; diff --git a/src/MfGames.ToolBuilder/ToolBuilderModule.cs b/src/MfGames.ToolBuilder/ToolBuilderModule.cs index 5965dda..bbeb155 100644 --- a/src/MfGames.ToolBuilder/ToolBuilderModule.cs +++ b/src/MfGames.ToolBuilder/ToolBuilderModule.cs @@ -1,4 +1,4 @@ -using Autofac; +using Autofac; using MfGames.ToolBuilder.Services; diff --git a/tests/SampleTool/CrashCommand.cs b/tests/SampleTool/CrashCommand.cs index cdd11ca..51b2efb 100644 --- a/tests/SampleTool/CrashCommand.cs +++ b/tests/SampleTool/CrashCommand.cs @@ -17,7 +17,7 @@ namespace SampleTool { this.Handler = this; this.messyOption = new Option("--messy"); - + this.AddOption(this.messyOption); } diff --git a/tests/SampleTool/Program.cs b/tests/SampleTool/Program.cs index 924962b..918d8a3 100644 --- a/tests/SampleTool/Program.cs +++ b/tests/SampleTool/Program.cs @@ -1,4 +1,4 @@ -using System.Threading.Tasks; +using System.Threading.Tasks; using Autofac; diff --git a/tests/SampleTool/SampleToolModule.cs b/tests/SampleTool/SampleToolModule.cs index 6aa17b3..7ee6962 100644 --- a/tests/SampleTool/SampleToolModule.cs +++ b/tests/SampleTool/SampleToolModule.cs @@ -1,4 +1,4 @@ -using System.CommandLine; +using System.CommandLine; using Autofac;