Skip to content

Crowdin - Download Translations #271

Crowdin - Download Translations

Crowdin - Download Translations #271

name: Crowdin - Download Translations
on:
# Scheduled run once a day
schedule:
- cron: '0 2 * * *'
# Run after:
# - "Upload Base" workflow completes
workflow_run:
workflows: ["Crowdin - Upload Sources"]
types:
- completed
# Support running manually
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-master
jobs:
crowdin-download-translations:
if: github.repository == 'Warzone2100/warzone2100'
permissions:
contents: read
runs-on: ubuntu-latest
environment: crowdin_sync
steps:
- name: Install gettext
env:
DEBIAN_FRONTEND: noninteractive
run: sudo apt-get -y install gettext
# Get a token using a GitHub App that has appropriate permissions *and* will trigger subsequent CI workflows
# (Since we want to run normal CI passes to catch translation string format errors that break builds)
- name: Get GH App Token
uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.WZ_CROWDIN_SYNC_GH_APP_ID }}
private-key: ${{ secrets.WZ_CROWDIN_SYNC_GH_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: "warzone2100"
- name: Checkout
uses: actions/checkout@v4
with:
ref: 'master'
token: ${{ steps.app-token.outputs.token }}
persist-credentials: true
- name: Prep local branches
id: configbranches
run: |
git fetch --prune
if [ -n "$(git show-ref origin/l10n_master)" ]; then
# has l10n_master branch
git checkout "l10n_master"
echo "CHECK_EXISTING=true" >> $GITHUB_OUTPUT
else
# no pre-existing l10n_master branch
echo "CHECK_EXISTING=false" >> $GITHUB_OUTPUT
exit 0
fi
# Switch back to master branch
git checkout -qf master
- name: Download Translations from Crowdin
uses: crowdin/github-action@v2
with:
config: 'crowdin.yml'
upload_sources: false
upload_translations: false
download_translations: true
localization_branch_name: 'l10n_master'
crowdin_branch_name: 'master'
push_translations: false
#commit_message: 'New Crowdin translations'
create_pull_request: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CROWDIN_PROJECT_ID: ${{ vars.CROWDIN_PROJECT_ID }}
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
- name: Fixup ownership
if: success() && (github.repository == 'Warzone2100/warzone2100')
run: |
sudo chown -R $(whoami) ./po
cd po
ls -al
- name: Cleanup .po files
if: success() && (github.repository == 'Warzone2100/warzone2100')
run: |
# 1.) Cleanup downloaded po (fixing up potential formatting differences and removing comments)
# For warzone2100.pot:
find po -name '*.po' -type f -maxdepth 1 \
-exec \
.ci/githubactions/cleanup-downloaded-po.sh 'po/warzone2100.pot' '{}' ';'
# For warzone2100_guide.pot:
find po/guide -name '*.po' -type f -maxdepth 1 \
-exec \
.ci/githubactions/cleanup-downloaded-po.sh 'po/guide/warzone2100_guide.pot' '{}' ';'
# 2.) Cleanup untranslated .po files
# For warzone2100.pot:
find po -name '*.po' -type f -maxdepth 1 \
-exec \
.ci/githubactions/check_po_base_unchanged.sh 'po/warzone2100.pot' '{}' ';' | xargs -r0 -I {} rm -v "{}"
# For warzone2100_guide.pot:
find po/guide -name '*.po' -type f -maxdepth 1 \
-exec \
.ci/githubactions/check_po_base_unchanged.sh 'po/guide/warzone2100_guide.pot' '{}' ';' | xargs -r0 -I {} rm -v "{}"
- name: Publish any changes to translations to l10n_master branch
if: success() && (github.repository == 'Warzone2100/warzone2100')
id: pushupdates
env:
CHECK_EXISTING_TRANSLATION_BRANCH: ${{ steps.configbranches.outputs.CHECK_EXISTING }}
run: |
git config user.name "github-actions[bot]"
git config user.email "<41898282+github-actions[bot]@users.noreply.github.com>"
# Add modified files (ignoring po header modifications):
echo "::group::Add modified files"
git difftool --dir-diff --extcmd=.ci/githubactions/crowdin_download_diff.sh | xargs -d '\n' git add
echo "::endgroup::"
# Add untracked (new) files:
echo "::group::Add untracked files"
git ls-files -z --others --exclude-standard | xargs -0 git add
echo "::endgroup::"
echo "Debug output:"
git status
echo "Commit changes:"
git commit -m "New Crowdin translations" || { echo "PROCESS_PR=false" >> $GITHUB_OUTPUT && exit 0; }
NEW_COMMIT_ID="$(git rev-parse HEAD)"
echo "New commit: ${NEW_COMMIT_ID}"
# Check if there are actual changes compared to the commit already pushed on the l10n_master branch
if [[ "${CHECK_EXISTING_TRANSLATION_BRANCH}" == "true" ]]; then
TRANSLATION_COMMIT_ID="$(git rev-parse l10n_master)"
echo "Current translation branch commit: ${TRANSLATION_COMMIT_ID}"
git diff --unified=0 ${NEW_COMMIT_ID}~..${NEW_COMMIT_ID} > l10n_temp_1.patch
git diff --unified=0 ${TRANSLATION_COMMIT_ID}~..${TRANSLATION_COMMIT_ID} > l10n_temp_2.patch
diff --brief --unified=1 \
--ignore-matching-lines='^[-+]"POT-Creation-Date: .*"' \
--ignore-matching-lines='^[-+]"PO-Revision-Date: .*"' \
--ignore-matching-lines='^[-+]"Last-Translator: .*"' \
--ignore-matching-lines='^index .*\.\..* .*' \
l10n_temp_1.patch l10n_temp_2.patch \
&& DIFF_RET=$? || DIFF_RET=$?
if [ $DIFF_RET -eq 0 ]; then
# Inputs are the same (ignoring header changes that aren't relevant)
echo "No pertinent changes - skipping force-push"
echo "PROCESS_PR=false" >> $GITHUB_OUTPUT
exit 0
fi
rm l10n_temp_1.patch
rm l10n_temp_2.patch
fi
echo "Pushing changes to l10n_master branch"
git push -f origin master:l10n_master
echo "PROCESS_PR=true" >> $GITHUB_OUTPUT
- name: Create Pull Request to update translations (if needed)
if: success() && (github.repository == 'Warzone2100/warzone2100') && (steps.pushupdates.outputs.PROCESS_PR == 'true')
id: cpr
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
GH_REPO: ${{ github.repository }}
run: |
gh pr create --base "master" --head "l10n_master" --title "New Crowdin translations" --body "New Crowdin translations sync (Auto-generated)" --label "automated pr" || echo "Seems like PR already exists?"