From 1b35913e6037dc4e4d5ad634b7e94f69fd34f418 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 22 Jul 2025 19:00:00 +0200 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Refactor=20comman?= =?UTF-8?q?d=20execution=20and=20streamline=20Git=20operations=20in=20Upda?= =?UTF-8?q?te-FontsData.ps1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/Update-FontsData.ps1 | 126 +++++++++++++++-------------------- 1 file changed, 53 insertions(+), 73 deletions(-) diff --git a/scripts/Update-FontsData.ps1 b/scripts/Update-FontsData.ps1 index 981e66a..482cee7 100644 --- a/scripts/Update-FontsData.ps1 +++ b/scripts/Update-FontsData.ps1 @@ -7,21 +7,18 @@ [CmdletBinding()] param ( # The command to execute - [Parameter(Mandatory, Position = 0)] - [string]$Command, - - # The arguments to pass to the command [Parameter(ValueFromRemainingArguments)] - [string[]]$Arguments + [string[]]$Command ) - - Write-Debug "Command: $Command" - Write-Debug "Arguments: $($Arguments -join ', ')" - $fullCommand = "$Command $($Arguments -join ' ')" + $cmd = $Command[0] + $arguments = $Command[1..$Command.Length] + Write-Debug "Command: $cmd" + Write-Debug "Arguments: $($arguments -join ', ')" + $fullCommand = "$cmd $($arguments -join ' ')" try { Write-Verbose "Executing: $fullCommand" - & $Command @Arguments + & $cmd @arguments if ($LASTEXITCODE -ne 0) { $errorMessage = "Command failed with exit code $LASTEXITCODE`: $fullCommand" Write-Error $errorMessage -ErrorId 'NativeCommandFailed' -Category OperationStopped -TargetObject $fullCommand @@ -31,49 +28,42 @@ } } -# Get the current branch and default branch information -$currentBranch = (Invoke-NativeCommand git rev-parse --abbrev-ref HEAD).Trim() -$defaultBranch = (Invoke-NativeCommand git remote show origin | Select-String 'HEAD branch:' | ForEach-Object { $_.ToString().Split(':')[1].Trim() }) - +$currentBranch = (Run git rev-parse --abbrev-ref HEAD).Trim() +$defaultBranch = (Run git remote show origin | Select-String 'HEAD branch:' | ForEach-Object { $_.ToString().Split(':')[1].Trim() }) Write-Output "Current branch: $currentBranch" Write-Output "Default branch: $defaultBranch" -# Fetch latest changes from remote -Invoke-NativeCommand git fetch origin - -# Get the head branch (latest default branch) -Invoke-NativeCommand git checkout $defaultBranch -Invoke-NativeCommand git pull origin $defaultBranch +Run git fetch origin +Run git checkout $defaultBranch +Run git pull origin $defaultBranch $timeStamp = Get-Date -Format 'yyyyMMdd-HHmmss' - -# Determine target branch based on current context if ($currentBranch -eq $defaultBranch) { # Running on main/default branch - create new branch - $targetBranch = "auto-font-update-$timeStamp" + $targetBranch = "auto-update-font-$timeStamp" Write-Output "Running on default branch. Creating new branch: $targetBranch" - Invoke-NativeCommand git checkout -b $targetBranch + Run git checkout -b $targetBranch } else { # Running on another branch (e.g., workflow_dispatch) - use current branch $targetBranch = $currentBranch Write-Output "Running on feature branch. Using existing branch: $targetBranch" - Invoke-NativeCommand git checkout $targetBranch + Run git checkout $targetBranch # Merge latest changes from default branch - Invoke-NativeCommand git merge origin/$defaultBranch + Run git merge origin/$defaultBranch } -$release = Get-GitHubRelease -Owner ryanoasis -Repository nerd-fonts -$fonts = @() -$fontAssets = $release | Get-GitHubReleaseAsset | Where-Object { $_.Name -like '*.zip' } - -foreach ($fontArchive in $fontAssets) { - $fonts += [PSCustomObject]@{ - Name = $fontArchive.Name.Split('.')[0] - URL = $fontArchive.Url +LogGroup 'Latest Fonts' { + $release = Get-GitHubRelease -Owner ryanoasis -Repository nerd-fonts + $fonts = @() + $fontAssets = $release | Get-GitHubReleaseAsset | Where-Object { $_.Name -like '*.zip' } + + foreach ($fontArchive in $fontAssets) { + $fonts += [PSCustomObject]@{ + Name = $fontArchive.Name.Split('.')[0] + URL = $fontArchive.Url + } } -} -LogGroup 'Latest Fonts' { $fonts | Sort-Object Name | Format-Table -AutoSize | Out-String } @@ -82,47 +72,37 @@ $filePath = Join-Path -Path $parentFolder -ChildPath 'src\FontsData.json' $null = New-Item -Path $filePath -ItemType File -Force $fonts | ConvertTo-Json | Set-Content -Path $filePath -Force -$changes = Invoke-NativeCommand git status --porcelain -if (-not [string]::IsNullOrWhiteSpace($changes)) { - Write-Output 'Changes detected:' - Write-Output $changes - - # Show what will be committed - Write-Output 'Diff of changes to be committed:' - Invoke-NativeCommand git diff --cached HEAD -- src/FontsData.json 2>$null - if ($LASTEXITCODE -ne 0) { - # If --cached doesn't work (no staged changes), show unstaged diff - Invoke-NativeCommand git diff HEAD -- src/FontsData.json - } +$changes = Run git status --porcelain +if ([string]::IsNullOrWhiteSpace($changes)) { + Write-Output 'No changes detected.' + return +} - Invoke-NativeCommand git add . - Invoke-NativeCommand git commit -m "Update-FontsData via script on $timeStamp" +Write-Output 'Changes detected:' +Write-Output $changes - # Show the commit that was just created - Write-Output 'Commit created:' - Invoke-NativeCommand git log -1 --oneline +Write-Output 'Diff of changes to be committed:' +Run git diff HEAD -- src/FontsData.json - # Show diff between HEAD and previous commit - Write-Output 'Changes in this commit:' - Invoke-NativeCommand git diff HEAD~1 HEAD -- src/FontsData.json +Run git add . +Run git commit -m "Update-FontsData via script on $timeStamp" +Write-Output 'Changes in this commit:' +Run git diff HEAD~1 HEAD -- src/FontsData.json - # Push behavior depends on branch type - if ($targetBranch -eq $currentBranch -and $currentBranch -ne $defaultBranch) { - # Push to existing branch - Invoke-NativeCommand git push origin $targetBranch - Write-Output "Changes committed and pushed to existing branch: $targetBranch" - } else { - # Push new branch and create PR - Invoke-NativeCommand git push --set-upstream origin $targetBranch +# Push behavior depends on branch type +if ($targetBranch -eq $currentBranch -and $currentBranch -ne $defaultBranch) { + # Push to existing branch + Run git push origin $targetBranch + Write-Output "Changes committed and pushed to existing branch: $targetBranch" +} else { + # Push new branch and create PR + Run git push --set-upstream origin $targetBranch - Invoke-NativeCommand gh pr create ` - --base $defaultBranch ` - --head $targetBranch ` - --title "Auto-Update: NerdFonts Data ($timeStamp)" ` - --body 'This PR updates FontsData.json with the latest NerdFonts metadata.' + Run gh pr create ` + --base $defaultBranch ` + --head $targetBranch ` + --title "Auto-Update: NerdFonts Data ($timeStamp)" ` + --body 'This PR updates FontsData.json with the latest NerdFonts metadata.' - Write-Output "Changes detected and PR opened for branch: $targetBranch" - } -} else { - Write-Output 'No changes to commit.' + Write-Output "Changes detected and PR opened for branch: $targetBranch" } From 746cf9d052a82afc54e9c40d4d7adc3d555b8eb0 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 22 Jul 2025 19:10:42 +0200 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Remove=20obsolete?= =?UTF-8?q?=20font=20entries=20for=20AdwaitaMono=20and=20Agave=20from=20Fo?= =?UTF-8?q?ntsData.json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/FontsData.json | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/FontsData.json b/src/FontsData.json index 8eaba6d..22b7f6c 100644 --- a/src/FontsData.json +++ b/src/FontsData.json @@ -7,14 +7,6 @@ "Name": "3270", "URL": "https://github.com/ryanoasis/nerd-fonts/releases/download/v3.4.0/3270.zip" }, - { - "Name": "AdwaitaMono", - "URL": "https://github.com/ryanoasis/nerd-fonts/releases/download/v3.4.0/AdwaitaMono.zip" - }, - { - "Name": "Agave", - "URL": "https://github.com/ryanoasis/nerd-fonts/releases/download/v3.4.0/Agave.zip" - }, { "Name": "AnonymousPro", "URL": "https://github.com/ryanoasis/nerd-fonts/releases/download/v3.4.0/AnonymousPro.zip" From 8e069a2f15d50476cf2ec5c78d92cb9bd1a8bb11 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions@users.noreply.github.com> Date: Tue, 22 Jul 2025 17:18:05 +0000 Subject: [PATCH 3/5] Update-FontsData via script on 20250722-171803 --- src/FontsData.json | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/FontsData.json b/src/FontsData.json index 22b7f6c..8eaba6d 100644 --- a/src/FontsData.json +++ b/src/FontsData.json @@ -7,6 +7,14 @@ "Name": "3270", "URL": "https://github.com/ryanoasis/nerd-fonts/releases/download/v3.4.0/3270.zip" }, + { + "Name": "AdwaitaMono", + "URL": "https://github.com/ryanoasis/nerd-fonts/releases/download/v3.4.0/AdwaitaMono.zip" + }, + { + "Name": "Agave", + "URL": "https://github.com/ryanoasis/nerd-fonts/releases/download/v3.4.0/Agave.zip" + }, { "Name": "AnonymousPro", "URL": "https://github.com/ryanoasis/nerd-fonts/releases/download/v3.4.0/AnonymousPro.zip" From 7badfa728a5400d19a04d508948b5e0bb557769c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 22 Jul 2025 19:41:36 +0200 Subject: [PATCH 4/5] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Remove=20diff=20o?= =?UTF-8?q?utput=20for=20changes=20to=20be=20committed=20in=20Update-Fonts?= =?UTF-8?q?Data.ps1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/Update-FontsData.ps1 | 4 ---- 1 file changed, 4 deletions(-) diff --git a/scripts/Update-FontsData.ps1 b/scripts/Update-FontsData.ps1 index 482cee7..e5406e8 100644 --- a/scripts/Update-FontsData.ps1 +++ b/scripts/Update-FontsData.ps1 @@ -80,10 +80,6 @@ if ([string]::IsNullOrWhiteSpace($changes)) { Write-Output 'Changes detected:' Write-Output $changes - -Write-Output 'Diff of changes to be committed:' -Run git diff HEAD -- src/FontsData.json - Run git add . Run git commit -m "Update-FontsData via script on $timeStamp" Write-Output 'Changes in this commit:' From a0f8956408bfabd14467fac0997ac2e47cd6d1ad Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 22 Jul 2025 19:52:31 +0200 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Remove=20output?= =?UTF-8?q?=20of=20detected=20changes=20before=20git=20add=20in=20Update-F?= =?UTF-8?q?ontsData.ps1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/Update-FontsData.ps1 | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/Update-FontsData.ps1 b/scripts/Update-FontsData.ps1 index e5406e8..7ee0d19 100644 --- a/scripts/Update-FontsData.ps1 +++ b/scripts/Update-FontsData.ps1 @@ -78,8 +78,6 @@ if ([string]::IsNullOrWhiteSpace($changes)) { return } -Write-Output 'Changes detected:' -Write-Output $changes Run git add . Run git commit -m "Update-FontsData via script on $timeStamp" Write-Output 'Changes in this commit:'