Skip to content

Commit

Permalink
Added github action moderniser for django 42 only in matrix (#395)
Browse files Browse the repository at this point in the history
* fix: inprogress stuff pushed for github action moderniser
---------

Co-authored-by: Usama Sadiq <[email protected]>
  • Loading branch information
zubairshakoorarbisoft and UsamaSadiq committed Jun 19, 2023
1 parent e29763c commit 93c7d84
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 4 deletions.
2 changes: 1 addition & 1 deletion edx_repo_tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

__version__ = '0.8.0'
__version__ = '0.8.1'
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""
Modernizer for Github Actions CI Django 4.2 support
"""
from copy import deepcopy
import click
from edx_repo_tools.utils import YamlLoader

ALLOWED_DJANGO_VERSIONS = ['django32', 'django40', 'django41', 'django42']


class GithubCIModernizer(YamlLoader):
def __init__(self, file_path):
super().__init__(file_path)

def _update_django_in_matrix(self):
django_versions = list()
matrix_elements = dict()
section_key = None

for key in ['build', 'tests', 'run_tests', 'run_quality', 'pytest']:
if key in self.elements['jobs']:
section_key = key
matrix_elements = deepcopy(self.elements['jobs'][section_key]['strategy']['matrix'])

for key, value in matrix_elements.items():
if key == 'django-version':
django_versions = value
django_versions.extend(filter(
lambda version: version not in value, ALLOWED_DJANGO_VERSIONS))
if not section_key:
return
if django_versions:
self.elements['jobs'][section_key]['strategy']['matrix']['django-version'] = django_versions

def _update_github_actions(self):
self._update_django_in_matrix()

def modernize(self):
self._update_github_actions()
self.update_yml_file()


@click.command()
@click.option(
'--path', default='.github/workflows/ci.yml',
help="Path to default CI workflow file")
def main(path):
modernizer = GithubCIModernizer(path)
modernizer.modernize()


if __name__ == '__main__':
main()
13 changes: 10 additions & 3 deletions edx_repo_tools/codemods/django42/tox_moderniser_django42.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
TEST_ENV_SECTION = "testenv"
TEST_ENV_DEPS = "deps"
PYTHON_SUBSTITUTE = "py38"
DJANGO_SUBSTITUTE = "django{32,40,42}"
DJANGO_SUBSTITUTE = "django{32,40, 41,42}"

DJANGO_40_DEPENDENCY = "django40: Django>=4.0,<4.1\n"
DJANGO_41_DEPENDENCY = "django41: Django>=4.1,<4.2\n"
DJANGO_42_DEPENDENCY = "django42: Django>=4.2,<4.3\n"
NEW_DJANGO_DEPENDENCIES = DJANGO_40_DEPENDENCY + DJANGO_42_DEPENDENCY

Expand Down Expand Up @@ -74,10 +75,16 @@ def _replace_matches(pattern, substitute, target, matches):
occurrences_to_replace = len(matches) - 1
if occurrences_to_replace > 0:
target = re.sub(pattern, '', target, occurrences_to_replace)

# checking if there is any dependency for django32 dont override it
if matches[0].startswith('django32:'):
substitute = matches[0] + substitute
substitute = matches[0]
if 'django40:' not in target:
substitute += DJANGO_40_DEPENDENCY
if 'django41:' not in target:
substitute += DJANGO_41_DEPENDENCY
if 'django42:' not in target:
substitute += DJANGO_42_DEPENDENCY
target = re.sub(pattern, substitute, target)
return target

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def is_requirement(line):
'show_hooks = edx_repo_tools.dev.show_hooks:main',
'tag_release = edx_repo_tools.release.tag_release:main',
'modernize_tox_django42 = edx_repo_tools.codemods.django42.tox_moderniser_django42:main',
'modernize_github_actions_django42 = edx_repo_tools.codemods.django42.github_actions_modernizer_django42:main',
],
},
package_data={
Expand Down

0 comments on commit 93c7d84

Please sign in to comment.