diff --git a/.github/workflows/Locales.yml b/.github/workflows/Locales.yml index 772a4db4..3ab5578c 100644 --- a/.github/workflows/Locales.yml +++ b/.github/workflows/Locales.yml @@ -14,9 +14,15 @@ jobs: pip install polib PyGithub - name: Check that .po files are up to date + env: + GH_TOKEN: ${{ github.token }} run: | if [[ "${{github.ref}}" == 'refs/heads/master' ]] ; then tools/check_po.py --manage-issues --github-repository "${{ github.repository }}" --github-token "${{ github.token }}" + elif [[ "${{github.base_ref}}" != "" ]] ; then + FILES=$(gh api repos/${{github.repository}}/pulls/${{github.event.pull_request.number}}/files | jq --raw-output '[.[].filename | select(. | startswith("locale/"))] | join(",")') + echo "Locale files changed by pull request: ${FILES}" + tools/check_po.py --fail-on "${FILES}" else tools/check_po.py fi diff --git a/tools/check_po.py b/tools/check_po.py index 2eb684ba..8d7e4302 100755 --- a/tools/check_po.py +++ b/tools/check_po.py @@ -35,6 +35,7 @@ if __name__ == "__main__": parser.add_argument("--github-repository") parser.add_argument("--github-token") parser.add_argument("--manage-issues", action="store_true") + parser.add_argument("--fail-on", default="") args = parser.parse_args() @@ -50,6 +51,8 @@ if __name__ == "__main__": repo = gh.get_repo(args.github_repository) with tempfile.TemporaryDirectory() as tmpdir: + return_code = 0 + client_pot = os.path.join(tmpdir, "client.pot") dashboard_pot = os.path.join(tmpdir, "dashboard.pot") @@ -115,7 +118,11 @@ if __name__ == "__main__": lang_issues[po].append(repr(i.msgid)) if missing > 0: - print(f"::warning file={po}::{lang} {missing} translations missing") + level = "warning" + if po in args.fail_on: + level = "error" + return_code = 1 + print(f"::{level} file={po}::{lang} {missing} translations missing") if args.manage_issues: issues = [ @@ -149,3 +156,4 @@ if __name__ == "__main__": else: for issue in issues: issue.edit(state="closed", body="All translations are up to date") + exit(return_code)