Skip to content

Added action to prevent changing msgid #1351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/prevent-msgid.py
Original file line number Diff line number Diff line change
@@ -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 changes: 21 additions & 0 deletions .github/workflows/prevent-msgid.yml
Original file line number Diff line number Diff line change
@@ -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