mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-05-15 23:26:48 +02:00
Added action to prevent changing msgid (#1351)
See discussion in #1344. This checks that all `.po` files changed in pull requests either contain changes in POT-Creation-Date (i.e. are run by the specific tool which should change msgid's), or don't change msgid's (by checking that each line changed is NOT between msgid and msgstr) I have tested this on my fork, see [valid changes](https://github.com/noamzaks/comprehensive-rust/pull/1/files) where the action passes, and [invalid changes](https://github.com/noamzaks/comprehensive-rust/pull/2/files) where it doesn't. The action also has output for failing/passing: [passing](https://github.com/noamzaks/comprehensive-rust/actions/runs/6488171290/job/17620037473?pr=1) [failing](https://github.com/noamzaks/comprehensive-rust/actions/runs/6488175171/job/17620050716?pr=2)
This commit is contained in:
parent
a46c6c19df
commit
b1cd19ed20
36
.github/workflows/prevent-msgid.py
vendored
Normal file
36
.github/workflows/prevent-msgid.py
vendored
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
for filename in os.popen("git diff --name-only").read().split():
|
||||||
|
if not filename.endswith(".po"):
|
||||||
|
continue
|
||||||
|
|
||||||
|
if "POT-Creation-Date" in os.popen(f"git diff --unified=0 {filename}").read():
|
||||||
|
print(f"Assuming {filename} was changed automatically, skipping msgid check")
|
||||||
|
continue
|
||||||
|
|
||||||
|
changed_lines = {
|
||||||
|
i + 1
|
||||||
|
for i, line in enumerate(os.popen(f"git blame {filename}").readlines())
|
||||||
|
if line.startswith("00000000")
|
||||||
|
}
|
||||||
|
|
||||||
|
saw_msgid = False
|
||||||
|
with open(filename, "r") as f:
|
||||||
|
line = f.readline()
|
||||||
|
line_number = 1
|
||||||
|
|
||||||
|
while line:
|
||||||
|
if line.startswith("msgid"):
|
||||||
|
saw_msgid = True
|
||||||
|
elif line.startswith("msgstr"):
|
||||||
|
saw_msgid = False
|
||||||
|
|
||||||
|
if saw_msgid and line_number in changed_lines:
|
||||||
|
print(f"Changed msgid in file {filename}:{line_number}!")
|
||||||
|
print(
|
||||||
|
"Please read https://github.com/google/comprehensive-rust/blob/main/TRANSLATIONS.md#creating-and-updating-translations."
|
||||||
|
)
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
line_number += 1
|
||||||
|
line = f.readline()
|
21
.github/workflows/prevent-msgid.yml
vendored
Normal file
21
.github/workflows/prevent-msgid.yml
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
name: Prevent msgid changes in translations
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
paths:
|
||||||
|
- "**/*.po"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
prevent-msgid-changes:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Reset git
|
||||||
|
run: git reset origin/main
|
||||||
|
|
||||||
|
- name: Check po file changes
|
||||||
|
run: python3 .github/workflows/prevent-msgid.py
|
Loading…
x
Reference in New Issue
Block a user