1
0
Fork 0

ci(auto_messages_pot): add a super small custom script to compare .pot files

This commit is contained in:
Laurent Peuch 2024-03-25 02:30:34 +01:00
parent 9526122551
commit 54628d2960
2 changed files with 34 additions and 3 deletions

29
.github/diff_pot_files.py vendored Normal file
View file

@ -0,0 +1,29 @@
#! /usr/bin/env python3
"""
Super small script for github action to detect if 2 .pot files have changed for
github/workflows/auto_messages_pot.yml
"""
import sys
from babel.messages.pofile import PoFileParser
def load_pot_file(file_path):
poparser = PoFileParser({})
poparser.parse(open(file_path))
return poparser.catalog
def main():
file_1 = load_pot_file(sys.argv[1])
file_2 = load_pot_file(sys.argv[2])
if [x for x in file_1.keys() if x] == [x for x in file_2.keys() if x]:
sys.exit(1)
else:
sys.exit(0)
if __name__ == "__main__":
main()

View file

@ -18,6 +18,10 @@ jobs:
run: |
cd tools/readme_generator/
pip install -r requirements.txt
- name: Save old messges.pot for diffing later
run: |
cd tools/readme_generator/
cp messages.pot messages.pot.old
- name: Try to generate messages.pot
run: |
cd tools/readme_generator/
@ -25,9 +29,7 @@ jobs:
- shell: pwsh
id: check_files_changed
run: |
# Diff HEAD with the previous commit
$diff = git diff
$HasDiff = $diff.Length -gt 0
$HasDiff = python .github/diff_pot_files.py tools/readme_generator/messages.pot.old tools/readme_generator/messages.pot
Write-Host "::set-output name=files_changed::$HasDiff"
- name: Create Pull Request
if: steps.check_files_changed.outputs.files_changed == 'true'