Skip to content

Commit

Permalink
refactor: improve shell script reliability
Browse files Browse the repository at this point in the history
  • Loading branch information
philippwaller committed Dec 11, 2022
1 parent d389772 commit 04d10db
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 1,088 deletions.
2 changes: 1 addition & 1 deletion .github/scripts/generate-chart-exclude-string.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ chartDir="$projectRootPath/charts"
excludePaths=$(
find "$chartDir" -type d -mindepth 1 -maxdepth 1 |
sed "s~$projectRootPath/~~" |
egrep -v "^$chartPath$" |
grep -Ev "^$chartPath$" |
awk -F "/" '{ print $2 }' |
tr '\n' ',' |
sed 's/,$//g'
Expand Down
16 changes: 11 additions & 5 deletions .github/scripts/generate-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@ changedCharts=$2

projectRootPath=$(git rev-parse --show-toplevel)
if [ "$ciChanged" == false ]; then
charts=($(echo "$changedCharts" |
chartStr=$(echo "$changedCharts" |
jq -r .[] |
awk -F '/' '{ print $1"/"$2 }' |
sort |
uniq)
)
charts=()
while IFS='' read -r line; do charts+=("$line"); done < <(echo "$chartStr")
else
charts=($(find "$projectRootPath/charts" -type d -mindepth 1 -maxdepth 1 | sed "s~$projectRootPath/~~"))
chartStr=$(find "$projectRootPath/charts" -type d -mindepth 1 -maxdepth 1 | sed "s~$projectRootPath/~~")
charts=()
while IFS='' read -r line; do charts+=("$line"); done < <(echo "$chartStr")
fi

index=0
chartsJsonArray=()
matrixJsonArray=()
for chartPath in "${charts[@]}"; do
chartName=$(basename $chartPath)
chartName=$(basename "$chartPath")
settings=$(yq -o=json '.' "$projectRootPath/$chartPath/ci.yaml")
chartJson=$(
jq --null-input \
Expand All @@ -29,7 +32,10 @@ for chartPath in "${charts[@]}"; do
'{"name": $name, "path": $path, "settings": $settings}'
)
chartsJsonArray+=("$chartJson")
versions=($(echo "$settings" | jq -r -c '.kubernetes.supportedVersions[]'))
versions=()
versionsStr=$(echo "$settings" | jq -r -c '.kubernetes.supportedVersions[]')
while IFS='' read -r line; do versions+=("$line"); done < <(echo "$versionsStr")

for version in "${versions[@]}"; do
matrixJson=$(
jq --null-input \
Expand Down
7 changes: 6 additions & 1 deletion .github/scripts/install-custom-resource-definitions-test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#!/usr/bin/env bash

index=3
index=1
configuration=$(jq -c . <stubs/configuration.json)

./install-custom-resource-definitions.sh "$index" "$configuration"

index=4
configuration=$(jq -c . <stubs/configuration.json)

./install-custom-resource-definitions.sh "$index" "$configuration"
4 changes: 3 additions & 1 deletion .github/scripts/install-custom-resource-definitions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
index="$1"
json="$2"

crds=($(echo "$json" | jq -r -c ".charts[$index].settings.kubernetes.customResourceDefinitions[]"))
crdsStr=$(echo "$json" | jq -r -c ".charts[$index].settings.kubernetes.customResourceDefinitions[]")
crds=()
while IFS='' read -r line; do [[ -n "$line" ]] && crds+=("$line"); done < <(echo "$crdsStr")
for crd in "${crds[@]}"; do
kubectl create -f "$crd"
done
Loading

0 comments on commit 04d10db

Please # to comment.