feat(yaml_lint): Added job yaml lint for checking yaml files
defaults to checking subfolder/.gitlab-ci.yml. Changes to be committed: modified: .gitlab-ci.yml new file: yaml_lint/.gitlab-ci.yml new file: yaml_lint/.yamllint.yaml new file: yaml_lint/README.md new file: yaml_lint/requirements.txt issue #1
This commit is contained in:
@ -8,11 +8,20 @@ stages:
|
|||||||
- sync
|
- sync
|
||||||
|
|
||||||
include:
|
include:
|
||||||
|
- local: $JOB_ROOT_DIR/yaml_lint/.gitlab-ci.yml
|
||||||
- local: $JOB_ROOT_DIR/conventional_commits/.gitlab-ci.yml
|
- local: $JOB_ROOT_DIR/conventional_commits/.gitlab-ci.yml
|
||||||
- local: $JOB_ROOT_DIR/git_push_mirror/.gitlab-ci.yml
|
- local: $JOB_ROOT_DIR/git_push_mirror/.gitlab-ci.yml
|
||||||
- local: $JOB_ROOT_DIR/gitlab_release/.gitlab-ci.yml
|
- local: $JOB_ROOT_DIR/gitlab_release/.gitlab-ci.yml
|
||||||
|
|
||||||
|
|
||||||
|
gilab-ci.yml Lint (python 3.6):
|
||||||
|
variables:
|
||||||
|
YAML_LINT_PATH: "/*/.gitlab-ci.yml"
|
||||||
|
extends:
|
||||||
|
- .yaml_lint_defaults
|
||||||
|
image: python:3.6-slim
|
||||||
|
|
||||||
|
|
||||||
Gitlab Release:
|
Gitlab Release:
|
||||||
variables:
|
variables:
|
||||||
MY_COMMAND: ./sub-folder_changlog.sh
|
MY_COMMAND: ./sub-folder_changlog.sh
|
||||||
@ -20,7 +29,6 @@ Gitlab Release:
|
|||||||
- .gitlab_release
|
- .gitlab_release
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Github (Push --mirror):
|
Github (Push --mirror):
|
||||||
variables:
|
variables:
|
||||||
GIT_SYNC_URL: "https://$GITHUB_USERNAME_ROBOT:$GITHUB_TOKEN_ROBOT@github.com/NoFussComputing/gitlab-ci.git"
|
GIT_SYNC_URL: "https://$GITHUB_USERNAME_ROBOT:$GITHUB_TOKEN_ROBOT@github.com/NoFussComputing/gitlab-ci.git"
|
||||||
|
44
yaml_lint/.gitlab-ci.yml
Normal file
44
yaml_lint/.gitlab-ci.yml
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
|
||||||
|
.yaml_lint_defaults:
|
||||||
|
variables:
|
||||||
|
YAML_LINT_PATH: "/*.yml"
|
||||||
|
YAML_LINT_CONFIG: "/yaml_lint/.yamllint.yaml"
|
||||||
|
stage: validation
|
||||||
|
before_script:
|
||||||
|
- if [ "0$JOB_ROOT_DIR" == "0" ]; then ROOT_DIR=gitlab-ci; else ROOT_DIR=$JOB_ROOT_DIR ; fi
|
||||||
|
- echo "[DEBUG] ROOT_DIR[$ROOT_DIR]"
|
||||||
|
- mkdir -p "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/$CI_JOB_NAME"
|
||||||
|
- mkdir -p "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/tests"
|
||||||
|
- export PYTHON_VERSION=`python -c 'import sys; version=sys.version_info[:3]; print("{0}.{1}.{2}".format(*version))'`
|
||||||
|
- apt update
|
||||||
|
- apt install --no-install-recommends -y git
|
||||||
|
- python3 -m venv env
|
||||||
|
- . env/bin/activate
|
||||||
|
- pip install --upgrade pip
|
||||||
|
- pip install -r $ROOT_DIR/yaml_lint/requirements.txt
|
||||||
|
- mkdir $PYTHON_VERSION
|
||||||
|
script:
|
||||||
|
- YAML_LINT_PATH=$ROOT_DIR$YAML_LINT_PATH
|
||||||
|
- echo "[DEBUG] YAML_LINT_PATH[$YAML_LINT_PATH]"
|
||||||
|
- YAML_LINT_CONFIG=$ROOT_DIR$YAML_LINT_CONFIG
|
||||||
|
- echo "[DEBUG] YAML_LINT_CONFIG[$YAML_LINT_CONFIG]"
|
||||||
|
- yamllint $YAML_LINT_PATH -f parsable -c $ROOT_DIR/yaml_lint/.yamllint.yaml > "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/$CI_JOB_NAME/$PYTHON_VERSION-yaml-lint.log" 1>&1 || YAML_LINT=$?
|
||||||
|
- cat "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/$CI_JOB_NAME/$PYTHON_VERSION-yaml-lint.log" | ansible-lint-to-junit-xml > "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/tests/$PYTHON_VERSION-yaml-lint.junit.xml"
|
||||||
|
- if [ $YAML_LINT > 0 ]; then echo "YAML lint failed with $YAML_LINT"; exit $YAML_LINT; fi
|
||||||
|
after_script:
|
||||||
|
- echo deactivate
|
||||||
|
artifacts:
|
||||||
|
expire_in: 3 days
|
||||||
|
when: always
|
||||||
|
paths:
|
||||||
|
- "artifacts/*"
|
||||||
|
reports:
|
||||||
|
junit:
|
||||||
|
- "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/tests/*.junit.xml"
|
||||||
|
rules:
|
||||||
|
- if: '$CI_COMMIT_BRANCH == "master"'
|
||||||
|
when: never
|
||||||
|
- if: '$CI_COMMIT_BRANCH'
|
||||||
|
when: always
|
||||||
|
- when: never
|
||||||
|
|
26
yaml_lint/.yamllint.yaml
Normal file
26
yaml_lint/.yamllint.yaml
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
---
|
||||||
|
extends: default
|
||||||
|
|
||||||
|
rules:
|
||||||
|
braces: {max-spaces-inside: 1, level: error}
|
||||||
|
brackets: {max-spaces-inside: 1, level: error}
|
||||||
|
colons: {max-spaces-after: -1, level: error}
|
||||||
|
commas: {max-spaces-after: -1, level: error}
|
||||||
|
comments: disable
|
||||||
|
comments-indentation: disable
|
||||||
|
document-start: disable
|
||||||
|
empty-lines:
|
||||||
|
max: 2
|
||||||
|
max-start: 1
|
||||||
|
max-end: 1
|
||||||
|
level: error
|
||||||
|
hyphens: {level: error}
|
||||||
|
# indentation: disable
|
||||||
|
indentation:
|
||||||
|
spaces: consistent
|
||||||
|
key-duplicates: enable
|
||||||
|
line-length: disable
|
||||||
|
new-line-at-end-of-file: disable
|
||||||
|
new-lines: {type: unix}
|
||||||
|
trailing-spaces: disable
|
||||||
|
truthy: disable
|
52
yaml_lint/README.md
Normal file
52
yaml_lint/README.md
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
# Yaml Lint
|
||||||
|
This job does yaml linting when any commit is pushed to any branch.
|
||||||
|
|
||||||
|
|
||||||
|
This job provides the following badge:
|
||||||
|
|
||||||
|
- None
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
|
||||||
|
- None
|
||||||
|
|
||||||
|
## your .gitlab-ci.yml changes
|
||||||
|
To use this job add the following to your `.gitlab-ci.yml` file
|
||||||
|
|
||||||
|
``` yaml
|
||||||
|
stages:
|
||||||
|
- validation
|
||||||
|
|
||||||
|
include:
|
||||||
|
- remote: https://gitlab.com/nofusscomputing/projects/gitlab-ci/-/raw/master/yaml_lint/.gitlab-ci.yml
|
||||||
|
|
||||||
|
Yaml Lint (python 3.6):
|
||||||
|
variables:
|
||||||
|
YAML_LINT_PATH: "roles/"
|
||||||
|
YAML_LINT_CONFIG: ".yamllint.yaml"
|
||||||
|
extends:
|
||||||
|
- .yaml_linter_defaults
|
||||||
|
image: python:3.6-slim
|
||||||
|
```
|
||||||
|
> You can use any python version you wish.
|
||||||
|
|
||||||
|
## CI/CD Variables required
|
||||||
|
|
||||||
|
| var name | Description |
|
||||||
|
|:----:|:----|
|
||||||
|
| YAML_LINT_PATH | *The path you wish the linter to search for yaml files* |
|
||||||
|
| YAML_LINT_CONFOG | *The path you have stored the yaml config file in* |
|
||||||
|
|
||||||
|
|
||||||
|
## Job Workflow
|
||||||
|
|
||||||
|
- This job will lint any yaml file in the specified directory using the specified rules.
|
||||||
|
|
||||||
|
## Artifacts
|
||||||
|
|
||||||
|
- `$CI_PROJECT_DIR/artifacts` - Root artifact directory
|
||||||
|
- `$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/tests/$PYTHON_VERSION-yaml-lint.junit.xml` - JUnit Test report
|
||||||
|
- `$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/$CI_JOB_NAME/$PYTHON_VERSION-yaml-lint.log` - Linter log
|
||||||
|
|
||||||
|
## License
|
||||||
|
To view the license for this folder and any sub-folders, refer [here](https://gitlab.com/nofusscomputing/projects/gitlab-ci)
|
2
yaml_lint/requirements.txt
Normal file
2
yaml_lint/requirements.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
yamllint
|
||||||
|
ansible-lint-to-junit-xml
|
Reference in New Issue
Block a user