1
0
mirror of https://github.com/helm/chart-testing.git synced 2026-02-05 18:45:18 +01:00
Files
chart-testing/chart_test.sh
Rimas Mocevicius 48e81aaa43 Add an option to force install of all/single charts (#24)
* Add an option to force install of all/single chart

Signed-off-by: rimas <rmocius@gmail.com>

* replace flag `--force` with `--chart-all`
add an option to list charts for `--chart` flag

Signed-off-by: rimas <rmocius@gmail.com>

* address mattfarina and unguiculus comments

Signed-off-by: rimas <rmocius@gmail.com>

* fixing merge conflicts

Signed-off-by: rimas <rmocius@gmail.com>

* fixing merge conflicts 2

Signed-off-by: rimas <rmocius@gmail.com>

* fixing merge conflicts 3

Signed-off-by: rimas <rmocius@gmail.com>

* exporting CHECK_VERSION_INCREMENT before chart_lib.sh is sourced

Signed-off-by: rimas <rmocius@gmail.com>

* fix --chart -> --charts

Signed-off-by: rimas <rmocius@gmail.com>

* print skip version check before env vars

Signed-off-by: rimas <rmocius@gmail.com>

* Fix readme

Signed-off-by: Reinhard Nägele <unguiculus@gmail.com>
2018-09-21 09:58:02 -04:00

189 lines
5.2 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# Copyright 2018 The Helm Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -o errexit
set -o nounset
set -o pipefail
readonly REPO_ROOT=$(git rev-parse --show-toplevel)
readonly SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
show_help() {
cat << EOF
Usage: $(basename "$0") <options>
Lint, install, and test Helm charts.
-h, --help Display help
--verbose Display verbose output
--no-lint Skip chart linting
--no-install Skip chart installation
--all Lint/install all charts
--charts Lint/install:
a standalone chart (e. g. stable/nginx)
a list of charts (e. g. stable/nginx,stable/cert-manager)
--config Path to the config file (optional)
-- End of all options
EOF
}
main() {
local verbose=
local no_install=
local no_lint=
local config=
local all=
local charts=
while :; do
case "${1:-}" in
-h|--help)
show_help
exit
;;
--verbose)
verbose=true
;;
--no-install)
no_install=true
;;
--no-lint)
no_lint=true
;;
--all)
all=true
;;
--charts)
if [ -n "$2" ]; then
charts="$2"
shift
else
echo "ERROR: '--charts' cannot be empty." >&2
exit 1
fi
;;
--config)
if [ -n "$2" ]; then
config="$2"
shift
else
echo "ERROR: '--config' cannot be empty." >&2
exit 1
fi
;;
-?*)
echo "WARN: Unknown option (ignored): $1" >&2
;;
*)
break
;;
esac
shift
done
if [[ -n "$config" ]]; then
if [[ -f "$config" ]]; then
# shellcheck disable=SC1090
source "$config"
else
echo "ERROR: Specified config file does not exist: $config" >&2
exit 1
fi
fi
if [[ "$all" == "true" || -n "$charts" ]]; then
export CHECK_VERSION_INCREMENT=false
fi
# shellcheck source=lib/chartlib.sh
source "$SCRIPT_DIR/lib/chartlib.sh"
[[ -n "$verbose" ]] && set -o xtrace
pushd "$REPO_ROOT" > /dev/null
for dir in "${CHART_DIRS[@]}"; do
if [[ ! -d "$dir" ]]; then
chartlib::error "Configured charts directory '$dir' does not exist"
exit 1
fi
done
local exit_code=0
if [[ "$all" == "true" ]]; then
read -ra changed_dirs <<< "$(chartlib::read_directories)"
elif [[ -n "$charts" ]]; then
charts="${charts//,/ }"
read -ra changed_dirs <<< "${charts}"
else
read -ra changed_dirs <<< "$(chartlib::detect_changed_directories)"
fi
if [[ -n "${changed_dirs[*]}" ]]; then
echo "Charts to be installed and tested: ${changed_dirs[*]}"
chartlib::init_helm
local summary=()
for chart_dir in "${changed_dirs[@]}"; do
echo ''
echo '--------------------------------------------------------------------------------'
echo " Processing chart '$chart_dir'..."
echo '--------------------------------------------------------------------------------'
echo ''
local error=
if [[ -z "$no_lint" ]]; then
if ! chartlib::validate_chart "$chart_dir"; then
error=true
fi
if ! chartlib::lint_chart_with_all_configs "$chart_dir"; then
error=true
fi
fi
if [[ -z "$no_install" && -z "$error" ]]; then
if ! chartlib::install_chart_with_all_configs "$chart_dir"; then
error=true
fi
fi
if [[ -z "$error" ]]; then
summary+=(" ✔︎ $chart_dir")
else
summary+=(" ✖︎ $chart_dir")
exit_code=1
fi
done
else
summary+=('No chart changes detected.')
fi
echo '--------------------------------------------------------------------------------'
for line in "${summary[@]}"; do
echo "$line"
done
echo '--------------------------------------------------------------------------------'
popd > /dev/null
exit "$exit_code"
}
main "$@"