Files
Sylvestre Ledru 48aa0e017e weblate-sync: stop rewriting ## group comments to #
## is valid Fluent GroupComment syntax; the rewrite caused a sync loop
with upstream-source-sync restoring ## every day.
2026-04-13 09:20:13 +02:00

105 lines
3.0 KiB
YAML

name: Weblate Synchronization
on:
# Run every 6 hours to sync with Weblate
schedule:
- cron: '0 */6 * * *'
# Allow manual triggering
workflow_dispatch:
# Trigger on push to main branch (for source updates)
push:
branches: [ main ]
paths:
- 'src/uu/*/locales/en-US.ftl'
- 'src/uucore/locales/en-US.ftl'
- 'src/uu/*/src/*.rs'
jobs:
sync-weblate:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
token: ${{ secrets.WEBLATE_TOKEN || github.token }}
fetch-depth: 0
- name: Install Weblate CLI
run: |
pip install wlc
- name: Configure Weblate CLI
run: |
mkdir -p ~/.config
cat > ~/.config/weblate << EOF
[weblate]
url = https://hosted.weblate.org/api/
[keys]
https://hosted.weblate.org/api/ = ${{ secrets.WEBLATE_API_KEY }}
EOF
- name: Install Mozilla Fluent Linter
run: |
pip install moz-fluent-linter
- name: Pull translations from Weblate
run: |
wlc pull rust-coreutils
- name: Fix Fluent syntax issues
run: |
# Ensure all .ftl files end with a newline
find src/uu/*/locales src/uucore/locales -name "*.ftl" -type f | while read -r f; do
if [ -s "$f" ] && [ "$(tail -c1 "$f" | wc -l)" -eq 0 ]; then
echo "" >> "$f"
echo "Fixed missing newline: $f"
fi
done
- name: Validate Fluent syntax
run: |
has_errors=false
for dir in $(find src/uu/*/locales src/uucore/locales -name "*.ftl" -type f -exec dirname {} \; | sort -u); do
if ! moz-fluent-lint --config .github/fluent_linter_config.yml "$dir"; then
echo "::warning::Fluent syntax issues in $dir"
has_errors=true
fi
done
if [ "$has_errors" = true ]; then
echo "::warning::Some Fluent files have syntax issues that could not be auto-fixed"
fi
- name: Commit and push translations
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
if [ -n "$(git status --porcelain)" ]; then
# Use find -type f so we don't traverse symlinked locales dirs
# (e.g. base64/locales -> ../base32/locales), which would cause
# "pathspec is beyond a symbolic link" errors from git add.
find src/uu/*/locales src/uucore/locales -name '*.ftl' -type f -print0 \
| xargs -0 git add --
git commit -m "Update translations from Weblate"
git pull --rebase
git push
else
echo "No translation updates to commit"
fi
- name: Push source changes to Weblate
if: github.event_name == 'push'
run: |
# Lock translations to prevent conflicts
wlc lock rust-coreutils
# Push source changes
wlc push rust-coreutils
# Unlock after push
wlc unlock rust-coreutils