I18n script runner #1
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Automatic update i18n files | |
on: | |
pull_request: | |
push: | |
branches: | |
- main # Only care about the main branch, don't care about any PRs or forks | |
- master | |
paths: | |
- client/strings/** # Should only check if any strings changed | |
jobs: | |
update_translations: | |
runs-on: ubuntu-latest | |
steps: | |
# Check out the repository | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
# Set up node to run the javascript | |
- name: Set up node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20" | |
# The action runs the `copy_keys.js` script, which copies any unused keys | |
# from the English language file to other language files, and orders each | |
# file by key alphabetically. | |
# | |
# The only argument is the `directory`, which is where the i18n files are | |
# stored. | |
- name: Run Update JSON Files action | |
uses: audiobookshelf/[email protected] | |
with: | |
directory: "client/strings/" # Adjust the directory path as needed | |
# Does a git diff to see if any language files were changed from running | |
# the script. This will be false if the local script was already ran | |
# locally so no changes are needed for the language files. | |
- name: Check diff of strings | |
run: | | |
if git diff --exit-code; then | |
echo "CHANGED=false" >>${GITHUB_ENV} | |
else | |
echo "CHANGED=true" >>${GITHUB_ENV} | |
fi | |
# If changes were detected, create a branch with the changes and open | |
# a PR to `main`. This requires changing the Workflow Permissions | |
# to be "read and write" to create the branch and commit, and then | |
# also need to enable "Allow GitHub actions to create and approve PR" | |
# so the PR can actually be made. Also set up secrets for user email | |
# name if anyone cares about that since it's available in git logs anyway. | |
- name: If changes, commit and open PR | |
if: ${{ env.CHANGED == 'true' }} | |
run: | | |
branch_name="update-strings-$(git log --format=%h -n 1)" | |
git config user.email "${{secrets.USER_EMAIL}}" | |
git config user.name "${{secrets.USER_NAME}}" | |
git checkout -b $branch_name | |
git add . | |
git commit -m "chore: Update strings" | |
git push origin $branch_name | |
gh pr create -B main -H $branch_name --title 'Automatic translation updates' --body 'Created by GH Action. Can be ignored if there are other open translation PRs.' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |