Adding linting to Chart and values yaml files (#2429)

This does not lint yaml templates as they are templates rather
than valid yaml files. They cannot be linted with a normal linter

yamllint is used for linting. This is an existing Python project
https://github.com/adrienverge/yamllint

The rules are not the default rules and are stored in their
entirity so they can be controlled over time

The existance of a Chart.yaml file and values.yaml file is checked
and an error is thrown if one is missing. Helm lint will not
detect a chart if Chart.yaml is missing and if a values.yaml file
is missing it is noted as info.

The run function is introduced to enable running all the linters,
capturing non-zero exit codes, and exiting with a non-zdero code
if any of them fail. This is used instead of exiting when the
first failure happens to provide more feedback to chart developers.
This commit is contained in:
Matt Farina
2017-10-09 21:23:39 +02:00
committed by Reinhard Nägele
parent f8d3a1197e
commit 2f12841300
4 changed files with 87 additions and 6 deletions
+1 -1
View File
@@ -10,5 +10,5 @@ jobs:
name: install tools
command: test/circle/install.sh
- run:
name: helm lint
name: lint
command: test/circle/lint.sh
+6 -2
View File
@@ -1,4 +1,4 @@
#!/bin/bash -xe
#!/bin/bash -e
# Copyright 2017 The Kubernetes Authors All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -20,4 +20,8 @@ wget http://storage.googleapis.com/kubernetes-helm/helm-${HELM_LATEST_VERSION}-l
tar -xvf helm-${HELM_LATEST_VERSION}-linux-amd64.tar.gz
sudo mv linux-amd64/helm /usr/local/bin
rm -f helm-${HELM_LATEST_VERSION}-linux-amd64.tar.gz
rm -rf linux-amd64
rm -rf linux-amd64
# Install A YAML Linter
# Pinning to a version for consistency
sudo pip install yamllint==1.8.1
+37 -3
View File
@@ -1,4 +1,4 @@
#!/bin/bash -xe
#!/bin/bash
# Copyright 2017 The Kubernetes Authors All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,6 +16,20 @@
# Compare to the merge-base rather than master to limit scanning to changes
# this PR/changeset is introducing. Making sure the comparison is to the
# upstream charts repo rather than a fork.
exitCode=0
# Run is a wrapper around the execution of functions. It captures non-zero exit
# codes and remembers an error happened. This enables running all the linters
# and capturing if any of them failed.
run() {
$@
local ret=$?
if [ $ret -ne 0 ]; then
exitCode=1
fi
}
git remote add k8s https://github.com/kubernetes/charts
git fetch k8s master
CHANGED_FOLDERS=`git diff --find-renames --name-only $(git merge-base k8s/master HEAD) stable/ incubator/ | awk -F/ '{print $1"/"$2}' | uniq`
@@ -30,6 +44,26 @@ for directory in ${CHANGED_FOLDERS}; do
if [ "$directory" == "incubator/common" ]; then
continue
elif [ -d $directory ]; then
helm lint ${directory}
run helm lint ${directory}
# If a Chart.yaml file is present lint it. Otherwise report an error
# because one should exist
if [ -e ${directory}/Chart.yaml ]; then
run yamllint -c test/circle/lintconf.yml ${directory}/Chart.yaml
else
echo "Error ${directory}/Chart.yaml file is missing"
exitCode=1
fi
# If a values.yaml file is present lint it. Otherwise report an error
# because one should exist
if [ -e ${directory}/values.yaml ]; then
run yamllint -c test/circle/lintconf.yml ${directory}/values.yaml
else
echo "Error ${directory}/values.yaml file is missing"
exitCode=1
fi
fi
done
done
exit $exitCode
+43
View File
@@ -0,0 +1,43 @@
---
rules:
braces:
min-spaces-inside: 0
max-spaces-inside: 0
min-spaces-inside-empty: -1
max-spaces-inside-empty: -1
brackets:
min-spaces-inside: 0
max-spaces-inside: 0
min-spaces-inside-empty: -1
max-spaces-inside-empty: -1
colons:
max-spaces-before: 0
max-spaces-after: 1
commas:
max-spaces-before: 0
min-spaces-after: 1
max-spaces-after: 1
comments:
require-starting-space: true
min-spaces-from-content: 2
comments-indentation: enable
document-end: disable
document-start: disable # No --- to start a file
empty-lines:
max: 2
max-start: 0
max-end: 0
hyphens:
max-spaces-after: 1
indentation:
spaces: consistent
indent-sequences: whatever # - list indentation will handle both indentation and without
check-multi-line-strings: false
key-duplicates: enable
line-length: disable # Lines can be any length
new-line-at-end-of-file: enable
new-lines:
type: unix
trailing-spaces: enable
truthy:
level: warning