Skip to content

Commit

Permalink
CLOUDP-218696: Check chart was actually released
Browse files Browse the repository at this point in the history
Signed-off-by: Jose Vazquez <[email protected]>
  • Loading branch information
josvazg committed Dec 19, 2023
1 parent e1aede8 commit edc6de0
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 12 deletions.
4 changes: 4 additions & 0 deletions .github/actions/releaser/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ inputs:
target:
description: "Specific charts folder inside <charts_dir> for releasing"
required: false
dryrun:
description: "not actually release, but check what would be done"
required: false

runs:
using: composite
Expand All @@ -24,6 +27,7 @@ runs:
export VERSION="${{ inputs.version }}"
export CHART_DIR="${{ inputs.charts_dir }}"
export CHARTS_REPO_URL="${{ inputs.charts_repo_url }}"
export DRYRUN="${{ inputs.dryrun }}"
owner=$(cut -d '/' -f 1 <<< "$GITHUB_REPOSITORY")
repo=$(cut -d '/' -f 2 <<< "$GITHUB_REPOSITORY")
Expand Down
62 changes: 50 additions & 12 deletions .github/actions/releaser/cr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

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

# NOTE: assume GNU semantics for tools like awk, grep, etc

set -o errexit
set -o nounset
set -o pipefail
Expand Down Expand Up @@ -35,39 +37,64 @@ release_charts_inside_folders() {
local folders=("$@")
local changed_charts=()

echo "fetch remote tags..."
git fetch --tags > /dev/null 2>&1
prepare_helm_repo

# form list of folder which was changed
for folder in "${folders[@]}"; do
[[ ! -f "$charts_dir/$folder/Chart.yaml" ]] && continue
print_line_separator
local chart_name
local tag
local chart_version
local chart_was_released

chart_name=$(read_chart_name "${charts_dir}/${folder}")
chart_version=$(read_chart_version "${charts_dir}/${folder}")
echo "Checking if \"$charts_dir/$folder\" has been released to the repo"
chart_was_released=$(chart_released "${chart_name}" "${chart_version}")

echo "Looking up latest release tag for \"$charts_dir/$folder/Chart.yaml\""
chart_name=$(awk '/^name/{print $2}' "$charts_dir/$folder/Chart.yaml")
echo "released result: ${chart_was_released}"

# if chart is not released or folder has change, then remember as changed_charts
if [[ ! "$(git tag -l "$chart_name-[0-9.]*")" ]] || has_changed "$folder"; then
if [ -n "${chart_was_released}" ] || has_changed "$folder"; then
changed_charts+=("$folder")
fi
done
echo "changed charts: " "${changed_charts[@]}"

# continue only with changed charts
if [[ -n "${changed_charts[*]}" ]]; then
helm repo update
install_chart_releaser
cleanup_releaser
package_charts "${changed_charts[@]}"
release_charts
update_index
if [ "${DRYRUN}" == "true" ]; then
echo "DRYRUN: Would have released charts" "${changed_charts[@]}"
else
release_changed_charts "${changed_charts[@]}"
fi
else
echo "Nothing to do. No chart changes detected."
fi
}

read_chart_name() {
local chart_path=$1
awk '/^name: /{print $2}' "$chart_path/Chart.yaml"
}

read_chart_version() {
local chart_path=$1
awk '/^version: /{print $2}' "$chart_path/Chart.yaml"
}

prepare_helm_repo() {
helm repo add mongodb https://mongodb.github.io/helm-charts
helm repo update mongodb
}

chart_released() {
local chart_name=$1
local version=$2

helm search repo "mongodb/${chart_name}" --version "${version}" |grep "${chart_name}\s"
}

# check if release version and chart version is diffrent
has_changed() {
local folder=$1
Expand Down Expand Up @@ -95,6 +122,17 @@ get_latest_tag(){
git describe --tags --abbrev=0 --match="$name-[0-9.]*" "$(git rev-list --tags --max-count=1)"
}

release_changed_charts() {
local changed_charts=("$@")

helm repo update
install_chart_releaser
cleanup_releaser
package_charts "${changed_charts[@]}"
release_charts
update_index
}

install_chart_releaser() {
print_line_separator
if [[ ! -d "$RUNNER_TOOL_CACHE" ]]; then
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ on:
type: string
default: ""
required: false
dryrun:
description: "not actually release, but check what would be done"
type: boolean
default: true
required: false

jobs:
build:
Expand Down Expand Up @@ -49,6 +54,7 @@ jobs:
target: |
atlas-operator-crds
community-operator-crds
dryrun: ${{ github.event.inputs.dryrun }}

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

0 comments on commit edc6de0

Please sign in to comment.