mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-01 11:19:09 +00:00
ci: fix branch base and per-language commits in sync-hotfix-translations (#55405)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
7
.github/helper/merge_po_files.py
vendored
7
.github/helper/merge_po_files.py
vendored
@@ -7,7 +7,7 @@ Merge rules:
|
|||||||
b. language not yet in hotfix → copy file as-is (bench will filter to main.pot)
|
b. language not yet in hotfix → copy file as-is (bench will filter to main.pot)
|
||||||
c. msgid present in both → use develop's msgstr
|
c. msgid present in both → use develop's msgstr
|
||||||
"""
|
"""
|
||||||
import shutil
|
from datetime import datetime, timezone
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from babel.messages.pofile import read_po, write_po
|
from babel.messages.pofile import read_po, write_po
|
||||||
@@ -24,7 +24,9 @@ for src in sorted(DEVELOP.glob("*.po")):
|
|||||||
dev = read_po(f)
|
dev = read_po(f)
|
||||||
|
|
||||||
if not dst.exists():
|
if not dst.exists():
|
||||||
shutil.copy(src, dst)
|
dev.revision_date = datetime.now(timezone.utc)
|
||||||
|
with dst.open("wb") as f:
|
||||||
|
write_po(f, dev)
|
||||||
added += 1
|
added += 1
|
||||||
print(f" [new] {src.name}")
|
print(f" [new] {src.name}")
|
||||||
continue
|
continue
|
||||||
@@ -39,6 +41,7 @@ for src in sorted(DEVELOP.glob("*.po")):
|
|||||||
changes += 1
|
changes += 1
|
||||||
|
|
||||||
if changes:
|
if changes:
|
||||||
|
hf.revision_date = datetime.now(timezone.utc)
|
||||||
with dst.open("wb") as f:
|
with dst.open("wb") as f:
|
||||||
write_po(f, hf)
|
write_po(f, hf)
|
||||||
updated += 1
|
updated += 1
|
||||||
|
|||||||
59
.github/helper/sync_hotfix_translations.sh
vendored
59
.github/helper/sync_hotfix_translations.sh
vendored
@@ -4,6 +4,9 @@
|
|||||||
# Env: GH_TOKEN, PR_REVIEWER, GITHUB_WORKSPACE (all set by Actions).
|
# Env: GH_TOKEN, PR_REVIEWER, GITHUB_WORKSPACE (all set by Actions).
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
HOTFIX_BRANCH="version-16-hotfix"
|
||||||
|
|
||||||
cd ~ || exit
|
cd ~ || exit
|
||||||
|
|
||||||
echo "=== Setting up bench ==="
|
echo "=== Setting up bench ==="
|
||||||
@@ -12,6 +15,23 @@ bench -v init frappe-bench --skip-assets --skip-redis-config-generation --python
|
|||||||
cd ./frappe-bench || exit
|
cd ./frappe-bench || exit
|
||||||
bench get-app --skip-assets erpnext "${GITHUB_WORKSPACE}"
|
bench get-app --skip-assets erpnext "${GITHUB_WORKSPACE}"
|
||||||
|
|
||||||
|
echo "=== Setting up translations_hotfix branch ==="
|
||||||
|
cd ./apps/erpnext || exit
|
||||||
|
git config user.email "developers@erpnext.com"
|
||||||
|
git config user.name "frappe-pr-bot"
|
||||||
|
git remote set-url upstream https://github.com/frappe/erpnext.git
|
||||||
|
gh auth setup-git
|
||||||
|
git fetch upstream "${HOTFIX_BRANCH}"
|
||||||
|
git fetch upstream translations_hotfix 2>/dev/null || true
|
||||||
|
|
||||||
|
if git rev-parse --verify "upstream/translations_hotfix" >/dev/null 2>&1; then
|
||||||
|
git checkout -b translations_hotfix "upstream/translations_hotfix"
|
||||||
|
git merge -X theirs "upstream/${HOTFIX_BRANCH}" --no-edit
|
||||||
|
else
|
||||||
|
git checkout -b translations_hotfix "upstream/${HOTFIX_BRANCH}"
|
||||||
|
fi
|
||||||
|
cd ../.. || exit
|
||||||
|
|
||||||
echo "=== Fetching develop's .po files ==="
|
echo "=== Fetching develop's .po files ==="
|
||||||
mkdir -p /tmp/develop-po
|
mkdir -p /tmp/develop-po
|
||||||
git -C "${GITHUB_WORKSPACE}" fetch origin develop
|
git -C "${GITHUB_WORKSPACE}" fetch origin develop
|
||||||
@@ -31,28 +51,37 @@ bench update-po-files --app erpnext
|
|||||||
|
|
||||||
cd ./apps/erpnext || exit
|
cd ./apps/erpnext || exit
|
||||||
|
|
||||||
git config user.email "developers@erpnext.com"
|
if git diff --quiet erpnext/locale/ && [ -z "$(git ls-files --others --exclude-standard erpnext/locale/)" ]; then
|
||||||
git config user.name "frappe-pr-bot"
|
|
||||||
git remote set-url upstream https://github.com/frappe/erpnext.git
|
|
||||||
|
|
||||||
if git diff --quiet erpnext/locale/; then
|
|
||||||
echo "Translations are already up to date. No PR needed."
|
echo "Translations are already up to date. No PR needed."
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Changed files:"
|
echo "Changed files:"
|
||||||
git diff --name-only erpnext/locale/
|
git diff --name-only erpnext/locale/
|
||||||
|
git ls-files --others --exclude-standard erpnext/locale/
|
||||||
|
|
||||||
echo "=== Committing and pushing ==="
|
echo "=== Committing ==="
|
||||||
git checkout -B translations_hotfix
|
while IFS= read -r file; do
|
||||||
git add erpnext/locale/
|
git add "${file}"
|
||||||
git commit -m "fix: sync translations to version-16-hotfix"
|
lang=$(basename "${file}" .po)
|
||||||
gh auth setup-git
|
git commit -m "fix: add ${lang} translation to ${HOTFIX_BRANCH}"
|
||||||
git push -u upstream translations_hotfix --force
|
done < <(git ls-files --others --exclude-standard erpnext/locale/ | grep '\.po$' | sort)
|
||||||
|
|
||||||
|
while IFS= read -r file; do
|
||||||
|
git add "${file}"
|
||||||
|
if ! git diff --staged --quiet -- "${file}"; then
|
||||||
|
lang=$(basename "${file}" .po)
|
||||||
|
git commit -m "fix: sync ${lang} translation to ${HOTFIX_BRANCH}"
|
||||||
|
else
|
||||||
|
git restore --staged -- "${file}"
|
||||||
|
fi
|
||||||
|
done < <(git diff --name-only erpnext/locale/ | grep '\.po$' | sort)
|
||||||
|
|
||||||
|
git push -u upstream translations_hotfix
|
||||||
|
|
||||||
echo "=== Opening PR (if not already open) ==="
|
echo "=== Opening PR (if not already open) ==="
|
||||||
existing_pr=$(gh pr list \
|
existing_pr=$(gh pr list \
|
||||||
--base "version-16-hotfix" \
|
--base "${HOTFIX_BRANCH}" \
|
||||||
--head "translations_hotfix" \
|
--head "translations_hotfix" \
|
||||||
--state open \
|
--state open \
|
||||||
--json number \
|
--json number \
|
||||||
@@ -65,10 +94,10 @@ if [ "${existing_pr}" -gt 0 ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
gh pr create \
|
gh pr create \
|
||||||
--base "version-16-hotfix" \
|
--base "${HOTFIX_BRANCH}" \
|
||||||
--head "translations_hotfix" \
|
--head "translations_hotfix" \
|
||||||
--title "fix: sync translations to version-16-hotfix" \
|
--title "fix: sync translations to ${HOTFIX_BRANCH}" \
|
||||||
--body "Automated sync of Crowdin translations from \`develop\` to \`version-16-hotfix\`.
|
--body "Automated sync of Crowdin translations from \`develop\` to \`${HOTFIX_BRANCH}\`.
|
||||||
|
|
||||||
A 3-way merge is performed per language, then \`bench update-po-files\` reconciles each \`.po\` against hotfix's \`main.pot\`:
|
A 3-way merge is performed per language, then \`bench update-po-files\` reconciles each \`.po\` against hotfix's \`main.pot\`:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user