简体   繁体   中英

xgettext dry run to avoid unnecessary commits in Github workflow

Is there any way to do a dry run of xgettext on source files, in order to simply check if there are any differences compared to the current .pot file?

I have set up a Github workflow that will run xgettext on source files any time a change to a source file is pushed to the repository. The result is that often the change to the source file didn't change the translation strings, so the only difference in the resulting .pot file is the Creation date, which gets updated every time xgettext is run. This makes for unnecessary commits, and triggers unnecessary webhook calls to my weblate instance which picks up on an "updated" .pot file, and winds up generating its own Pull Request with an "updated" .pot file.

If there were a way to do a dry run and first check if there are any actual differences in the strings, I could avoid unnecessary commits and PRs from polluting my repo. Any ideas?

I was able to add a filter to my Github workflow, checking whether there are any significant changes besides a simple update to the value of POT-Creation-Date in the .pot file. I added an id to the step that takes care of running xgettext , then after running xgettext I save the count of significant lines changed in the pot file to a variable that will be accessible to the next step:

      - name: Update source file translation strings
        id: update_pot
        run: |
          sudo apt-get install -y gettext
          xgettext --from-code=UTF-8 --add-comments='translators:' --keyword="pgettext:1c,2" -o i18n/litcal.pot index.php
          echo "::set-output name=POT_LINES_CHANGED::$(git diff -U0 | grep '^[+|-][^+|-]' | grep -Ev '^[+-]"POT-Creation-Date' | tee >(wc -l))"

Then I check against this variable before running the commit step:

      - name: Push changes  # push the output folder to your repo
        if: ${{ steps.update_pot.outputs.POT_LINES_CHANGED > 0 }}
        uses: actions-x/commit@v4
        with:
          # The committer's email address
          email: 41898282+github-actions[bot]@users.noreply.github.com
          # The committer's name
          name: github-actions
          # The commit message
          message: regenerated i18n/litcal.pot from source files

etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM