Skip to content

Commit f802c79

Browse files
authored
CLOUDP-218696: Check chart was actually released (#294)
Signed-off-by: Jose Vazquez <[email protected]>
1 parent e1aede8 commit f802c79

File tree

3 files changed

+61
-12
lines changed

3 files changed

+61
-12
lines changed

.github/actions/releaser/action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ inputs:
1515
target:
1616
description: "Specific charts folder inside <charts_dir> for releasing"
1717
required: false
18+
dryrun:
19+
description: "not actually release, but check what would be done"
20+
required: false
1821

1922
runs:
2023
using: composite
@@ -24,6 +27,7 @@ runs:
2427
export VERSION="${{ inputs.version }}"
2528
export CHART_DIR="${{ inputs.charts_dir }}"
2629
export CHARTS_REPO_URL="${{ inputs.charts_repo_url }}"
30+
export DRYRUN="${{ inputs.dryrun }}"
2731
2832
owner=$(cut -d '/' -f 1 <<< "$GITHUB_REPOSITORY")
2933
repo=$(cut -d '/' -f 2 <<< "$GITHUB_REPOSITORY")

.github/actions/releaser/cr.sh

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
# Release changed charts with updated version inside Chart.yaml only(!)
44

5+
# NOTE: assume GNU semantics for tools like awk, grep, etc
6+
57
set -o errexit
68
set -o nounset
79
set -o pipefail
@@ -35,39 +37,64 @@ release_charts_inside_folders() {
3537
local folders=("$@")
3638
local changed_charts=()
3739

38-
echo "fetch remote tags..."
39-
git fetch --tags > /dev/null 2>&1
40+
prepare_helm_repo
4041

4142
# form list of folder which was changed
4243
for folder in "${folders[@]}"; do
4344
[[ ! -f "$charts_dir/$folder/Chart.yaml" ]] && continue
4445
print_line_separator
4546
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}")
4754

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}\""
5056

5157
# 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
5359
changed_charts+=("$folder")
5460
fi
5561
done
5662
echo "changed charts: " "${changed_charts[@]}"
5763

5864
# continue only with changed charts
5965
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
6671
else
6772
echo "Nothing to do. No chart changes detected."
6873
fi
6974
}
7075

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+
7198
# check if release version and chart version is diffrent
7299
has_changed() {
73100
local folder=$1
@@ -95,6 +122,17 @@ get_latest_tag(){
95122
git describe --tags --abbrev=0 --match="$name-[0-9.]*" "$(git rev-list --tags --max-count=1)"
96123
}
97124

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+
98136
install_chart_releaser() {
99137
print_line_separator
100138
if [[ ! -d "$RUNNER_TOOL_CACHE" ]]; then

.github/workflows/main.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ on:
1313
type: string
1414
default: ""
1515
required: false
16+
dryrun:
17+
description: "not actually release, but check what would be done"
18+
type: boolean
19+
default: true
20+
required: false
1621

1722
jobs:
1823
build:
@@ -49,6 +54,7 @@ jobs:
4954
target: |
5055
atlas-operator-crds
5156
community-operator-crds
57+
dryrun: ${{ github.event.inputs.dryrun }}
5258

5359
- name: Get latest charts from repo
5460
run: |
@@ -61,3 +67,4 @@ jobs:
6167
with:
6268
charts_repo_url: https://mongodb.github.io/helm-charts
6369
target: ${{ github.event.inputs.target }}
70+
dryrun: ${{ github.event.inputs.dryrun }}

0 commit comments

Comments
 (0)