Skip to content

Commit 48e81aa

Browse files
rimuszmattfarina
authored andcommitted
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>
1 parent 9dfea37 commit 48e81aa

File tree

3 files changed

+104
-6
lines changed

3 files changed

+104
-6
lines changed

README.md

+46-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ Usage: chart_test.sh <options>
3939
--verbose Display verbose output
4040
--no-lint Skip chart linting
4141
--no-install Skip chart installation
42+
--all Lint/install all charts
43+
--charts Lint/install:
44+
a standalone chart (e. g. stable/nginx)
45+
a list of charts (e. g. stable/nginx,stable/cert-manager)
4246
--config Path to the config file (optional)
47+
-- End of all options
4348
```
4449

4550
## Configuration
@@ -58,8 +63,8 @@ Note that this must be done before the script is sourced.
5863
| `LINT_CONF` | Config file for YAML linter | `/testing/etc/lintconf.yaml` (path of default config file in Docker image) |
5964
| `CHART_YAML_SCHEMA` | YAML schema for `Chart.yaml` | `/testing/etc/chart_schema.yaml` (path of default schema file in Docker image) |
6065
| `VALIDATE_MAINTAINERS`| If `true`, maintainer names in `Chart.yaml` are validated to be existing Github accounts | `true` |
61-
| `CHECK_VERSION_INCREMENT`| If `true`, the chart version is checked to be incremented from the version on the remote target branch | `true` |
6266
| `GITHUB_INSTANCE`| Url of Github instance for maintainer validation | `https://github.com` |
67+
| `CHECK_VERSION_INCREMENT`| If `true`, the chart version is checked to be incremented from the version on the remote target branch | `true` |
6368

6469
Note that `CHART_DIRS`, `EXCLUDED_CHARTS`, and `CHART_REPOS` must be configured as Bash arrays.
6570

@@ -141,6 +146,26 @@ Linting chart 'stable/dummy'...
141146
Done.
142147
```
143148

149+
#### Linting Unchanged Charts
150+
151+
You can lint all charts with `--all` flag (chart version bump check will be ignored):
152+
153+
```shell
154+
docker run --rm -v "$(pwd):/workdir" --workdir /workdir quay.io/helmpack/chart-testing:v1.0.5 chart_test.sh --no-install --config .mytestenv --all
155+
```
156+
157+
You can lint a list of charts (separated by comma) with `--charts` flag (chart version bump check will be ignored):
158+
159+
```shell
160+
docker run --rm -v "$(pwd):/workdir" --workdir /workdir quay.io/helmpack/chart-testing:v1.0.5 chart_test.sh --no-install --config .mytestenv --charts stable/nginx,stable/cert-manager
161+
```
162+
163+
You can lint a single chart with `--charts` flag (chart version bump check will be ignored):
164+
165+
```shell
166+
docker run --rm -v "$(pwd):/workdir" --workdir /workdir quay.io/helmpack/chart-testing:v1.0.5 chart_test.sh --no-install --config .mytestenv --charts stable/nginx
167+
```
168+
144169
### Installing and Testing Charts
145170

146171
Installing a chart requires access to a Kubernetes cluster.
@@ -156,12 +181,31 @@ Make sure you set it based on the pull request number.
156181
docker run --rm -v "$(pwd):/workdir" --workdir /workdir quay.io/helmpack/chart-testing:v1.0.5 chart_test.sh --no-lint --config .mytestenv
157182
```
158183

184+
#### Installing Unchanged Charts
185+
186+
You can force to install all charts with `--all` flag:
187+
188+
```shell
189+
docker run --rm -v "$(pwd):/workdir" --workdir /workdir quay.io/helmpack/chart-testing:v1.0.5 chart_test.sh --no-lint --config .mytestenv --all
190+
```
191+
192+
You can force to install a list of charts (separated by comma) with `--charts` flag:
193+
194+
```shell
195+
docker run --rm -v "$(pwd):/workdir" --workdir /workdir quay.io/helmpack/chart-testing:v1.0.5 chart_test.sh --no-lint --config .mytestenv --charts stable/nginx,stable/cert-manager
196+
```
197+
198+
You can force to install one chart with `--charts` flag:
199+
200+
```shell
201+
docker run --rm -v "$(pwd):/workdir" --workdir /workdir quay.io/helmpack/chart-testing:v1.0.5 chart_test.sh --no-lint --config .mytestenv --charts stable/nginx
202+
```
203+
159204
#### GKE Example
160205

161206
An example for GKE is available in the [examples/gke](examples/gke) directory.
162207
A custom `Dockerfile` additionally installs the `google-cloud-sdk` and a custom shell script puts everything together.
163208

164-
165209
#### Docker for Mac Example
166210

167211
An example for Docker for Mac is available in the [examples/docker-for-mac](examples/docker-for-mac) directory.

chart_test.sh

+32-3
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,22 @@ Usage: $(basename "$0") <options>
2929
--verbose Display verbose output
3030
--no-lint Skip chart linting
3131
--no-install Skip chart installation
32+
--all Lint/install all charts
33+
--charts Lint/install:
34+
a standalone chart (e. g. stable/nginx)
35+
a list of charts (e. g. stable/nginx,stable/cert-manager)
3236
--config Path to the config file (optional)
3337
-- End of all options
3438
EOF
3539
}
3640

