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 8001f81
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .github/actions/releaser/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ 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
Expand All @@ -28,6 +32,7 @@ runs:
export CHART_DIR="${{ inputs.charts_dir }}"
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")
Expand Down
20 changes: 14 additions & 6 deletions .github/actions/releaser/cr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ 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}
Expand Down Expand Up @@ -58,7 +62,7 @@ release_charts_inside_folders() {
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_was_released}" == "Not found" ] || has_changed "$folder"; then
changed_charts+=("$folder")
fi
done
Expand Down Expand Up @@ -95,16 +99,20 @@ check_charts_released() {
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}\""
echo "Has been released result: \"${chart_was_released}\""

if [ -z "${chart_was_released}" ]; then
if [ "${chart_was_released}" == "Not found" ]; 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 Down Expand Up @@ -219,7 +227,7 @@ 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[@]}"
Expand Down
21 changes: 20 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,33 @@ 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

- 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: |
git config user.name "$GITHUB_ACTOR"
Expand Down Expand Up @@ -64,7 +79,11 @@ jobs:
uses: ./.github/actions/releaser
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
CHARTS_DIR: ${{ github.event.inputs.backport-branch == '' && 'charts' || format('{0}/charts', 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 }}
charts_dir: ${{ env.CHARTS_DIR }}
mark_latest: ${{ env.MARK_LATEST }}

0 comments on commit 8001f81

Please sign in to comment.