From ba37e694edfd8fc0cedb89976235e7c0e17071d0 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 22 Jul 2025 09:21:13 +0200 Subject: [PATCH 01/12] Refactor Update-FontsData script to use a native command function for improved command execution and error handling --- .github/workflows/Update-FontsData.yml | 7 +-- scripts/Update-FontsData.ps1 | 71 +++++++++++++++++--------- 2 files changed, 50 insertions(+), 28 deletions(-) diff --git a/.github/workflows/Update-FontsData.yml b/.github/workflows/Update-FontsData.yml index 0b6e788..e442043 100644 --- a/.github/workflows/Update-FontsData.yml +++ b/.github/workflows/Update-FontsData.yml @@ -5,7 +5,9 @@ on: schedule: - cron: '0 0 * * *' -permissions: {} +permissions: + contents: write + pull-requests: write jobs: Update-FontsData: @@ -15,6 +17,7 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 with: + fetch-depth: 0 persist-credentials: false - name: Update-FontsData @@ -22,6 +25,4 @@ jobs: env: GOOGLE_DEVELOPER_API_KEY: ${{ secrets.GOOGLE_DEVELOPER_API_KEY }} with: - ClientID: ${{ secrets.GOOGLEFONTS_UPDATER_BOT_CLIENT_ID }} - PrivateKey: ${{ secrets.GOOGLEFONTS_UPDATER_BOT_PRIVATE_KEY }} Script: scripts/Update-FontsData.ps1 diff --git a/scripts/Update-FontsData.ps1 b/scripts/Update-FontsData.ps1 index 5ee34ac..236f96b 100644 --- a/scripts/Update-FontsData.ps1 +++ b/scripts/Update-FontsData.ps1 @@ -1,25 +1,50 @@ -Connect-GitHubApp -Organization PSModule -Default +function Invoke-NativeCommand { + <# + .SYNOPSIS + Executes a native command with arguments. + #> + [Alias('Exec', 'Run')] + [CmdletBinding()] + param ( + # The command to execute + [Parameter(Mandatory, Position = 0)] + [string]$Command, -git checkout main -git pull + # The arguments to pass to the command + [Parameter(ValueFromRemainingArguments)] + [string[]]$Arguments + ) -# 2. Retrieve the date-time to create a unique branch name. + Write-Debug "Command: $Command" + Write-Debug "Arguments: $($Arguments -join ', ')" + $fullCommand = "$Command $($Arguments -join ' ')" + + try { + Write-Verbose "Executing: $fullCommand" + & $Command @Arguments + if ($LASTEXITCODE -ne 0) { + $errorMessage = "Command failed with exit code $LASTEXITCODE`: $fullCommand" + Write-Error $errorMessage -ErrorId 'NativeCommandFailed' -Category OperationStopped -TargetObject $fullCommand + } + } catch { + throw + } +} + +Invoke-NativeCommand git checkout main +Invoke-NativeCommand git pull $timeStamp = Get-Date -Format 'yyyyMMdd-HHmmss' $branchName = "auto-font-update-$timeStamp" +Invoke-NativeCommand git checkout -b $branchName -# 3. Create a new branch for the changes. -git checkout -b $branchName - -# 4. Retrieve the latest font data from Google Fonts. -$GOOGLE_DEVELOPER_API_KEY = $env:GOOGLE_DEVELOPER_API_KEY -$fontList = Invoke-RestMethod -Uri "https://www.googleapis.com/webfonts/v1/webfonts?key=$GOOGLE_DEVELOPER_API_KEY" +$fontList = Invoke-RestMethod -Uri "https://www.googleapis.com/webfonts/v1/webfonts?key=$env:GOOGLE_DEVELOPER_API_KEY" $fontFamilies = $fontList.items $fonts = @() foreach ($fontFamily in $fontFamilies) { $variants = $fontFamily.files.PSObject.Properties foreach ($variant in $variants) { - $fonts += [ordered]@{ + $fonts += [PSCustomObject]@{ Name = $fontFamily.family Variant = $variant.Name URL = $variant.Value @@ -27,25 +52,21 @@ foreach ($fontFamily in $fontFamilies) { } } -# 5. Write results to FontsData.json. +LogGroup 'Latest Fonts' { + $fonts | Sort-Object Name | Format-Table -AutoSize | Out-String +} + $parentFolder = Split-Path -Path $PSScriptRoot -Parent $filePath = Join-Path -Path $parentFolder -ChildPath 'src\FontsData.json' - -# Make sure file exists (or overwrite). $null = New-Item -Path $filePath -ItemType File -Force -$fonts | ConvertTo-Json -Depth 10 | Out-File -FilePath $filePath -Force +$fonts | ConvertTo-Json | Set-Content -Path $filePath -Force -# 6. Check if anything actually changed. -# If git status --porcelain is empty, there are no new changes to commit. -$changes = git status --porcelain +$changes = Invoke-NativeCommand git status --porcelain if (-not [string]::IsNullOrWhiteSpace($changes)) { - # 7. Commit and push changes. - git add . - git commit -m "Update-FontsData via script on $timeStamp" - git push --set-upstream origin $branchName - - # 8. Create a PR via GitHub CLI. - gh pr create ` + Invoke-NativeCommand git add . + Invoke-NativeCommand git commit -m "Update-FontsData via script on $timeStamp" + Invoke-NativeCommand git push --set-upstream origin $branchName + Invoke-NativeCommand gh pr create ` --base main ` --head $branchName ` --title "Auto-Update: Google Fonts Data ($timeStamp)" ` From f4a4af6a71cdb40db72b8cae26cc2342bc90390a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 22 Jul 2025 10:59:47 +0200 Subject: [PATCH 02/12] Refactor Update-FontsData script to enhance branch handling and commit process with detailed output --- scripts/Update-FontsData.ps1 | 78 ++++++++++++++++++++++++++++++------ 1 file changed, 66 insertions(+), 12 deletions(-) diff --git a/scripts/Update-FontsData.ps1 b/scripts/Update-FontsData.ps1 index 236f96b..e7f2dfa 100644 --- a/scripts/Update-FontsData.ps1 +++ b/scripts/Update-FontsData.ps1 @@ -31,11 +31,36 @@ } } -Invoke-NativeCommand git checkout main -Invoke-NativeCommand git pull +# 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() }) + +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 + $timeStamp = Get-Date -Format 'yyyyMMdd-HHmmss' -$branchName = "auto-font-update-$timeStamp" -Invoke-NativeCommand git checkout -b $branchName + +# Determine target branch based on current context +if ($currentBranch -eq $defaultBranch) { + # Running on main/default branch - create new branch + $targetBranch = "auto-font-update-$timeStamp" + Write-Output "Running on default branch. Creating new branch: $targetBranch" + Invoke-NativeCommand 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 + # Merge latest changes from default branch + Invoke-NativeCommand git merge origin/$defaultBranch +} $fontList = Invoke-RestMethod -Uri "https://www.googleapis.com/webfonts/v1/webfonts?key=$env:GOOGLE_DEVELOPER_API_KEY" $fontFamilies = $fontList.items @@ -63,16 +88,45 @@ $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 + } + Invoke-NativeCommand git add . Invoke-NativeCommand git commit -m "Update-FontsData via script on $timeStamp" - Invoke-NativeCommand git push --set-upstream origin $branchName - Invoke-NativeCommand gh pr create ` - --base main ` - --head $branchName ` - --title "Auto-Update: Google Fonts Data ($timeStamp)" ` - --body 'This PR updates FontsData.json with the latest Google Fonts metadata.' - - Write-Output 'Changes detected and PR opened.' + + # Show the commit that was just created + Write-Output 'Commit created:' + Invoke-NativeCommand git log -1 --oneline + + # Show diff between HEAD and previous commit + Write-Output 'Changes in this commit:' + Invoke-NativeCommand 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 + + Invoke-NativeCommand gh pr create ` + --base $defaultBranch ` + --head $targetBranch ` + --title "Auto-Update: Google Fonts Data ($timeStamp)" ` + --body 'This PR updates FontsData.json with the latest Google Fonts metadata.' + + Write-Output "Changes detected and PR opened for branch: $targetBranch" + } } else { Write-Output 'No changes to commit.' } From 44f003bce4066c305d68a4113eace5025281dc2a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 22 Jul 2025 11:04:55 +0200 Subject: [PATCH 03/12] Remove obsolete font entries from FontsData.json --- src/FontsData.json | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/FontsData.json b/src/FontsData.json index 5868a50..1e73db8 100644 --- a/src/FontsData.json +++ b/src/FontsData.json @@ -9,16 +9,6 @@ "Variant": "italic", "URL": "https://fonts.gstatic.com/s/abeezee/v22/esDT31xSG-6AGleN2tCklZUCGpG-GQ.ttf" }, - { - "Name": "ADLaM Display", - "Variant": "regular", - "URL": "https://fonts.gstatic.com/s/adlamdisplay/v1/KFOhCnGXkPOLlhx6jD8_b1ZECsHYkYBPY3o.ttf" - }, - { - "Name": "AR One Sans", - "Variant": "regular", - "URL": "https://fonts.gstatic.com/s/aronesans/v5/TUZezwhrmbFp0Srr_tH6fv6RcUejHO_u7GF5aXfv-U2QzBLF6gslWn_9DW03no5mBF4.ttf" - }, { "Name": "AR One Sans", "Variant": "500", From a47c76a21d2c08f86d0094d3ab4dcc7b89315add Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 22 Jul 2025 11:20:02 +0200 Subject: [PATCH 04/12] Refactor Invoke-NativeCommand function to streamline command and argument handling --- scripts/Update-FontsData.ps1 | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/scripts/Update-FontsData.ps1 b/scripts/Update-FontsData.ps1 index e7f2dfa..1bedf97 100644 --- a/scripts/Update-FontsData.ps1 +++ b/scripts/Update-FontsData.ps1 @@ -7,21 +7,19 @@ [CmdletBinding()] param ( # The command to execute - [Parameter(Mandatory, Position = 0)] - [string]$Command, - - # The arguments to pass to the command [Parameter(ValueFromRemainingArguments)] - [string[]]$Arguments + [string[]]$InputObject ) - Write-Debug "Command: $Command" - Write-Debug "Arguments: $($Arguments -join ', ')" - $fullCommand = "$Command $($Arguments -join ' ')" + $command = $inputObject[0] + $arguments = $inputObject[1..$inputObject.Length] + Write-Debug "Command: $command" + Write-Debug "Arguments: $($arguments -join ', ')" + $fullCommand = "$command $($arguments -join ' ')" try { Write-Verbose "Executing: $fullCommand" - & $Command @Arguments + & $command @arguments if ($LASTEXITCODE -ne 0) { $errorMessage = "Command failed with exit code $LASTEXITCODE`: $fullCommand" Write-Error $errorMessage -ErrorId 'NativeCommandFailed' -Category OperationStopped -TargetObject $fullCommand From e5b718312ab9f2ec70b30353d7269a89f12e1a33 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 22 Jul 2025 12:08:05 +0200 Subject: [PATCH 05/12] Refactor Invoke-NativeCommand function to improve argument processing and error handling --- scripts/Update-FontsData.ps1 | 38 +++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/scripts/Update-FontsData.ps1 b/scripts/Update-FontsData.ps1 index 1bedf97..0bb261f 100644 --- a/scripts/Update-FontsData.ps1 +++ b/scripts/Update-FontsData.ps1 @@ -11,21 +11,31 @@ [string[]]$InputObject ) - $command = $inputObject[0] - $arguments = $inputObject[1..$inputObject.Length] - Write-Debug "Command: $command" - Write-Debug "Arguments: $($arguments -join ', ')" - $fullCommand = "$command $($arguments -join ' ')" - - try { - Write-Verbose "Executing: $fullCommand" - & $command @arguments - if ($LASTEXITCODE -ne 0) { - $errorMessage = "Command failed with exit code $LASTEXITCODE`: $fullCommand" - Write-Error $errorMessage -ErrorId 'NativeCommandFailed' -Category OperationStopped -TargetObject $fullCommand + process { + Write-Debug "InputObject: $InputObject" + foreach ($item in $InputObject) { + Write-Debug "Processing item: $item" + $commandwitharguments = $InputObject -join ' ' + } + } + + end { + $command = $inputObject[0] + $arguments = $inputObject[1..$inputObject.Length] + Write-Debug "Command: $command" + Write-Debug "Arguments: $($arguments -join ', ')" + $fullCommand = "$command $($arguments -join ' ')" + + try { + Write-Verbose "Executing: $fullCommand" + & $command @arguments + if ($LASTEXITCODE -ne 0) { + $errorMessage = "Command failed with exit code $LASTEXITCODE`: $fullCommand" + Write-Error $errorMessage -ErrorId 'NativeCommandFailed' -Category OperationStopped -TargetObject $fullCommand + } + } catch { + throw } - } catch { - throw } } From de91f831f07bcd66e1bcbbfe3980580df55f661d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 22 Jul 2025 12:20:55 +0200 Subject: [PATCH 06/12] Refactor Update-FontsData script to replace Invoke-NativeCommand with Run for improved command execution consistency --- scripts/Update-FontsData.ps1 | 77 ++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 44 deletions(-) diff --git a/scripts/Update-FontsData.ps1 b/scripts/Update-FontsData.ps1 index 0bb261f..75443ae 100644 --- a/scripts/Update-FontsData.ps1 +++ b/scripts/Update-FontsData.ps1 @@ -8,50 +8,39 @@ param ( # The command to execute [Parameter(ValueFromRemainingArguments)] - [string[]]$InputObject + [string[]]$Command ) - - process { - Write-Debug "InputObject: $InputObject" - foreach ($item in $InputObject) { - Write-Debug "Processing item: $item" - $commandwitharguments = $InputObject -join ' ' - } - } - - end { - $command = $inputObject[0] - $arguments = $inputObject[1..$inputObject.Length] - Write-Debug "Command: $command" - Write-Debug "Arguments: $($arguments -join ', ')" - $fullCommand = "$command $($arguments -join ' ')" - - try { - Write-Verbose "Executing: $fullCommand" - & $command @arguments - if ($LASTEXITCODE -ne 0) { - $errorMessage = "Command failed with exit code $LASTEXITCODE`: $fullCommand" - Write-Error $errorMessage -ErrorId 'NativeCommandFailed' -Category OperationStopped -TargetObject $fullCommand - } - } catch { - throw + $cmd = $Command[0] + $args = $Command[1..$Command.Length] + Write-Debug "Command: $cmd" + Write-Debug "Arguments: $($args -join ', ')" + $fullCommand = "$cmd $($args -join ' ')" + + try { + Write-Verbose "Executing: $fullCommand" + & $cmd @args + if ($LASTEXITCODE -ne 0) { + $errorMessage = "Command failed with exit code $LASTEXITCODE`: $fullCommand" + Write-Error $errorMessage -ErrorId 'NativeCommandFailed' -Category OperationStopped -TargetObject $fullCommand } + } catch { + throw } } # 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 +Run git fetch origin # Get the head branch (latest default branch) -Invoke-NativeCommand git checkout $defaultBranch -Invoke-NativeCommand git pull origin $defaultBranch +Run git checkout $defaultBranch +Run git pull origin $defaultBranch $timeStamp = Get-Date -Format 'yyyyMMdd-HHmmss' @@ -60,14 +49,14 @@ if ($currentBranch -eq $defaultBranch) { # Running on main/default branch - create new branch $targetBranch = "auto-font-update-$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 } $fontList = Invoke-RestMethod -Uri "https://www.googleapis.com/webfonts/v1/webfonts?key=$env:GOOGLE_DEVELOPER_API_KEY" @@ -94,40 +83,40 @@ $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 +$changes = Run 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 + Run 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 + Run git diff HEAD -- src/FontsData.json } - Invoke-NativeCommand git add . - Invoke-NativeCommand git commit -m "Update-FontsData via script on $timeStamp" + Run git add . + Run git commit -m "Update-FontsData via script on $timeStamp" # Show the commit that was just created Write-Output 'Commit created:' - Invoke-NativeCommand git log -1 --oneline + Run git log -1 --oneline # 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 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 + Run 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 + Run git push --set-upstream origin $targetBranch - Invoke-NativeCommand gh pr create ` + Run gh pr create ` --base $defaultBranch ` --head $targetBranch ` --title "Auto-Update: Google Fonts Data ($timeStamp)" ` From dfe02cdeef8c909021617723c09bbadacd8a39d0 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 22 Jul 2025 12:26:40 +0200 Subject: [PATCH 07/12] Refactor Invoke-NativeCommand function to improve variable naming and enhance command execution clarity --- scripts/Update-FontsData.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/Update-FontsData.ps1 b/scripts/Update-FontsData.ps1 index 75443ae..20a3b1b 100644 --- a/scripts/Update-FontsData.ps1 +++ b/scripts/Update-FontsData.ps1 @@ -11,14 +11,14 @@ [string[]]$Command ) $cmd = $Command[0] - $args = $Command[1..$Command.Length] + $arguments = $Command[1..$Command.Length] Write-Debug "Command: $cmd" - Write-Debug "Arguments: $($args -join ', ')" - $fullCommand = "$cmd $($args -join ' ')" + Write-Debug "Arguments: $($arguments -join ', ')" + $fullCommand = "$cmd $($arguments -join ' ')" try { Write-Verbose "Executing: $fullCommand" - & $cmd @args + & $cmd @arguments if ($LASTEXITCODE -ne 0) { $errorMessage = "Command failed with exit code $LASTEXITCODE`: $fullCommand" Write-Error $errorMessage -ErrorId 'NativeCommandFailed' -Category OperationStopped -TargetObject $fullCommand From 8aaec15c6cf5d2737a7f3c4da27e5b3dfc24ab5f Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions@users.noreply.github.com> Date: Tue, 22 Jul 2025 10:40:12 +0000 Subject: [PATCH 08/12] Update-FontsData via script on 20250722-104010 --- src/FontsData.json | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/FontsData.json b/src/FontsData.json index 1e73db8..5868a50 100644 --- a/src/FontsData.json +++ b/src/FontsData.json @@ -9,6 +9,16 @@ "Variant": "italic", "URL": "https://fonts.gstatic.com/s/abeezee/v22/esDT31xSG-6AGleN2tCklZUCGpG-GQ.ttf" }, + { + "Name": "ADLaM Display", + "Variant": "regular", + "URL": "https://fonts.gstatic.com/s/adlamdisplay/v1/KFOhCnGXkPOLlhx6jD8_b1ZECsHYkYBPY3o.ttf" + }, + { + "Name": "AR One Sans", + "Variant": "regular", + "URL": "https://fonts.gstatic.com/s/aronesans/v5/TUZezwhrmbFp0Srr_tH6fv6RcUejHO_u7GF5aXfv-U2QzBLF6gslWn_9DW03no5mBF4.ttf" + }, { "Name": "AR One Sans", "Variant": "500", From ec622877f16a417b1665db5c93e9ad1e1eba84e8 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 22 Jul 2025 18:59:17 +0200 Subject: [PATCH 09/12] Refactor Update-FontsData script to enhance readability and streamline change detection logic --- scripts/Update-FontsData.ps1 | 97 +++++++++++++++--------------------- 1 file changed, 40 insertions(+), 57 deletions(-) diff --git a/scripts/Update-FontsData.ps1 b/scripts/Update-FontsData.ps1 index 20a3b1b..5564251 100644 --- a/scripts/Update-FontsData.ps1 +++ b/scripts/Update-FontsData.ps1 @@ -28,26 +28,19 @@ } } -# Get the current branch and default branch information $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 Run git fetch origin - -# Get the head branch (latest default branch) 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" Run git checkout -b $targetBranch } else { @@ -59,22 +52,22 @@ if ($currentBranch -eq $defaultBranch) { Run git merge origin/$defaultBranch } -$fontList = Invoke-RestMethod -Uri "https://www.googleapis.com/webfonts/v1/webfonts?key=$env:GOOGLE_DEVELOPER_API_KEY" -$fontFamilies = $fontList.items -$fonts = @() - -foreach ($fontFamily in $fontFamilies) { - $variants = $fontFamily.files.PSObject.Properties - foreach ($variant in $variants) { - $fonts += [PSCustomObject]@{ - Name = $fontFamily.family - Variant = $variant.Name - URL = $variant.Value +LogGroup 'Latest Fonts' { + $fontList = Invoke-RestMethod -Uri "https://www.googleapis.com/webfonts/v1/webfonts?key=$env:GOOGLE_DEVELOPER_API_KEY" + $fontFamilies = $fontList.items + $fonts = @() + + foreach ($fontFamily in $fontFamilies) { + $variants = $fontFamily.files.PSObject.Properties + foreach ($variant in $variants) { + $fonts += [PSCustomObject]@{ + Name = $fontFamily.family + Variant = $variant.Name + URL = $variant.Value + } } } -} -LogGroup 'Latest Fonts' { $fonts | Sort-Object Name | Format-Table -AutoSize | Out-String } @@ -84,46 +77,36 @@ $null = New-Item -Path $filePath -ItemType File -Force $fonts | ConvertTo-Json | Set-Content -Path $filePath -Force $changes = Run 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:' - Run git diff --cached HEAD -- src/FontsData.json 2>$null - if ($LASTEXITCODE -ne 0) { - # If --cached doesn't work (no staged changes), show unstaged diff - Run git diff HEAD -- src/FontsData.json - } +if ([string]::IsNullOrWhiteSpace($changes)) { + Write-Output 'No changes detected.' + return +} - Run git add . - Run 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:' - Run 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:' - Run 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 - 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 +# 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 - Run gh pr create ` - --base $defaultBranch ` - --head $targetBranch ` - --title "Auto-Update: Google Fonts Data ($timeStamp)" ` - --body 'This PR updates FontsData.json with the latest Google Fonts metadata.' + Run gh pr create ` + --base $defaultBranch ` + --head $targetBranch ` + --title "Auto-Update: Google Fonts Data ($timeStamp)" ` + --body 'This PR updates FontsData.json with the latest Google Fonts 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 a37d2e19a1ec9ac14aaff6bb05ed79b516b8923a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 22 Jul 2025 19:09:54 +0200 Subject: [PATCH 10/12] Remove ADLaM Display font entry from FontsData.json --- src/FontsData.json | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/FontsData.json b/src/FontsData.json index 5868a50..7bfb071 100644 --- a/src/FontsData.json +++ b/src/FontsData.json @@ -9,11 +9,6 @@ "Variant": "italic", "URL": "https://fonts.gstatic.com/s/abeezee/v22/esDT31xSG-6AGleN2tCklZUCGpG-GQ.ttf" }, - { - "Name": "ADLaM Display", - "Variant": "regular", - "URL": "https://fonts.gstatic.com/s/adlamdisplay/v1/KFOhCnGXkPOLlhx6jD8_b1ZECsHYkYBPY3o.ttf" - }, { "Name": "AR One Sans", "Variant": "regular", From 6549d4c20235059da0d7314fca0717340d794083 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 22 Jul 2025 19:52:32 +0200 Subject: [PATCH 11/12] Remove redundant output for detected changes and diff in Update-FontsData script --- scripts/Update-FontsData.ps1 | 6 ------ 1 file changed, 6 deletions(-) diff --git a/scripts/Update-FontsData.ps1 b/scripts/Update-FontsData.ps1 index 5564251..0450c1f 100644 --- a/scripts/Update-FontsData.ps1 +++ b/scripts/Update-FontsData.ps1 @@ -82,12 +82,6 @@ if ([string]::IsNullOrWhiteSpace($changes)) { return } -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 94200eba84ca77ec6b24b44f3779707835f3f072 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions@users.noreply.github.com> Date: Tue, 22 Jul 2025 18:26:30 +0000 Subject: [PATCH 12/12] Update-FontsData via script on 20250722-182628 --- src/FontsData.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/FontsData.json b/src/FontsData.json index 7bfb071..5868a50 100644 --- a/src/FontsData.json +++ b/src/FontsData.json @@ -9,6 +9,11 @@ "Variant": "italic", "URL": "https://fonts.gstatic.com/s/abeezee/v22/esDT31xSG-6AGleN2tCklZUCGpG-GQ.ttf" }, + { + "Name": "ADLaM Display", + "Variant": "regular", + "URL": "https://fonts.gstatic.com/s/adlamdisplay/v1/KFOhCnGXkPOLlhx6jD8_b1ZECsHYkYBPY3o.ttf" + }, { "Name": "AR One Sans", "Variant": "regular",