Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions scripts/Update-FontsData.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
}
}

Install-PSResource -Repository PSGallery -TrustRepository -Name 'Json'

Connect-GitHubApp -Organization 'PSModule' -Default
$repo = Get-GitHubRepository -Owner 'PSModule' -Name 'GoogleFonts'

Expand All @@ -49,7 +51,7 @@ LogGroup 'Checkout' {
$timeStamp = Get-Date -Format 'yyyyMMdd-HHmmss'
if ($currentBranch -eq $defaultBranch) {
# Running on main/default branch - create new branch
$targetBranch = "auto-update-font-$timeStamp"
$targetBranch = "auto-update-$timeStamp"
Write-Output "Running on default branch. Creating new branch: $targetBranch"
Run git checkout -b $targetBranch
} else {
Expand Down Expand Up @@ -82,7 +84,7 @@ LogGroup 'Getting latest fonts' {
$parentFolder = Split-Path -Path $PSScriptRoot -Parent
$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
$fonts | ConvertTo-Json | Format-Json -IndentationType Spaces -IndentationSize 4 | Set-Content -Path $filePath -Force
}

$changes = Run git status --porcelain
Expand All @@ -93,7 +95,7 @@ if ([string]::IsNullOrWhiteSpace($changes)) {
}
LogGroup 'Get changes' {
Run git add .
Run git commit -m "Update-FontsData via script on $timeStamp"
Run git commit -m 'Update FontsData.json'
Write-Output 'Changes in this commit:'
$changes = Run git diff HEAD~1 HEAD -- src/FontsData.json
Write-Output $changes
Expand All @@ -114,20 +116,17 @@ $changes
}

LogGroup 'Process changes' {
# 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.'
--title "Auto-Update $timeStamp" `
--body 'This PR updates FontsData.json with the latest metadata.'

Write-Output "Changes detected and PR opened for branch: $targetBranch"
}
Expand Down
5 changes: 5 additions & 0 deletions src/FontsData.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
"Variant": "regular",
"URL": "https://fonts.gstatic.com/s/adlamdisplay/v1/KFOhCnGXkPOLlhx6jD8_b1ZECsHYkYBPY3o.ttf"
},
{
"Name": "Test",
"Variant": "regular",
"URL": "https://fonts.gstatic.com/s/test/v1/abcd1234.ttf"
},
{
"Name": "AR One Sans",
"Variant": "regular",
Expand Down
Loading