-
Notifications
You must be signed in to change notification settings - Fork 18
feat: add Husky.Net README badge sync hook and clean up 3-Series leftovers #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+241
−266
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5965b79
feat: add Husky.Net pre-commit hook to sync README badges
jkdevito 69b8c4b
chore: cleanup unused CI scripts
jkdevito 5c359db
chore: install git hooks when the folder opens in VS Code
jkdevito f97c558
docs: add Husky.Net setup and usage to README
jkdevito 80a7ac6
chore: remove 3-Series leftovers, ignore code-workspace, update copyr…
jkdevito 9d3af8d
docs: address review feedback on badge hook
jkdevito e0f6fe5
chore: use PowerShell 7 for README badge hook on all platforms
jkdevito c0fec3b
fix: harden badge hook staging guard and pin task shell to pwsh
jkdevito a2d2597
chore: move dotnet tool manifest to .config
jkdevito File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| "version": 1, | ||
| "isRoot": true, | ||
| "tools": { | ||
| "husky": { | ||
| "version": "0.9.1", | ||
| "commands": [ | ||
| "husky" | ||
| ], | ||
| "rollForward": false | ||
| } | ||
| } | ||
| } | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| <# | ||
| .SYNOPSIS | ||
| Syncs the README .NET and PepperDash Essentials badges with the project files. | ||
| .PARAMETER Check | ||
| Exit 1 if the README badges are stale instead of rewriting them. | ||
| .PARAMETER Stage | ||
| git add README.md when it was changed. | ||
| #> | ||
| [CmdletBinding()] | ||
| param( | ||
| [switch]$Check, | ||
| [switch]$Stage | ||
| ) | ||
|
|
||
| $ErrorActionPreference = 'Stop' | ||
| $root = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) | ||
| $srcDir = Join-Path $root 'src' | ||
| $readmePath = Join-Path $root 'README.md' | ||
| $utf8 = New-Object System.Text.UTF8Encoding($false) | ||
|
|
||
| function Fail($message) { | ||
| [Console]::Error.WriteLine("badges: $message") | ||
| exit 1 | ||
| } | ||
|
|
||
| # Staging README.md adds its whole working-tree copy, and badges are computed from working-tree | ||
| # sources, so refuse to run when any of those inputs differ from the index. | ||
| if ($Stage) { | ||
| # Porcelain XY: a non-blank Y is a worktree change ('??' = untracked), which the index lacks. | ||
| $status = @(git -C $root status --porcelain --untracked-files=all -- README.md 'src/*.4Series.csproj' 'src/*Factory.cs') | ||
| if ($LASTEXITCODE) { Fail 'git status failed' } | ||
| $unstaged = @($status | Where-Object { $_ -match '^.[^ ]' }) | ||
| if ($unstaged.Count -gt 0) { | ||
| Fail ("unstaged or untracked badge inputs ($(($unstaged | ForEach-Object { $_.Substring(3) }) -join ', ')); stage or stash them, then commit again") | ||
| } | ||
| } | ||
|
|
||
| # Target framework from the 4Series csproj | ||
| $csprojFile = Get-ChildItem -Path $srcDir -Filter '*.4Series.csproj' | Select-Object -First 1 | ||
| if (-not $csprojFile) { Fail 'no *.4Series.csproj found in src/' } | ||
| $csproj = [System.IO.File]::ReadAllText($csprojFile.FullName, $utf8) | ||
| $tfmMatch = [regex]::Match($csproj, '<TargetFramework>\s*([^<\s]+)\s*</TargetFramework>') | ||
| if (-not $tfmMatch.Success) { Fail "TargetFramework not found in $($csprojFile.Name)" } | ||
| $tfm = $tfmMatch.Groups[1].Value | ||
|
|
||
| # Minimum Essentials version: highest MinimumEssentialsFrameworkVersion across factories | ||
| $minVersions = @() | ||
| foreach ($file in Get-ChildItem -Path $srcDir -Filter '*Factory.cs') { | ||
| $text = [System.IO.File]::ReadAllText($file.FullName, $utf8) | ||
| $found = [regex]::Matches($text, '(?m)^\s*MinimumEssentialsFrameworkVersion\s*=\s*"(\d+(?:\.\d+)+)"\s*;') | ||
| foreach ($m in $found) { $minVersions += $m.Groups[1].Value } | ||
| } | ||
| if ($minVersions.Count -eq 0) { Fail 'MinimumEssentialsFrameworkVersion not found in src/*Factory.cs' } | ||
| $minVersion = ($minVersions | Sort-Object { [version]$_ } | Select-Object -Last 1) | ||
|
|
||
| # Warn when the NuGet reference and the factory minimum disagree | ||
| $pkgMatch = [regex]::Match($csproj, '<PackageReference\s+Include="PepperDashEssentials"\s+Version="([^"]+)"') | ||
| if ($pkgMatch.Success -and $pkgMatch.Groups[1].Value -ne $minVersion) { | ||
| Write-Warning "badges: PepperDashEssentials package $($pkgMatch.Groups[1].Value) != MinimumEssentialsFrameworkVersion $minVersion" | ||
| } | ||
|
|
||
| function Get-FrameworkBadge($moniker) { | ||
| $legacy = [regex]::Match($moniker, '^net(\d)(\d)(\d)?$') | ||
| if ($legacy.Success) { | ||
| $parts = @($legacy.Groups[1].Value, $legacy.Groups[2].Value) | ||
| if ($legacy.Groups[3].Success) { $parts += $legacy.Groups[3].Value } | ||
| return @{ Label = '.NET Framework'; Message = ($parts -join '.') } | ||
| } | ||
| $modern = [regex]::Match($moniker, '^net(\d+\.\d+)') | ||
| if ($modern.Success) { return @{ Label = '.NET'; Message = $modern.Groups[1].Value } } | ||
| return @{ Label = '.NET'; Message = $moniker } | ||
| } | ||
|
|
||
| # shields.io static badge path: '-' and '_' are escaped by doubling, spaces as %20 | ||
| function Format-Segment($s) { $s.Replace('-', '--').Replace('_', '__').Replace(' ', '%20') } | ||
| function Get-BadgeUrl($label, $message, $color) { | ||
| 'https://img.shields.io/badge/{0}-{1}-{2}' -f (Format-Segment $label), (Format-Segment $message), $color | ||
| } | ||
|
|
||
| $fw = Get-FrameworkBadge $tfm | ||
| $essentialsMessage = '{0} v{1}' -f [char]0x2265, $minVersion | ||
| $replacements = @( | ||
| @{ | ||
| Pattern = '!\[\.NET[^\]]*\]\(https://img\.shields\.io/badge/[^)]*\)' | ||
| Value = ' + ')' | ||
| }, | ||
| @{ | ||
| Pattern = '!\[PepperDash Essentials\]\(https://img\.shields\.io/badge/[^)]*\)' | ||
| Value = ' + ')' | ||
| } | ||
| ) | ||
|
|
||
| $original = [System.IO.File]::ReadAllText($readmePath, $utf8) | ||
| $updated = $original | ||
| foreach ($r in $replacements) { | ||
| if (-not [regex]::IsMatch($updated, $r.Pattern)) { Fail "badge not found in README.md: $($r.Pattern)" } | ||
| $value = $r.Value | ||
| $updated = [regex]::Replace($updated, $r.Pattern, { param($m) $value }, 'None') | ||
| } | ||
|
|
||
| if ($updated -ceq $original) { | ||
| Write-Host 'badges: README.md up to date' | ||
| exit 0 | ||
| } | ||
|
|
||
| if ($Check) { Fail 'README.md badges are stale; run .github/scripts/Update-ReadmeBadges.ps1' } | ||
|
|
||
| [System.IO.File]::WriteAllText($readmePath, $updated, $utf8) | ||
| Write-Host "badges: README.md updated ($($fw.Label) $($fw.Message), Essentials >= v$minVersion)" | ||
|
|
||
| if ($Stage) { | ||
| git -C $root add README.md | ||
| if ($LASTEXITCODE) { Fail 'git add README.md failed' } | ||
| } |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -357,3 +357,6 @@ MigrationBackup/ | |
| *.clz | ||
| *.projectinfo | ||
| *.suo | ||
|
|
||
| # VS Code | ||
| *.code-workspace | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "$schema": "https://alirezanet.github.io/Husky.Net/schema.json", | ||
| "tasks": [ | ||
| { | ||
| "name": "update-readme-badges", | ||
| "command": "pwsh", | ||
| "args": [ "-NoProfile", "-File", ".github/scripts/Update-ReadmeBadges.ps1", "-Stage" ] | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| "version": "2.0.0", | ||
| "tasks": [ | ||
| { | ||
| "label": "Install git hooks", | ||
| "type": "shell", | ||
| "command": "dotnet tool restore && dotnet husky install", | ||
| "options": { | ||
| "shell": { | ||
| "executable": "pwsh", | ||
| "args": ["-NoProfile", "-Command"] | ||
| } | ||
| }, | ||
| "presentation": { | ||
| "reveal": "silent", | ||
| "close": true | ||
| }, | ||
| "runOptions": { | ||
| "runOn": "folderOpen" | ||
| }, | ||
| "problemMatcher": [] | ||
| } | ||
| ] | ||
| } |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.