Skip to content

Commit

Permalink
fix: refactor configuration script to avoid unnecessary version checks
Browse files Browse the repository at this point in the history
  • Loading branch information
philippwaller committed Dec 11, 2022
1 parent 91a5061 commit 37ebbdb
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/scripts/generate-config-test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

ciChanged=false
ciChanged=true
changedCharts=$(jq -c . <stubs/changed-charts.json)

./generate-config.sh "$ciChanged" "$changedCharts"
43 changes: 28 additions & 15 deletions .github/scripts/generate-config.sh
Original file line number Diff line number Diff line change
@@ -1,35 +1,47 @@
#!/usr/bin/env bash

ciChanged=$1
changedCharts=$2

ciChanged="$1"
changedCharts="$2"
projectRootPath=$(git rev-parse --show-toplevel)
if [ "$ciChanged" == false ]; then
chartStr=$(echo "$changedCharts" |
jq -r .[] |
awk -F '/' '{ print $1"/"$2 }' |
sort |
uniq)

# get changed charts
changedChartStr=$(echo "$changedCharts" |
jq -r .[] |
awk -F '/' '{ print $1"/"$2 }' |
sort |
uniq)
changedCharts=()
while IFS='' read -r line; do changedCharts+=("$line"); done < <(echo "$changedChartStr")

if [ "$ciChanged" == true ]; then
# get all charts
allChartsStr=$(find "$projectRootPath/charts" -type d -mindepth 1 -maxdepth 1 | sed "s~$projectRootPath/~~")
charts=()
while IFS='' read -r line; do charts+=("$line"); done < <(echo "$chartStr")
while IFS='' read -r line; do charts+=("$line"); done < <(echo "$allChartsStr")
else
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")
charts=("${changedCharts[@]}")
fi

index=0
chartsJsonArray=()
matrixJsonArray=()
for chartPath in "${charts[@]}"; do

if printf '%s\0' "${changedCharts[@]}" | grep -Fxqz -- "$chartPath"; then
versionBump=true
else
versionBump=false
fi

chartName=$(basename "$chartPath")
settings=$(yq -o=json '.' "$projectRootPath/$chartPath/ci.yaml")
chartJson=$(
jq --null-input \
--arg name "$chartName" \
--arg path "$chartPath" \
--arg versionBump "$versionBump" \
--argjson settings "$settings" \
'{"name": $name, "path": $path, "settings": $settings}'
'{"name": $name, "path": $path, "settings": $settings, "versionBump": $versionBump}'
)
chartsJsonArray+=("$chartJson")
versions=()
Expand All @@ -42,8 +54,9 @@ for chartPath in "${charts[@]}"; do
--arg index "$index" \
--arg name "$chartName" \
--arg path "$chartPath" \
--arg versionBump "$versionBump" \
--arg version "$version" \
'{"sourceIndex": $index, "name": $name, "path": $path, "version": $version}'
'{"sourceIndex": $index, "name": $name, "path": $path, "version": $version, "versionBump": $versionBump}'
)
matrixJsonArray+=("$matrixJson")
done
Expand Down
2 changes: 0 additions & 2 deletions .github/scripts/stubs/changed-charts.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@
"charts/inadyn/Chart.yaml",
"charts/inadyn/README.md",
"charts/inadyn/ci.yaml",
"charts/k3s-traefik-config/.helmignore",
"charts/k3s-traefik-config/Chart.yaml",
"charts/k3s-traefik-config/ci.yaml"
]
1 change: 1 addition & 0 deletions .github/workflows/job_lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
echo $exclude
- name: Check if version bump is required
if: ${{ matrix.chart.versionBump }} == 'true'
run: |
ct lint \
--config .github/ct.yaml \
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/job_preparation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ jobs:
list-files: json
filters: |
charts:
- 'charts/**'
- 'charts/*/*/**'
- 'charts/*/!(ci.yaml|README.md)'
ci:
- '.github/**'
Expand Down

0 comments on commit 37ebbdb

Please sign in to comment.