From 087e28c1fc2641ee32a33cc73e7307cfdc4ac179 Mon Sep 17 00:00:00 2001 From: Zedifus Date: Fri, 10 Jun 2022 14:45:48 +0100 Subject: [PATCH] Separate Linting from main ci yml --- .gitlab-ci.yml | 67 +---------------------------------------------- .gitlab/lint.yml | 68 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 66 deletions(-) create mode 100644 .gitlab/lint.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5cc58af4..7b1eef96 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -13,72 +13,6 @@ variables: DOCKER_HOST: tcp://docker:2376 DOCKER_TLS_CERTDIR: "/certs" -yamllint: - stage: lint - image: registry.gitlab.com/pipeline-components/yamllint:latest - tags: - - docker - rules: - - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' - - if: "$CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS" - when: never - script: - - yamllint . - -jsonlint: - stage: lint - image: registry.gitlab.com/pipeline-components/jsonlint:latest - tags: - - docker - rules: - - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' - - if: "$CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS" - when: never - script: - - | - find . -not -path './.git/*' -name '*.json' -type f -print0 | - parallel --will-cite -k -0 -n1 jsonlint -q - -black: - stage: lint - image: registry.gitlab.com/pipeline-components/black:latest - tags: - - docker - rules: - - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' - - if: "$CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS" - when: never - script: - - black --check --verbose -- . - -pylint: - stage: lint - image: registry.gitlab.com/pipeline-components/pylint:latest - tags: - - docker - rules: - - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' - - if: "$CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS" - when: never - # before_script: - # - mkdir -p public/badges public/lint - # - echo undefined > public/badges/$CI_JOB_NAME.score - script: - # - pylint --exit-zero --output-format=text $(find -type f -name "*.py" ! -path "**/.venv/**" ! -path "**/app/migrations/**") | tee /tmp/pylint.txt - # - sed -n 's/^Your code has been rated at \([-0-9.]*\)\/.*/\1/p' /tmp/pylint.txt > public/badges/$CI_JOB_NAME.score - - pylint --exit-zero --output-format=pylint_gitlab.GitlabCodeClimateReporter $(find -type f -name "*.py" ! -path "**/.venv/**" ! -path "**/app/migrations/**") > codeclimate.json - # after_script: - # - anybadge --overwrite --label $CI_JOB_NAME --value=$(cat public/badges/$CI_JOB_NAME.score) --file=public/badges/$CI_JOB_NAME.svg 4=red 6=orange 8=yellow 10=green - # - | - # echo "Your score is: $(cat public/badges/$CI_JOB_NAME.score)" - # Removed lint badge generation until public release - artifacts: - paths: - - public - reports: - codequality: codeclimate.json - when: always - docker-build-dev: image: docker:latest services: @@ -295,6 +229,7 @@ gemnasium-python-dependency_scanning: - docker include: + - local: ./.gitlab/lint.yml - template: Security/Dependency-Scanning.gitlab-ci.yml - template: Security/SAST.gitlab-ci.yml - template: Security/Secret-Detection.gitlab-ci.yml diff --git a/.gitlab/lint.yml b/.gitlab/lint.yml new file mode 100644 index 00000000..fe6aa0b3 --- /dev/null +++ b/.gitlab/lint.yml @@ -0,0 +1,68 @@ +# YAML Linting +yamllint: + stage: lint + image: registry.gitlab.com/pipeline-components/yamllint:latest + tags: + - docker + rules: + - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' + - if: "$CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS" + when: never + script: + - yamllint . + +# JSON Linting +jsonlint: + stage: lint + image: registry.gitlab.com/pipeline-components/jsonlint:latest + tags: + - docker + rules: + - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' + - if: "$CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS" + when: never + script: + - | + find . -not -path './.git/*' -name '*.json' -type f -print0 | + parallel --will-cite -k -0 -n1 jsonlint -q + +# Code Format Checking +black: + stage: lint + image: registry.gitlab.com/pipeline-components/black:latest + tags: + - docker + rules: + - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' + - if: "$CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS" + when: never + script: + - black --check --verbose -- . + +# Code Climate/Quality Checking +pylint: + stage: lint + image: registry.gitlab.com/pipeline-components/pylint:latest + tags: + - docker + rules: + - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' + - if: "$CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS" + when: never + before_script: + - mkdir -p public/badges public/lint + - echo undefined > public/badges/$CI_JOB_NAME.score + script: + - pylint --exit-zero --output-format=text $(find -type f -name "*.py" ! -path "**/.venv/**" ! -path "**/app/migrations/**") | tee /tmp/pylint.txt + - sed -n 's/^Your code has been rated at \([-0-9.]*\)\/.*/\1/p' /tmp/pylint.txt > public/badges/$CI_JOB_NAME.score + - pylint --exit-zero --output-format=pylint_gitlab.GitlabCodeClimateReporter $(find -type f -name "*.py" ! -path "**/.venv/**" ! -path "**/app/migrations/**") > codeclimate.json + after_script: + - anybadge --overwrite --label $CI_JOB_NAME --value=$(cat public/badges/$CI_JOB_NAME.score) --file=public/badges/$CI_JOB_NAME.svg 4=red 6=orange 8=yellow 10=green + - | + echo "Your score is: $(cat public/badges/$CI_JOB_NAME.score)" + artifacts: + paths: + - public + reports: + codequality: codeclimate.json + when: always