Update Translations #352
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: Update Translations | |
on: | |
workflow_dispatch: | |
schedule: | |
# Check for updates every day at midnight. | |
- cron: '0 0 * * *' | |
jobs: | |
update-translation-files: | |
name: Update Translation Files | |
# Don't run on forks. | |
if: github.repository == 'RebelToolbox/RebelEngine' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Rebel Engine | |
uses: actions/checkout@v4 | |
- name: Install dependencies | |
shell: bash | |
run: | | |
#Install dependencies | |
sudo apt-get update | |
sudo apt-get install -y gettext | |
- name: Create branch | |
run: | | |
#Create branch | |
git fetch origin | |
echo "::group::git switch main" | |
if ! git switch main 2>/dev/null ; then | |
git switch -c main origin/main | |
fi | |
echo "::endgroup::" | |
echo "::group::git switch -c update-translation-files" | |
if git ls-remote --exit-code \ | |
--heads origin refs/heads/update-translation-files \ | |
>/dev/null | |
then | |
echo "Use existing branch" | |
git switch -c update-translation-files origin/update-translation-files | |
echo "existing_branch=yes" >> "$GITHUB_ENV" | |
else | |
echo "Create new branch" | |
git switch -c update-translation-files | |
fi | |
echo "::endgroup::" | |
- name: Update existing branch | |
if: env.existing_branch == 'yes' | |
run: | | |
#Update existing branch | |
echo "::group::git rebase main" | |
if ! git rebase main >/dev/null ; then | |
git rebase --abort | |
echo "Rebase merge conflict!" | |
echo "Previous changes need to be overwritten." | |
echo "recreate_branch=yes" >> "$GITHUB_ENV" | |
else | |
git push -f | |
fi | |
echo "::endgroup::" | |
- name: Recreate branch | |
if: env.recreate_branch == 'yes' | |
run: | | |
git switch main | |
git branch -D update-translation-files | |
git switch -c update-translation-files | |
git push -u -f origin update-translation-files | |
- name: Update API Translation Files | |
run: | | |
#Update API Translation Files | |
cd translations | |
make | |
cd .. | |
- name: Update Editor Translation Files | |
run: | | |
#Update API Translation Files | |
cd editor/translations | |
make | |
cd ../.. | |
- name: Check for changes | |
run: | | |
#git diff | |
if git diff --exit-code ; then | |
echo "No files have changed." | |
else | |
echo "Translation files have been updated." | |
echo "has_changes=yes" >> "$GITHUB_ENV" | |
fi | |
- name: Create commit | |
if: env.has_changes == 'yes' | |
run: | | |
#Create commit | |
git config user.name "Rebel Documentation" | |
git config user.email "[email protected]" | |
echo "Adding files" | |
git add . | |
echo "Creating commit" | |
git commit -m "Update Translation Files" | |
echo "Pushing changes" | |
git push -u origin update-translation-files | |
- name: Create Pull Request | |
if: env.has_changes == 'yes' | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
#Create Pull Request | |
if gh pr list --state open --head update-translation-files \ | |
--json state | grep state | |
then | |
echo "Existing Pull Request updated" | |
echo "Please merge the Pull Request" | |
else | |
gh pr create \ | |
--base main \ | |
--head update-translation-files \ | |
--title "Update Translation Files" \ | |
--body "Updates the API and editor translation files with the latest changes." \ | |
--label "PR Type: Maintenance" | |
echo "New Pull Request created" | |
fi | |
update-translations: | |
name: Update Translations | |
# Don't run on forks. | |
if: github.repository == 'RebelToolbox/RebelEngine' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Rebel Engine | |
uses: actions/checkout@v4 | |
- name: Pull updates from Weblate | |
run: | | |
#Pull updates from Weblate | |
git fetch origin | |
echo "::group::git switch main" | |
if ! git switch main 2>/dev/null ; then | |
git switch -c main origin/main | |
fi | |
echo "::endgroup::" | |
git remote add weblate https://hosted.weblate.org/git/rebel-toolbox/rebel-engine-api/ | |
git fetch weblate | |
git switch -c weblate weblate/main | |
git push -f origin weblate | |
- name: Check for changes | |
run: | | |
#git diff | |
if git diff --exit-code main -- ; then | |
echo "No new translations." | |
else | |
echo "New translations available from Weblate!" | |
echo "weblate_has_updates=yes" >> "$GITHUB_ENV" | |
fi | |
- name: Create Pull Request | |
if: env.weblate_has_updates == 'yes' | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
#Create Pull Request | |
if gh pr list --state open --head weblate \ | |
--json state | grep state | |
then | |
echo "Existing Pull Request updated" | |
echo "Please merge the Pull Request" | |
else | |
gh pr create \ | |
--base main \ | |
--head weblate \ | |
--title "Update Translations" \ | |
--body "New translations from Weblate." \ | |
--label "PR Type: Enhancement" | |
echo "New Pull Request created" | |
fi | |