Skip to content

Commit

Permalink
Force exact version of UI framework (#4710)
Browse files Browse the repository at this point in the history
* it can now extract translations from filters

* avoid angularjs views

* force exact ui-framework version

* test if develop branch exists in github actions

* test

* test

* test

* fetch upstream to be able to compare current commit to it
  • Loading branch information
tomaskikutis authored Dec 30, 2024
1 parent 316f625 commit 28f119d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
46 changes: 29 additions & 17 deletions grep-lint.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import subprocess
import sys
import re

def get_command(branch=None):
arguments_list = ["git", "grep", "-P", rule_regex]
Expand All @@ -9,15 +10,19 @@ def get_command(branch=None):

arguments_list.append("--")
arguments_list.append("scripts")
arguments_list.append("./package.json")

return arguments_list

## fetch upstream to be able to compare current commit to it
subprocess.call(["git", "remote", "add", "temp-remote", "https://github.com/superdesk/superdesk-client-core.git"], stderr=subprocess.STDOUT)
subprocess.call(["git", "fetch", "temp-remote", "--quiet"], stderr=subprocess.STDOUT)
develop_commit_with_ref = subprocess.check_output(["git", "ls-remote", "--heads", "temp-remote", "develop"]).decode('utf-8')
develop_commit = re.split('\t', develop_commit_with_ref)[0]
subprocess.call(["git", "remote", "remove", "temp-remote"], stderr=subprocess.STDOUT)
##

rules_to_check = [
{
'name': 'Do not use `translate` filter anymore. Translation strings can\'t be extracted when the filter is used.',
'perl_regex': '\|\s*?translate',
'tolerance': True
},
{
'name': 'Do not use angularjs for views anymore. Use React components and use `reactToAngular1` if you need to use React components inside existing angular templates.',

Expand All @@ -38,16 +43,23 @@ def get_command(branch=None):
'perl_regex': 'templateUrl\s*?:\s*[\'|"|`].+?\.html[\'|"|`]',
'tolerance': True
},
# {
# 'name': 'Do not use angularjs for views anymore. Use React components and use `reactToAngular1` if you need to use React components inside existing angular templates.',

# # must match:
# # template: '<'
# # must not match:
# # template: 'a', b: '<'
# 'perl_regex': 'template\s*?:\s*[\'|"|`][^\'|"|`]*<[^\'|"|`]*[\'|"|`]',
# 'tolerance': True
# },
{
'name': 'Do not use angularjs for views anymore. Use React components and use `reactToAngular1` if you need to use React components inside existing angular templates.',

# must match:
# template: '<'
# must not match:
# template: 'a', b: '<'
'perl_regex': 'template\s*?:\s*[\'|"|`][^\'|"|`]*<[^\'|"|`]*[\'|"|`]',
'tolerance': True
},
{
'name': 'force exact ui-framework version',

# errors if finds a caret or a tilde next to ui-framework version
'perl_regex': '"superdesk-ui-framework": "(\^|~)',
'tolerance': False
},
]

any_rule_violated = False
Expand All @@ -61,7 +73,7 @@ def get_command(branch=None):

try:
violations_count_develop = len(
subprocess.check_output(get_command("develop")).decode('utf-8').splitlines()
subprocess.check_output(get_command(develop_commit)).decode('utf-8').splitlines()
)
except subprocess.CalledProcessError as e:
# ignore exception if grep simply didn't find matches
Expand Down Expand Up @@ -89,6 +101,6 @@ def get_command(branch=None):
print("Rule regex: `" + rule_regex + "`")

if rule_tolerance is True:
print('Tolerance is enabled, but ' + str(violations_count) + ' violations were found in the working while there only are ' + str(violations_count_develop) + ' violations on develop. See grep-lint.py for details.')
print('Tolerance is enabled, but ' + str(violations_count) + ' violations were found on this commit while there only are ' + str(violations_count_develop) + ' violations on develop. See grep-lint.py for details.')

sys.exit(1 if any_rule_violated else 0)
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
"sass-loader": "6.0.6",
"shortid": "2.2.8",
"style-loader": "0.20.2",
"superdesk-ui-framework": "^4.0.4",
"superdesk-ui-framework": "4.0.4",
"ts-loader": "3.5.0",
"typescript": "4.9.5",
"uuid": "8.3.1",
Expand Down Expand Up @@ -163,7 +163,7 @@
"test": "npm run lint && npm run unit && node tasks/verify-client-api-changes.js",
"debug-unit-tests": "karma start --reporters=progress --browsers=Chrome",
"unit": "karma start --single-run",
"lint": "tsc -p scripts --noEmit && eslint --quiet --parser=@typescript-eslint/parser --ext .js --ext .jsx --ext .ts --ext .tsx scripts e2e/client tasks",
"lint": "python ./grep-lint.py && tsc -p scripts --noEmit && eslint --quiet --parser=@typescript-eslint/parser --ext .js --ext .jsx --ext .ts --ext .tsx scripts e2e/client tasks",
"lint-fix": "eslint --fix --parser=@typescript-eslint/parser --ext .js --ext .jsx --ext .ts --ext .tsx scripts e2e/client tasks",
"server": "grunt server",
"dev": "npm run server"
Expand Down

0 comments on commit 28f119d

Please sign in to comment.