Skip to content

Commit

Permalink
CLOUDP-226369: Allow backport releases
Browse files Browse the repository at this point in the history
Signed-off-by: jose.vazquez <[email protected]>
  • Loading branch information
josvazg committed Feb 6, 2024
1 parent 2fcc060 commit f56b0e5
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 45 deletions.
16 changes: 11 additions & 5 deletions .github/actions/releaser/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ inputs:
description: "The chart-releaser version to use (default: v1.2.1)"
required: false
default: v1.6.0
charts_dir:
description: "The charts directory"
work_dir:
description: "The repo directory"
required: false
default: charts
default: "."
charts_repo_url:
description: "The GitHub Pages URL to the charts repo (default: https://<owner>.github.io/<repo>)"
required: true
Expand All @@ -18,20 +18,26 @@ inputs:
dryrun:
description: "not actually release, but check what would be done"
required: false
mark_latest:
description: "mark released charts as latest"
required: false
default: "true"

runs:
using: composite
steps:
- shell: bash
run: |
export VERSION="${{ inputs.version }}"
export CHART_DIR="${{ inputs.charts_dir }}"
export WORK_DIR=${{ inputs.work_dir }}
export CHART_DIR="charts"
export CHARTS_REPO_URL="${{ inputs.charts_repo_url }}"
export DRYRUN="${{ inputs.dryrun }}"
export MARK_LATEST="${{ inputs.mark_latest }}"
owner=$(cut -d '/' -f 1 <<< "$GITHUB_REPOSITORY")
repo=$(cut -d '/' -f 2 <<< "$GITHUB_REPOSITORY")
export OWNER=$owner
export REPO=$repo
"$GITHUB_ACTION_PATH/cr.sh" "${{ inputs.target }}"
cd $WORK_DIR && "$GITHUB_ACTION_PATH/cr.sh" "${{ inputs.target }}"
52 changes: 16 additions & 36 deletions .github/actions/releaser/cr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ set -o errexit
set -o nounset
set -o pipefail

set -x

mark_latest=${MARK_LATEST:-true}

main() {
local version=${VERSION:-v1.2.1}
local charts_dir=${CHART_DIR:-charts}
local charts_repo_url=${CHARTS_REPO_URL:-}
local target=("$@")
local owner=${OWNER:-}
local repo=${REPO:-}
Expand Down Expand Up @@ -48,17 +51,13 @@ release_charts_inside_folders() {
print_line_separator
local chart_name
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 "released result: \"${chart_was_released}\""

# if chart is not released or folder has change, then remember as changed_charts
if [ -z "${chart_was_released}" ] || has_changed "$folder"; then
if ! chart_released "${chart_name}" "${chart_version}"; then
changed_charts+=("$folder")
fi
done
Expand Down Expand Up @@ -88,23 +87,23 @@ check_charts_released() {
print_line_separator
local chart_name
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 "released result: \"${chart_was_released}\""

if [ -z "${chart_was_released}" ]; then
if ! chart_released "${chart_name}" "${chart_version}"; then
unreleased_charts+=("$chart_name")
fi
done

if [[ -n "${unreleased_charts[*]}" ]]; then
echo "FAIL: found unreleased charts:" "${unreleased_charts[@]}"
exit 1
if [ "${DRYRUN}" == "true" ]; then
echo "DRYRUN: would have not seen released charts for" "${unreleased_charts[@]}"
else
echo "FAIL: found unreleased charts:" "${unreleased_charts[@]}"
exit 1
fi
else
echo "PASS: all latest helm charts released for" "${folders[@]}"
fi
Expand All @@ -129,27 +128,7 @@ chart_released() {
local chart_name=$1
local version=$2

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

# check if release version and chart version is diffrent
has_changed() {
local folder=$1
local chart_name
chart_name=$(awk '/^name/{print $2}' "$charts_dir/$folder/Chart.yaml")
tag=$(get_latest_tag "$chart_name")
changed_files=$(git diff --find-renames --name-only "$tag" -- "$charts_dir/$folder")

echo "Looking for versions..."
tag_version=$(echo "$tag" | awk -F '-' '{print $NF}') # sample-0.1.1 | 0.1.1
chart_version=$(awk '/^version: /{print $2}' "$charts_dir/$folder/Chart.yaml")
echo "version from tag: $tag_version"
echo "version from chart: $chart_version"

if [[ "$tag_version" != "$chart_version" ]] && [[ -n "$changed_files" ]]; then
return 0
fi
return 1
helm search repo "mongodb/${chart_name}" --version "${version}" | grep -q "${chart_name}\s"
}

get_latest_tag(){
Expand Down Expand Up @@ -219,15 +198,16 @@ package_charts() {
}

release_charts() {
local args=(-o "$owner" -r "$repo" -c "$(git rev-parse HEAD)")
local args=(-o "$owner" -r "$repo" -c "$(git rev-parse HEAD)" --make-release-latest "${mark_latest}")

echo 'Releasing charts...'
cr upload "${args[@]}"
}

update_index() {
local args=(-o "$owner" -r "$repo" -c "$charts_repo_url" --push)
local args=(-o "$owner" -r "$repo" --push --remote origin --pages-branch gh-pages)

git fetch
echo 'Updating charts repo index...'
cr index "${args[@]}"
}
Expand Down
38 changes: 34 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,45 @@ on:
default: ""
required: false
dryrun:
description: "not actually release, but check what would be done"
description: "dry-run"
type: boolean
default: true
required: false
backport-branch:
description: "Branch or leave empty for current CI branch"
type: string
default: ""
required: true

jobs:
build:
runs-on: ubuntu-latest
env:
BACKPORT_BRANCH: ${{ github.event.inputs.backport-branch || '' }}
BACKPORT_DIR: 'backport'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
path: current

- name: Checkout Backport branch
uses: actions/checkout@v4
if: github.event.inputs.backport-branch != ''
with:
ref: ${{ env.BACKPORT_BRANCH }}
path: ${{ env.BACKPORT_DIR }}

- name: Configure Git
run: |
cd current
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
- name: Configure Git for backport
if: github.event.inputs.backport-branch != ''
run: |
cd ${{ env.BACKPORT_DIR }}
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
Expand All @@ -42,10 +67,10 @@ jobs:
- name: Allow script
run: |
chmod +x ./.github/actions/releaser/cr.sh
chmod +x ./current/.github/actions/releaser/cr.sh
- name: Helm Chart Dependency Releaser
uses: ./.github/actions/releaser
uses: ./current/.github/actions/releaser
if: github.event.inputs.target == ''
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
Expand All @@ -55,16 +80,21 @@ jobs:
atlas-operator-crds
community-operator-crds
dryrun: ${{ github.event.inputs.dryrun }}
work_dir: current

- name: Get latest charts from repo
run: |
helm repo update
- name: Helm Chart Releaser
uses: ./.github/actions/releaser
uses: ./current/.github/actions/releaser
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
WORK_DIR: ${{ github.event.inputs.backport-branch == '' && 'current' || env.BACKPORT_DIR }}
MARK_LATEST: ${{ github.event.inputs.backport-branch == '' && 'true' || 'false' }}
with:
charts_repo_url: https://mongodb.github.io/helm-charts
target: ${{ github.event.inputs.target }}
dryrun: ${{ github.event.inputs.dryrun }}
work_dir: ${{ env.WORK_DIR }}
mark_latest: ${{ env.MARK_LATEST }}

0 comments on commit f56b0e5

Please sign in to comment.