Skip to content
This repository has been archived by the owner on Feb 22, 2022. It is now read-only.

Adding linting to Chart and values yaml files #2429

Merged
merged 1 commit into from
Oct 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ jobs:
name: install tools
command: test/circle/install.sh
- run:
name: helm lint
name: lint
command: test/circle/lint.sh
8 changes: 6 additions & 2 deletions test/circle/install.sh
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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
40 changes: 37 additions & 3 deletions test/circle/lint.sh
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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`
Expand All @@ -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 changes: 43 additions & 0 deletions test/circle/lintconf.yml
Original file line number Diff line number Diff line change
@@ -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