diff --git a/.github/actions/releaser/action.yml b/.github/actions/releaser/action.yml index 2d8d17ed..bdddcc9c 100644 --- a/.github/actions/releaser/action.yml +++ b/.github/actions/releaser/action.yml @@ -15,6 +15,9 @@ inputs: target: description: "Specific charts folder inside for releasing" required: false + dryrun: + description: "not actually release, but check what would be done" + required: false runs: using: composite @@ -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") diff --git a/.github/actions/releaser/cr.sh b/.github/actions/releaser/cr.sh index 06ec472e..e97731e0 100755 --- a/.github/actions/releaser/cr.sh +++ b/.github/actions/releaser/cr.sh @@ -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 @@ -35,21 +37,25 @@ 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 [ -z "${chart_was_released}" ] || has_changed "$folder"; then changed_charts+=("$folder") fi done @@ -57,17 +63,38 @@ release_charts_inside_folders() { # 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 @@ -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 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a44cf8f1..387f7286 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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: @@ -49,6 +54,7 @@ jobs: target: | atlas-operator-crds community-operator-crds + dryrun: ${{ github.event.inputs.dryrun }} - name: Get latest charts from repo run: | @@ -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 }}