|
2 | 2 |
|
3 | 3 | # Release changed charts with updated version inside Chart.yaml only(!)
|
4 | 4 |
|
| 5 | +# NOTE: assume GNU semantics for tools like awk, grep, etc |
| 6 | + |
5 | 7 | set -o errexit
|
6 | 8 | set -o nounset
|
7 | 9 | set -o pipefail
|
@@ -35,39 +37,64 @@ release_charts_inside_folders() {
|
35 | 37 | local folders=("$@")
|
36 | 38 | local changed_charts=()
|
37 | 39 |
|
38 |
| - echo "fetch remote tags..." |
39 |
| - git fetch --tags > /dev/null 2>&1 |
| 40 | + prepare_helm_repo |
40 | 41 |
|
41 | 42 | # form list of folder which was changed
|
42 | 43 | for folder in "${folders[@]}"; do
|
43 | 44 | [[ ! -f "$charts_dir/$folder/Chart.yaml" ]] && continue
|
44 | 45 | print_line_separator
|
45 | 46 | local chart_name
|
46 |
| - local tag |
| 47 | + local chart_version |
| 48 | + local chart_was_released |
| 49 | + |
| 50 | + chart_name=$(read_chart_name "${charts_dir}/${folder}") |
| 51 | + chart_version=$(read_chart_version "${charts_dir}/${folder}") |
| 52 | + echo "Checking if \"$charts_dir/$folder\" has been released to the repo" |
| 53 | + chart_was_released=$(chart_released "${chart_name}" "${chart_version}") |
47 | 54 |
|
48 |
| - echo "Looking up latest release tag for \"$charts_dir/$folder/Chart.yaml\"" |
49 |
| - chart_name=$(awk '/^name/{print $2}' "$charts_dir/$folder/Chart.yaml") |
| 55 | + echo "released result: \"${chart_was_released}\"" |
50 | 56 |
|
51 | 57 | # if chart is not released or folder has change, then remember as changed_charts
|
52 |
| - if [[ ! "$(git tag -l "$chart_name-[0-9.]*")" ]] || has_changed "$folder"; then |
| 58 | + if [ -z "${chart_was_released}" ] || has_changed "$folder"; then |
53 | 59 | changed_charts+=("$folder")
|
54 | 60 | fi
|
55 | 61 | done
|
56 | 62 | echo "changed charts: " "${changed_charts[@]}"
|
57 | 63 |
|
58 | 64 | # continue only with changed charts
|
59 | 65 | if [[ -n "${changed_charts[*]}" ]]; then
|
60 |
| - helm repo update |
61 |
| - install_chart_releaser |
62 |
| - cleanup_releaser |
63 |
| - package_charts "${changed_charts[@]}" |
64 |
| - release_charts |
65 |
| - update_index |
| 66 | + if [ "${DRYRUN}" == "true" ]; then |
| 67 | + echo "DRYRUN: Would have released charts" "${changed_charts[@]}" |
| 68 | + else |
| 69 | + release_changed_charts "${changed_charts[@]}" |
| 70 | + fi |
66 | 71 | else
|
67 | 72 | echo "Nothing to do. No chart changes detected."
|
68 | 73 | fi
|
69 | 74 | }
|
70 | 75 |
|
| 76 | +read_chart_name() { |
| 77 | + local chart_path=$1 |
| 78 | + awk '/^name: /{print $2}' "$chart_path/Chart.yaml" |
| 79 | +} |
| 80 | + |
| 81 | +read_chart_version() { |
| 82 | + local chart_path=$1 |
| 83 | + awk '/^version: /{print $2}' "$chart_path/Chart.yaml" |
| 84 | +} |
| 85 | + |
| 86 | +prepare_helm_repo() { |
| 87 | + helm repo add mongodb https://mongodb.github.io/helm-charts |
| 88 | + helm repo update mongodb |
| 89 | +} |
| 90 | + |
| 91 | +chart_released() { |
| 92 | + local chart_name=$1 |
| 93 | + local version=$2 |
| 94 | + |
| 95 | + helm search repo "mongodb/${chart_name}" --version "${version}" |grep "${chart_name}\s" |
| 96 | +} |
| 97 | + |
71 | 98 | # check if release version and chart version is diffrent
|
72 | 99 | has_changed() {
|
73 | 100 | local folder=$1
|
@@ -95,6 +122,17 @@ get_latest_tag(){
|
95 | 122 | git describe --tags --abbrev=0 --match="$name-[0-9.]*" "$(git rev-list --tags --max-count=1)"
|
96 | 123 | }
|
97 | 124 |
|
| 125 | +release_changed_charts() { |
| 126 | + local changed_charts=("$@") |
| 127 | + |
| 128 | + helm repo update |
| 129 | + install_chart_releaser |
| 130 | + cleanup_releaser |
| 131 | + package_charts "${changed_charts[@]}" |
| 132 | + release_charts |
| 133 | + update_index |
| 134 | +} |
| 135 | + |
98 | 136 | install_chart_releaser() {
|
99 | 137 | print_line_separator
|
100 | 138 | if [[ ! -d "$RUNNER_TOOL_CACHE" ]]; then
|
|
0 commit comments