Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update google fonts on release instead of on a schedule #461

Merged
merged 6 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
38 changes: 38 additions & 0 deletions .github/workflows/deploy-to-dotorg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,44 @@ 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

- name: Get current date
id: date
run: echo "{date}={$(date +'%Y-%m-%d')}" >> $GITHUB_OUTPUT
vcanales marked this conversation as resolved.
Show resolved Hide resolved

# 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
Loading