77 [CmdletBinding ()]
88 param (
99 # The command to execute
10- [Parameter (Mandatory , Position = 0 )]
11- [string ]$Command ,
12-
13- # The arguments to pass to the command
1410 [Parameter (ValueFromRemainingArguments )]
15- [string []]$Arguments
11+ [string []]$Command
1612 )
17-
18- Write-Debug " Command: $Command "
19- Write-Debug " Arguments: $ ( $Arguments -join ' , ' ) "
20- $fullCommand = " $Command $ ( $Arguments -join ' ' ) "
13+ $cmd = $Command [0 ]
14+ $arguments = $Command [1 .. $Command.Length ]
15+ Write-Debug " Command: $cmd "
16+ Write-Debug " Arguments: $ ( $arguments -join ' , ' ) "
17+ $fullCommand = " $cmd $ ( $arguments -join ' ' ) "
2118
2219 try {
2320 Write-Verbose " Executing: $fullCommand "
24- & $Command @Arguments
21+ & $cmd @arguments
2522 if ($LASTEXITCODE -ne 0 ) {
2623 $errorMessage = " Command failed with exit code $LASTEXITCODE `: $fullCommand "
2724 Write-Error $errorMessage - ErrorId ' NativeCommandFailed' - Category OperationStopped - TargetObject $fullCommand
3128 }
3229}
3330
34- # Get the current branch and default branch information
35- $currentBranch = (Invoke-NativeCommand git rev- parse -- abbrev- ref HEAD).Trim()
36- $defaultBranch = (Invoke-NativeCommand git remote show origin | Select-String ' HEAD branch:' | ForEach-Object { $_.ToString ().Split(' :' )[1 ].Trim() })
37-
31+ $currentBranch = (Run git rev- parse -- abbrev- ref HEAD).Trim()
32+ $defaultBranch = (Run git remote show origin | Select-String ' HEAD branch:' | ForEach-Object { $_.ToString ().Split(' :' )[1 ].Trim() })
3833Write-Output " Current branch: $currentBranch "
3934Write-Output " Default branch: $defaultBranch "
4035
41- # Fetch latest changes from remote
42- Invoke-NativeCommand git fetch origin
43-
44- # Get the head branch (latest default branch)
45- Invoke-NativeCommand git checkout $defaultBranch
46- Invoke-NativeCommand git pull origin $defaultBranch
36+ Run git fetch origin
37+ Run git checkout $defaultBranch
38+ Run git pull origin $defaultBranch
4739
4840$timeStamp = Get-Date - Format ' yyyyMMdd-HHmmss'
49-
50- # Determine target branch based on current context
5141if ($currentBranch -eq $defaultBranch ) {
5242 # Running on main/default branch - create new branch
53- $targetBranch = " auto-font- update-$timeStamp "
43+ $targetBranch = " auto-update-font -$timeStamp "
5444 Write-Output " Running on default branch. Creating new branch: $targetBranch "
55- Invoke-NativeCommand git checkout - b $targetBranch
45+ Run git checkout - b $targetBranch
5646} else {
5747 # Running on another branch (e.g., workflow_dispatch) - use current branch
5848 $targetBranch = $currentBranch
5949 Write-Output " Running on feature branch. Using existing branch: $targetBranch "
60- Invoke-NativeCommand git checkout $targetBranch
50+ Run git checkout $targetBranch
6151 # Merge latest changes from default branch
62- Invoke-NativeCommand git merge origin/ $defaultBranch
52+ Run git merge origin/ $defaultBranch
6353}
6454
65- $release = Get-GitHubRelease - Owner ryanoasis - Repository nerd- fonts
66- $fonts = @ ()
67- $fontAssets = $release | Get-GitHubReleaseAsset | Where-Object { $_.Name -like ' *.zip' }
68-
69- foreach ($fontArchive in $fontAssets ) {
70- $fonts += [PSCustomObject ]@ {
71- Name = $fontArchive.Name.Split (' .' )[0 ]
72- URL = $fontArchive.Url
55+ LogGroup ' Latest Fonts' {
56+ $release = Get-GitHubRelease - Owner ryanoasis - Repository nerd- fonts
57+ $fonts = @ ()
58+ $fontAssets = $release | Get-GitHubReleaseAsset | Where-Object { $_.Name -like ' *.zip' }
59+
60+ foreach ($fontArchive in $fontAssets ) {
61+ $fonts += [PSCustomObject ]@ {
62+ Name = $fontArchive.Name.Split (' .' )[0 ]
63+ URL = $fontArchive.Url
64+ }
7365 }
74- }
7566
76- LogGroup ' Latest Fonts' {
7767 $fonts | Sort-Object Name | Format-Table - AutoSize | Out-String
7868}
7969
@@ -82,47 +72,37 @@ $filePath = Join-Path -Path $parentFolder -ChildPath 'src\FontsData.json'
8272$null = New-Item - Path $filePath - ItemType File - Force
8373$fonts | ConvertTo-Json | Set-Content - Path $filePath - Force
8474
85- $changes = Invoke-NativeCommand git status -- porcelain
86- if (-not [string ]::IsNullOrWhiteSpace($changes )) {
87- Write-Output ' Changes detected:'
88- Write-Output $changes
89-
90- # Show what will be committed
91- Write-Output ' Diff of changes to be committed:'
92- Invoke-NativeCommand git diff -- cached HEAD -- src/ FontsData.json 2> $null
93- if ($LASTEXITCODE -ne 0 ) {
94- # If --cached doesn't work (no staged changes), show unstaged diff
95- Invoke-NativeCommand git diff HEAD -- src/ FontsData.json
96- }
75+ $changes = Run git status -- porcelain
76+ if ([string ]::IsNullOrWhiteSpace($changes )) {
77+ Write-Output ' No changes detected.'
78+ return
79+ }
9780
98- Invoke-NativeCommand git add .
99- Invoke-NativeCommand git commit - m " Update-FontsData via script on $timeStamp "
81+ Write-Output ' Changes detected: '
82+ Write-Output $changes
10083
101- # Show the commit that was just created
102- Write-Output ' Commit created:'
103- Invoke-NativeCommand git log -1 -- oneline
84+ Write-Output ' Diff of changes to be committed:'
85+ Run git diff HEAD -- src/ FontsData.json
10486
105- # Show diff between HEAD and previous commit
106- Write-Output ' Changes in this commit:'
107- Invoke-NativeCommand git diff HEAD~1 HEAD -- src/ FontsData.json
87+ Run git add .
88+ Run git commit - m " Update-FontsData via script on $timeStamp "
89+ Write-Output ' Changes in this commit:'
90+ Run git diff HEAD~1 HEAD -- src/ FontsData.json
10891
109- # Push behavior depends on branch type
110- if ($targetBranch -eq $currentBranch -and $currentBranch -ne $defaultBranch ) {
111- # Push to existing branch
112- Invoke-NativeCommand git push origin $targetBranch
113- Write-Output " Changes committed and pushed to existing branch: $targetBranch "
114- } else {
115- # Push new branch and create PR
116- Invoke-NativeCommand git push -- set-upstream origin $targetBranch
92+ # Push behavior depends on branch type
93+ if ($targetBranch -eq $currentBranch -and $currentBranch -ne $defaultBranch ) {
94+ # Push to existing branch
95+ Run git push origin $targetBranch
96+ Write-Output " Changes committed and pushed to existing branch: $targetBranch "
97+ } else {
98+ # Push new branch and create PR
99+ Run git push -- set-upstream origin $targetBranch
117100
118- Invoke-NativeCommand gh pr create `
119- -- base $defaultBranch `
120- -- head $targetBranch `
121- -- title " Auto-Update: NerdFonts Data ($timeStamp )" `
122- -- body ' This PR updates FontsData.json with the latest NerdFonts metadata.'
101+ Run gh pr create `
102+ -- base $defaultBranch `
103+ -- head $targetBranch `
104+ -- title " Auto-Update: NerdFonts Data ($timeStamp )" `
105+ -- body ' This PR updates FontsData.json with the latest NerdFonts metadata.'
123106
124- Write-Output " Changes detected and PR opened for branch: $targetBranch "
125- }
126- } else {
127- Write-Output ' No changes to commit.'
107+ Write-Output " Changes detected and PR opened for branch: $targetBranch "
128108}
0 commit comments