Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
a777a28
🩹 [Patch]: Simplify permissions in Update-FontsData workflow
MariusStorhaug Jul 23, 2025
6e9ccc2
🩹 [Patch]: Add Connect-GitHubApp command to Update-FontsData script
MariusStorhaug Jul 23, 2025
3518b7c
Update-FontsData via script on 20250723-090541
googlefonts-updater[bot] Jul 23, 2025
afba786
🩹 [Patch]: Refactor checkout process in Update-FontsData script for i…
MariusStorhaug Jul 23, 2025
98da69a
🩹 [Patch]: Update log group names for consistency and clarity in Upda…
MariusStorhaug Jul 23, 2025
ee4e5df
🩹 [Patch]: Update output messages and enhance GitHub summary in Updat…
MariusStorhaug Jul 23, 2025
a7d2178
Update-FontsData via script on 20250723-093544
googlefonts-updater[bot] Jul 23, 2025
22d1cbe
🩹 [Patch]: Enhance output handling in Invoke-NativeCommand and update…
MariusStorhaug Jul 23, 2025
c6e7836
🩹 [Patch]: Update method for retrieving default branch in Checkout lo…
MariusStorhaug Jul 23, 2025
3aea2e2
🩹 [Patch]: Update method for retrieving default branch in Checkout lo…
MariusStorhaug Jul 23, 2025
bfb07d9
Update-FontsData via script on 20250723-102247
googlefonts-updater[bot] Jul 23, 2025
e19bdfc
🩹 [Patch]: Enhance GitHub step summary formatting in Update-FontsData…
MariusStorhaug Jul 23, 2025
4809165
Merge branch 'reintroGHAPP' of https://github.com/PSModule/GoogleFont…
MariusStorhaug Jul 23, 2025
3e6984d
🩹 [Patch]: Remove deprecated Google Sans Code font entries from Fonts…
MariusStorhaug Jul 23, 2025
e8a0bbd
Update-FontsData via script on 20250723-103320
googlefonts-updater[bot] Jul 23, 2025
fc892c0
🩹 [Patch]: Remove deprecated Google Sans Code font entries from Fonts…
MariusStorhaug Jul 23, 2025
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
6 changes: 3 additions & 3 deletions .github/workflows/Update-FontsData.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ on:
schedule:
- cron: '0 0 * * *'

permissions:
contents: write
pull-requests: write
permissions: {}

jobs:
Update-FontsData:
Expand All @@ -25,4 +23,6 @@ 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
130 changes: 79 additions & 51 deletions scripts/Update-FontsData.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,51 @@

try {
Write-Verbose "Executing: $fullCommand"
& $cmd @arguments
$output = & $cmd @arguments
if ($LASTEXITCODE -ne 0) {
$errorMessage = "Command failed with exit code $LASTEXITCODE`: $fullCommand"
Write-Error $errorMessage -ErrorId 'NativeCommandFailed' -Category OperationStopped -TargetObject $fullCommand
}
if ($output -is [array] -and $output.Count -gt 1) {
return $output -join "`n"
} else {
return $output
}
} catch {
throw
}
}

$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"

Run git fetch origin
Run git checkout $defaultBranch
Run git pull origin $defaultBranch

$timeStamp = Get-Date -Format 'yyyyMMdd-HHmmss'
if ($currentBranch -eq $defaultBranch) {
# Running on main/default branch - create new branch
$targetBranch = "auto-update-font-$timeStamp"
Write-Output "Running on default branch. Creating new branch: $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"
Run git checkout $targetBranch
# Merge latest changes from default branch
Run git merge origin/$defaultBranch
Connect-GitHubApp -Organization 'PSModule' -Default
$repo = Get-GitHubRepository -Owner 'PSModule' -Name 'GoogleFonts'

LogGroup 'Checkout' {
$currentBranch = (Run git rev-parse --abbrev-ref HEAD).Trim()
$defaultBranch = $repo.DefaultBranch

Write-Output "Current branch: $currentBranch"
Write-Output "Default branch: $defaultBranch"
Run git fetch origin
Run git checkout $defaultBranch
Run git pull origin $defaultBranch

$timeStamp = Get-Date -Format 'yyyyMMdd-HHmmss'
if ($currentBranch -eq $defaultBranch) {
# Running on main/default branch - create new branch
$targetBranch = "auto-update-font-$timeStamp"
Write-Output "Running on default branch. Creating new branch: $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"
Run git checkout $targetBranch
# Merge latest changes from default branch
Run git merge origin/$defaultBranch
}
}

LogGroup 'Latest Fonts' {
LogGroup 'Getting latest fonts' {
$fontList = Invoke-RestMethod -Uri "https://www.googleapis.com/webfonts/v1/webfonts?key=$env:GOOGLE_DEVELOPER_API_KEY"
$fontFamilies = $fontList.items
$fonts = @()
Expand All @@ -69,38 +79,56 @@ 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'
$null = New-Item -Path $filePath -ItemType File -Force
$fonts | ConvertTo-Json | Set-Content -Path $filePath -Force
}

$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

$changes = Run git status --porcelain
if ([string]::IsNullOrWhiteSpace($changes)) {
Write-Output 'No changes detected.'
Write-Output 'No updates available.'
Write-GitHubNotice 'No updates available.'
return
}
LogGroup 'Get changes' {
Run git add .
Run git commit -m "Update-FontsData via script on $timeStamp"
Write-Output 'Changes in this commit:'
$changes = Run git diff HEAD~1 HEAD -- src/FontsData.json
Write-Output $changes
Set-GitHubStepSummary @"
## Changes available

<details><summary>Details</summary>
<p>

``````diff
$changes
``````

</p>
</details>
"@

}

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

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"
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.'

Write-Output "Changes detected and PR opened for branch: $targetBranch"
}
}
Loading