-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added github action moderniser for django 42 only in matrix (#395)
* fix: inprogress stuff pushed for github action moderniser --------- Co-authored-by: Usama Sadiq <[email protected]>
- Loading branch information
1 parent
e29763c
commit 93c7d84
Showing
4 changed files
with
65 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
|
||
__version__ = '0.8.0' | ||
__version__ = '0.8.1' |
53 changes: 53 additions & 0 deletions
53
edx_repo_tools/codemods/django42/github_actions_modernizer_django42.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters