Skip to content

Commit

Permalink
ci(auto_messages_pot): add a super small custom script to compare .po…
Browse files Browse the repository at this point in the history
…t files
  • Loading branch information
Psycojoker committed Mar 25, 2024
1 parent f49802f commit 3f552ca
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
29 changes: 29 additions & 0 deletions .github/diff_pot_files.py
Original file line number Diff line number Diff line change
@@ -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()
8 changes: 5 additions & 3 deletions .github/workflows/auto_messages_pot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@ 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/
pybabel extract --ignore-dirs venv -F babel.cfg -o messages.pot .
- 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'
Expand Down

0 comments on commit 3f552ca

Please sign in to comment.