3741
main() {
38-
local no_lint=
42+
local verbose=
3943
local no_install=
44+
local no_lint=
4045
local config=
41-
local verbose=
46+
local all=
47+
local charts=
4248

4349
while :; do
4450
case "${1:-}" in
@@ -55,6 +61,18 @@ main() {
5561
--no-lint)
5662
no_lint=true
5763
;;
64+
--all)
65+
all=true
66+
;;
67+
--charts)
68+
if [ -n "$2" ]; then
69+
charts="$2"
70+
shift
71+
else
72+
echo "ERROR: '--charts' cannot be empty." >&2
73+
exit 1
74+
fi
75+
;;
5876
--config)
5977
if [ -n "$2" ]; then
6078
config="$2"
@@ -85,6 +103,10 @@ main() {
85103
fi
86104
fi
87105

106+
if [[ "$all" == "true" || -n "$charts" ]]; then
107+
export CHECK_VERSION_INCREMENT=false
108+
fi
109+
88110
# shellcheck source=lib/chartlib.sh
89111
source "$SCRIPT_DIR/lib/chartlib.sh"
90112

@@ -101,7 +123,14 @@ main() {
101123

102124
local exit_code=0
103125

104-
read -ra changed_dirs <<< "$(chartlib::detect_changed_directories)"
126+
if [[ "$all" == "true" ]]; then
127+
read -ra changed_dirs <<< "$(chartlib::read_directories)"
128+
elif [[ -n "$charts" ]]; then
129+
charts="${charts//,/ }"
130+
read -ra changed_dirs <<< "${charts}"
131+
else
132+
read -ra changed_dirs <<< "$(chartlib::detect_changed_directories)"
133+
fi
105134

106135
if [[ -n "${changed_dirs[*]}" ]]; then
107136
echo "Charts to be installed and tested: ${changed_dirs[*]}"

lib/chartlib.sh

+26-1
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,19 @@ readonly TIMEOUT="${TIMEOUT:-300}"
2626
readonly LINT_CONF="${LINT_CONF:-/testing/etc/lintconf.yaml}"
2727
readonly CHART_YAML_SCHEMA="${CHART_YAML_SCHEMA:-/testing/etc/chart_schema.yaml}"
2828
readonly VALIDATE_MAINTAINERS="${VALIDATE_MAINTAINERS:-true}"
29-
readonly CHECK_VERSION_INCREMENT="${CHECK_VERSION_INCREMENT:-true}"
3029
readonly GITHUB_INSTANCE="${GITHUB_INSTANCE:-https://github.com}"
30+
readonly CHECK_VERSION_INCREMENT="${CHECK_VERSION_INCREMENT:-true}"
3131

3232
# Special handling for arrays
3333
[[ -z "${CHART_DIRS[*]}" ]] && CHART_DIRS=(charts); readonly CHART_DIRS
3434
[[ -z "${EXCLUDED_CHARTS[*]}" ]] && EXCLUDED_CHARTS=(); readonly EXCLUDED_CHARTS
3535
[[ -z "${CHART_REPOS[*]}" ]] && CHART_REPOS=(); readonly CHART_REPOS
3636

3737
echo
38+
if [[ "$CHECK_VERSION_INCREMENT" == false ]]; then
39+
echo '--------------------------------------------------------------------------------'
40+
echo " SKIPPING VERSION INCREMENT CHECK!"
41+
fi
3842
echo '--------------------------------------------------------------------------------'
3943
echo ' Environment:'
4044
echo " REMOTE=$REMOTE"
@@ -51,6 +55,25 @@ echo " CHECK_VERSION_INCREMENT=$CHECK_VERSION_INCREMENT"
5155
echo '--------------------------------------------------------------------------------'
5256
echo
5357

58+
# Read chart directories to be used with --force
59+
chartlib::read_directories() {
60+
local dir
61+
62+
while read -r dir; do
63+
local excluded=
64+
for excluded_dir in "${EXCLUDED_CHARTS[@]}"; do
65+
if [[ "$dir" == "$excluded_dir" ]]; then
66+
excluded=true
67+
break
68+
fi
69+
done
70+
if [[ -z "$excluded" && -d "$dir" ]]; then
71+
changed_dirs=("${changed_dirs[@]}" "$dir")
72+
fi
73+
done < <(find "${CHART_DIRS[@]}" -mindepth 1 -maxdepth 1 -type d | awk -F/ '{ print $1"/"$2 }' | uniq)
74+
75+
echo "${changed_dirs[@]}"
76+
}
5477

5578
# Detects chart directories that have changes against the
5679
# target branch ("$REMOTE/$TARGET_BRANCH").
@@ -221,6 +244,8 @@ chartlib::validate_chart() {
221244

222245
if [[ "$CHECK_VERSION_INCREMENT" == true ]]; then
223246
chartlib::check_for_version_bump "$chart_dir" || error=true
247+
else
248+
echo "Skipping version increment check!"
224249
fi
225250

226251
chartlib::lint_yaml_file "$chart_dir/Chart.yaml" || error=true

0 commit comments

Comments
 (0)