Skip to content

Commit

Permalink
Update google fonts on release instead of on a schedule (#461)
Browse files Browse the repository at this point in the history
* Run google fonts update on release, automerge

* add missing & line end

* add --squash to pr merge

* split update and commit

* Uncomment repo check

It was commented out for testing on a fork.

* Remove date print on workflow log
  • Loading branch information
vcanales authored Oct 31, 2023
1 parent dab55a3 commit d6fb04f
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 65 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/deploy-to-dotorg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,40 @@ on:
- minor
- patch
jobs:
update-google-fonts-json:
if: github.repository_owner == 'WordPress'
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18

# Runs a single command using the runners shell
# This script fetchs the Goolgle Fonts API data and creates a PR if new data is available
- name: Update Google Fonts JSON file
env:
GOOGLE_FONTS_API_KEY: ${{ secrets.GOOGLE_FONTS_API_KEY }}
run: |
echo "Updating Google fonts JSON file"
node ./update-google-fonts-json-file.js
- name: Commit Changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git config --global --add --bool push.autoSetupRemote true
git diff-index --quiet HEAD -- || \
( git add assets/google-fonts/fallback-fonts-list.json && \
git checkout trunk && \
git commit -m "Automation: update Google Fonts data file" --no-verify && \
git push
)
tag:
name: Checkout repo
runs-on: ubuntu-latest
Expand Down
45 changes: 0 additions & 45 deletions .github/workflows/update-google-fonts-data.yml

This file was deleted.

46 changes: 26 additions & 20 deletions update-google-fonts-json-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,35 @@ async function updateFiles() {
}

if ( newData.items ) {
const newDataString = JSON.stringify( newData, null, 2 );

const oldFileData = fs.readFileSync(
'./assets/google-fonts/fallback-fonts-list.json',
'utf8'
);
const oldData = JSON.parse( oldFileData );
const oldDataString = JSON.stringify( oldData, null, 2 );

if (
calculateHash( newDataString ) !== calculateHash( oldDataString )
) {
fs.writeFileSync(
try {
const newDataString = JSON.stringify( newData, null, 2 );
const oldFileData = fs.readFileSync(
'./assets/google-fonts/fallback-fonts-list.json',
newDataString
'utf8'
);
// TODO: show in UI and remove console statement
// eslint-disable-next-line
console.info( '✅ Google Fonts JSON file updated' );
} else {
// TODO: show in UI and remove console statement
const oldData = JSON.parse( oldFileData );
const oldDataString = JSON.stringify( oldData, null, 2 );

if (
calculateHash( newDataString ) !==
calculateHash( oldDataString )
) {
fs.writeFileSync(
'./assets/google-fonts/fallback-fonts-list.json',
newDataString
);
// TODO: show in UI and remove console statement
// eslint-disable-next-line
console.info( '✅ Google Fonts JSON file updated' );
} else {
// TODO: show in UI and remove console statement
// eslint-disable-next-line
console.info( 'ℹ️ Google Fonts JSON file is up to date' );
}
} catch ( error ) {
// eslint-disable-next-line
console.info( 'ℹ️ Google Fonts JSON file is up to date' );
console.error( '❎ Error stringifying the new JSON data:', error );
process.exit( 1 );
}
} else {
// TODO: show in UI and remove console statement
Expand Down

0 comments on commit d6fb04f

Please sign in to comment.