From b0e236badd319bd247c1e215cdee53d38aafb5cb Mon Sep 17 00:00:00 2001 From: Afshan Date: Mon, 13 Apr 2020 18:07:08 +0530 Subject: [PATCH] workflow for github actions to check translation formats --- .../workflows/check_translation_format.yml | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 .github/workflows/check_translation_format.yml diff --git a/.github/workflows/check_translation_format.yml b/.github/workflows/check_translation_format.yml new file mode 100644 index 0000000000..e5d2031182 --- /dev/null +++ b/.github/workflows/check_translation_format.yml @@ -0,0 +1,42 @@ +name: Check format +on: + pull_request: + branches: + - master + - develop +jobs: + check_translation: + name: Check format + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - name: Setup python3 + uses: actions/setup-python@v1 + with: + python-version: 3.6 + - name: Run check_translation for pull_request + run: | + import os + import subprocess + import re + errors_encounter = 0 + pattern = re.compile(r"_\(([\"']{,3})(?P((?!\1).)*)\1(\s*,\s*context\s*=\s*([\"'])(?P((?!\5).)*)\5)*(\s*,\s*(.)*?\s*(,\s*([\"'])(?P((?!\11).)*)\11)*)*\)") + temp = re.compile(r"_\(([\"']{,3})") + subprocess.run('git fetch origin '+os.environ['GITHUB_BASE_REF']+ ' :' +os.environ['GITHUB_BASE_REF']+ ' -q', shell=True) + files = subprocess.check_output('git diff --name-only '+os.environ['GITHUB_BASE_REF'], shell=True) + files = files.decode('utf-8') + files = files.split() + for file in files: + with open(file, 'r') as f: + for num, line in enumerate(f, 1): + all_matches = temp.finditer(line) + if all_matches: + for match in all_matches: + verify = pattern.search(line) + if not verify: + errors_encounter += 1 + print(num) + print(line) + if errors_encounter > 0 : + assert 1+1 == 3 + shell: python \ No newline at end of file