diff --git a/.github/actions/releaser/action.yml b/.github/actions/releaser/action.yml index bdddcc9c..6d8b02fe 100644 --- a/.github/actions/releaser/action.yml +++ b/.github/actions/releaser/action.yml @@ -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 @@ -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") diff --git a/.github/actions/releaser/cr.sh b/.github/actions/releaser/cr.sh index a9ab1db2..4f4864de 100755 --- a/.github/actions/releaser/cr.sh +++ b/.github/actions/releaser/cr.sh @@ -8,6 +8,8 @@ set -o errexit set -o nounset set -o pipefail +mark_latest=${MARK_LATEST:-true} + main() { local version=${VERSION:-v1.2.1} local charts_dir=${CHART_DIR:-charts} @@ -58,7 +60,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 @@ -95,16 +97,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 @@ -219,7 +225,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[@]}" diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 387f7286..279a0866 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,14 +18,29 @@ on: type: boolean default: true required: false + backport-branch: + description: "Set backport branch if different CI branch (allows to deliver backports on older versions)" + 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" @@ -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 }}