Skip to content

Sync with CPython

Sync with CPython #42

name: Sync with CPython
on:
schedule:
- cron: '0 4 * * *'
workflow_dispatch:
inputs:
cpython_tag:
description: 'CPython tag to sync against (e.g. 3.14)'
required: false
default: '3.14'
permissions:
contents: write
issues: write
concurrency:
group: sync
cancel-in-progress: false
jobs:
sync:
runs-on: ubuntu-latest
env:
CPYTHON_TAG: ${{ github.event.inputs.cpython_tag || '3.14' }}
steps:
- name: Checkout translation repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'
- name: Install gettext
run: sudo apt-get install -y gettext
- name: Install Python dependencies
run: pip install sphinx sphinx-intl
# Item 4: fetch/build/merge/validate now all live in one shared
# module (scripts/po_sync.py) instead of inline bash/awk here, so
# this workflow can't drift from update_python_version.py the way
# it did before (missing --no-location --no-wrap on one side).
- name: Sync msgids (fetch, build gettext, merge, validate)
run: python scripts/po_sync.py sync-only "$CPYTHON_TAG" --create-new
- name: Ensure translation label exists
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh label create "translation" \
--color "0075ca" \
--description "Translation review needed" \
--repo ${{ github.repository }} \
2>/dev/null || true
- name: Open issue for new and fuzzy strings
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
tmpfile=$(mktemp)
# --- New PO files (untracked, since nothing is staged yet) ---
new_files=$(git ls-files --others --exclude-standard -- '*.po' \
':(exclude).cpython-src' ':(exclude).pot-templates')
if [ -n "$new_files" ]; then
new_count=$(echo "$new_files" | wc -l)
{
echo "## 🆕 New PO files ($new_count)"
echo "$new_files" | sed 's/^/- `/; s/$/`/'
echo ""
} >> "$tmpfile"
fi
# --- Fuzzy strings ---
fuzzy_out=$(mktemp)
while IFS= read -r f; do
fuzzy=$(msgattrib --only-fuzzy --no-obsolete "$f" 2>/dev/null)
if [ -n "$fuzzy" ]; then
entries=$(echo "$fuzzy" | awk '
/^msgid / {
first=$0; msg=$0"\n"; lines=1; incapture=1; next
}
incapture && /^"/ {
msg = msg $0 "\n"; lines++; next
}
incapture && /^msgstr/ {
incapture=0
if (!(first == "msgid \"\"" && lines==1)) {
printf "- %s\n", msg
}
next
}
')
count=$(echo "$entries" | grep -c '^- ' || true)
if [ "${count:-0}" -gt 0 ]; then
echo "### $f ($count fuzzy)" >> "$fuzzy_out"
echo "$entries" | head -20 >> "$fuzzy_out"
echo "" >> "$fuzzy_out"
fi
fi
done < <(find . -name "*.po" \
-not -path "./.git/*" \
-not -path "./.cpython-src/*" \
-not -path "./.pot-templates/*")
if [ -s "$fuzzy_out" ]; then
{
echo "## 🔍 Fuzzy strings"
cat "$fuzzy_out"
} >> "$tmpfile"
fi
# --- One issue for both ---
if [ -s "$tmpfile" ]; then
echo "Triggered by sync with \`$CPYTHON_TAG\`." >> "$tmpfile"
gh issue create \
--title "🔍 Translation review needed after CPython sync ($(date +%Y-%m-%d))" \
--body-file "$tmpfile" \
--label "translation" \
--repo ${{ github.repository }}
fi
rm -f "$tmpfile" "$fuzzy_out"
- name: Stage changes
run: git add --all
- name: Unstage POT-Creation-Date-only changes
run: python scripts/unstage_cosmetic.py
- name: Commit if changed
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
if git diff --staged --quiet; then
echo "Nothing to commit, skipping."
exit 0
fi
git commit -m "chore: sync msgids with CPython $CPYTHON_TAG"
git push