43 lines
No EOL
1.7 KiB
YAML
43 lines
No EOL
1.7 KiB
YAML
name: frappe_linter
|
|
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<message>((?!\1).)*)\1(\s*,\s*context\s*=\s*([\"'])(?P<py_context>((?!\5).)*)\5)*(\s*,\s*(.)*?\s*(,\s*([\"'])(?P<js_context>((?!\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('A syntax error has been discovered at line number: ' + num)
|
|
print('Syntax error occured with: ' + line)
|
|
if errors_encounter > 0 :
|
|
print('You can visit "https://frappe.io/docs/user/en/translations" to resolve this error.')
|
|
assert 1+1 == 3
|
|
shell: python |