babel icon indicating copy to clipboard operation
babel copied to clipboard

Extraction check for CI integration

Open azmeuk opened this issue 2 years ago • 9 comments

I would like to setup a CI job that would check if users have forgotten to extract the catalogs. The idea is that the CI would extract the catalogs, and fail if there was differences.

I was thinking a simple way to achieve this was to add a --dry-run for pybabel extract, that would return 0 if nothing changed and 1 elsewise. I suppose the return code would need to ignore some fields in the header that would always be updated (POT-Creation-Date or Generated-By).

What do you think?

Related to #910 and #725

azmeuk avatar Oct 11 '23 10:10 azmeuk

You can just extract and then git diff --exit-code https://github.com/oprypin/mkdocs-literate-nav/blob/1e586657e3ea19a080b6a4e1075eac3db5e18a82/.github/workflows/ci.yml#L74

oprypin avatar Oct 11 '23 14:10 oprypin

I did not thought about this but this would be even simpler, thanks.

However, in any cases the POT-Creation-Date and the Generated-By headers are updated, and I could not find any option to ask pybabel to not update them.

Would a PR for adding options like --no-creation-date-update and --no-generated-by - or a --no-headers-update be OK?

azmeuk avatar Oct 11 '23 17:10 azmeuk

Hm there is actually something for POT-Creation-Date

  • https://github.com/python-babel/babel/pull/999

But maybe not for Generated-By

oprypin avatar Oct 11 '23 17:10 oprypin

Also there is update-header-comment, but that's just for the # comment. Doesn't seem to be a way to avoid updating Generated-By, it would be nice.

oprypin avatar Oct 11 '23 17:10 oprypin

This command might do it?

git diff --exit-code --ignore-matching-lines '^"(POT-Creation-Date|Generated-By):'

oprypin avatar Oct 11 '23 17:10 oprypin

But I think I'd like to have a way to avoid updating Generated-By, or a flag to override its value. Then this can be used for not only checking diffs in CI but actually applying them automatically too.

Just note that I'm not a contributor to this project, I'm just making random comments :sweat_smile:

oprypin avatar Oct 11 '23 18:10 oprypin

Thank your for your investigation and your workaround. I will try to test this soon.

azmeuk avatar Oct 11 '23 21:10 azmeuk

Strangely enough, the --ignore-matching-lines seems to not be very constant:

git clone https://github.com/numerique-gouv/b3desk.git
cd b3desk
make install-dev
make translation-extract

git diff -I "POT-Creation-Date"
# expected result, POT-Creation-Date diff is hidden

git diff -I "Generated-By"
# unexpectedly, Generated-By diff is NOT hidden

git diff -I "#:"
# Most location comments are hidden, but not everyone.

It feels like a bug in git though and not related to python-babel.

azmeuk avatar Oct 12 '23 07:10 azmeuk

Yes it is like that, it's not a bug in Git but instead it's a stupid but documented behavior.

The behavior is: show diff hunks where at least one line still differs after filtering undesired lines.

So: if you filter out all irrelevant lines within 1 command and there is no diff then you can be sure that there are no other diffs (and exit status 0 is consistent)

If instead there is still some diff then there were in fact other diffs but the diff output is pretty much garbage (exit status 1 is still 100% correctly returned though!)

Not ideal for sure.

oprypin avatar Oct 12 '23 07:10 oprypin