diff --git a/.github/workflows/_python.yml b/.github/workflows/_python.yml index 8e67133..405a59f 100644 --- a/.github/workflows/_python.yml +++ b/.github/workflows/_python.yml @@ -292,39 +292,59 @@ jobs: exit 1 shell: bash + # TODO this comment is still relevant? # not the best solution because i do not think that dependabot supports this - name: Create requirements-linters.txt run: | + function check_linter_dependency_and_append_to_file { + # + # Function to check whether a specific linter is in the requirements file + # If it can be found inside the requirements, said linter dependency will be appended to a newly created requirements-linter.txt file. + # If the linter is not found inside the requirements file an error will be raised. + # + # 1st parameter: Name of the linter. + # 2nd parameter: Path of the requirements file. + # + if [[ -z $(grep -P "^$1[^a-zA-Z0-9_-].*" "$2") ]]; then + echo "::error::$1 dependency not found in $2 file!" + exit 1 + else + echo "$1 dependency found in $2!" + echo "$(grep -P ^$1[^a-zA-Z0-9_-].* $2)" >> requirements-linters.txt + fi + } + CI_REQUIREMENTS_LINTERS="${GITHUB_WORKSPACE}/.github/configurations/python_linters/requirements-linters.txt" echo > requirements-linters.txt if [[ '${{ inputs.use_black}}' != 'false' ]]; then - echo "black==24.8.0" >> requirements-linters.txt + check_linter_dependency_and_append_to_file "black" "$CI_REQUIREMENTS_LINTERS" fi if [[ '${{ inputs.use_isort}}' != 'false' ]]; then - echo "isort==5.13.2" >> requirements-linters.txt + check_linter_dependency_and_append_to_file "isort" "$CI_REQUIREMENTS_LINTERS" fi if [[ '${{ inputs.use_flake8}}' != 'false' ]]; then - echo "flake8==7.1.1" >> requirements-linters.txt + check_linter_dependency_and_append_to_file "flake8" "$CI_REQUIREMENTS_LINTERS" if [[ -n '${{ inputs.django_settings_module }}' ]]; then - echo "flake8-django @ git+https://github.com/terencehonles/flake8-django.git@a6e369e89d275dfd5514f2aa9d091aa36c5ff84b" >> requirements-linters.txt + check_linter_dependency_and_append_to_file "flake8-django" "$CI_REQUIREMENTS_LINTERS" fi fi if [[ '${{ inputs.use_pylint}}' != 'false' ]]; then - echo "pylint==3.2.6" >> requirements-linters.txt + check_linter_dependency_and_append_to_file "pylint" "$CI_REQUIREMENTS_LINTERS" if [[ -n '${{ inputs.django_settings_module }}' ]]; then - echo "pylint-django==2.5.5" >> requirements-linters.txt + check_linter_dependency_and_append_to_file "pylint-django" "$CI_REQUIREMENTS_LINTERS" fi fi if [[ '${{ inputs.use_bandit}}' != 'false' ]]; then - echo "bandit==1.7.9" >> requirements-linters.txt + check_linter_dependency_and_append_to_file "bandit" "$CI_REQUIREMENTS_LINTERS" fi if [[ '${{ inputs.use_autoflake}}' != 'false' ]]; then - echo "autoflake==2.3.1" >> requirements-linters.txt + check_linter_dependency_and_append_to_file "autoflake" "$CI_REQUIREMENTS_LINTERS" fi + # TODO does this make any sense? It seems a copy paste of the same file cat $(echo ${{ inputs.requirements_path }} | sed -e 's/.txt/-linter.txt/') >> requirements-linters.txt 2>/dev/null || exit 0 shell: bash working-directory: ${{ inputs.install_from }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e93115..77e5cac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,3 +19,4 @@ * Added both frontend and backend exclusions on _detect_changes.yaml (paths that won't be considered by git diff) * Updated CodeQL action v2 -> v3 (v2 has been [deprecated](https://github.blog/changelog/2024-01-12-code-scanning-deprecation-of-codeql-action-v2/) on december '24) * Removed `setup-python-dependencies` from `codeql/action.yml` since it has no effect anymore. See [this](https://github.blog/changelog/2024-01-23-codeql-2-16-python-dependency-installation-disabled-new-queries-and-bug-fixes/) for more information. +* Linters versions in step `Create requirements-linters.txt` of `_python.yml` action are now computed according to `configurations/python_linters/requirements-linters.txt`. As of now, linter updates are only required in `configurations/python_linters/requirements-linters.txt`. diff --git a/workflows/_python.yml b/workflows/_python.yml index 8e67133..04f71a0 100644 --- a/workflows/_python.yml +++ b/workflows/_python.yml @@ -292,38 +292,55 @@ jobs: exit 1 shell: bash - # not the best solution because i do not think that dependabot supports this - name: Create requirements-linters.txt run: | + function check_linter_dependency_and_append_to_file { + # + # Function to check whether a specific linter is in the requirements file + # If it can be found inside the requirements, said linter dependency will be appended to a newly created requirements-linter.txt file. + # If the linter is not found inside the requirements file an error will be raised. + # + # 1st parameter: Name of the linter. + # 2nd parameter: Path of the requirements file. + # + if [[ -z $(grep -P "^$1[^a-zA-Z0-9_-].*" "$2") ]]; then + echo "::error::$1 dependency not found in $2 file!" + exit 1 + else + echo "$1 dependency found in $2!" + echo "$(grep -P ^$1[^a-zA-Z0-9_-].* $2)" >> requirements-linters.txt + fi + } + CI_REQUIREMENTS_LINTERS="${GITHUB_WORKSPACE}/.github/configurations/python_linters/requirements-linters.txt" echo > requirements-linters.txt if [[ '${{ inputs.use_black}}' != 'false' ]]; then - echo "black==24.8.0" >> requirements-linters.txt + check_linter_dependency_and_append_to_file "black" "$CI_REQUIREMENTS_LINTERS" fi if [[ '${{ inputs.use_isort}}' != 'false' ]]; then - echo "isort==5.13.2" >> requirements-linters.txt + check_linter_dependency_and_append_to_file "isort" "$CI_REQUIREMENTS_LINTERS" fi if [[ '${{ inputs.use_flake8}}' != 'false' ]]; then - echo "flake8==7.1.1" >> requirements-linters.txt + check_linter_dependency_and_append_to_file "flake8" "$CI_REQUIREMENTS_LINTERS" if [[ -n '${{ inputs.django_settings_module }}' ]]; then - echo "flake8-django @ git+https://github.com/terencehonles/flake8-django.git@a6e369e89d275dfd5514f2aa9d091aa36c5ff84b" >> requirements-linters.txt + check_linter_dependency_and_append_to_file "flake8-django" "$CI_REQUIREMENTS_LINTERS" fi fi if [[ '${{ inputs.use_pylint}}' != 'false' ]]; then - echo "pylint==3.2.6" >> requirements-linters.txt + check_linter_dependency_and_append_to_file "pylint" "$CI_REQUIREMENTS_LINTERS" if [[ -n '${{ inputs.django_settings_module }}' ]]; then - echo "pylint-django==2.5.5" >> requirements-linters.txt + check_linter_dependency_and_append_to_file "pylint-django" "$CI_REQUIREMENTS_LINTERS" fi fi if [[ '${{ inputs.use_bandit}}' != 'false' ]]; then - echo "bandit==1.7.9" >> requirements-linters.txt + check_linter_dependency_and_append_to_file "bandit" "$CI_REQUIREMENTS_LINTERS" fi if [[ '${{ inputs.use_autoflake}}' != 'false' ]]; then - echo "autoflake==2.3.1" >> requirements-linters.txt + check_linter_dependency_and_append_to_file "autoflake" "$CI_REQUIREMENTS_LINTERS" fi cat $(echo ${{ inputs.requirements_path }} | sed -e 's/.txt/-linter.txt/') >> requirements-linters.txt 2>/dev/null || exit 0 shell: bash