From 3b644cef3329fd0f630ff787c992f56077ba5cbf Mon Sep 17 00:00:00 2001 From: Alexandre Lavigne Date: Tue, 5 Sep 2023 13:31:45 +0200 Subject: [PATCH 1/4] pre-create waterfall branches in bump version action By creating the waterfall branches in bump version we ensure when opening the PR that bert-e is already happy and we don't need to solve conflict ourselves knowing that we don't want to keep the upade as the update only contains the version bump for version x.y and we try to merge in upper version branches wo th version is already x+1.y+1 and we don't want to forward-port this change. --- xcore/bump_version_pull_request/action.yaml | 22 ++----- .../push_new_version.sh | 62 +++++++++++++++++++ 2 files changed, 68 insertions(+), 16 deletions(-) create mode 100755 xcore/bump_version_pull_request/push_new_version.sh diff --git a/xcore/bump_version_pull_request/action.yaml b/xcore/bump_version_pull_request/action.yaml index f351dfd..10397d9 100644 --- a/xcore/bump_version_pull_request/action.yaml +++ b/xcore/bump_version_pull_request/action.yaml @@ -29,7 +29,7 @@ runs: - name: install semver shell: bash run: | - curl --fail -LO https://raw.githubusercontent.com/fsaintjacques/semver-tool/3.3.0/src/semver + curl -s --fail -LO https://raw.githubusercontent.com/fsaintjacques/semver-tool/3.3.0/src/semver chmod +x ./semver - name: extract version shell: bash @@ -46,22 +46,12 @@ runs: - name: push changes shell: bash run: | - NEW_VERSION=${{ steps.bumped-version.outputs.new_version }} - git checkout -b feature/bump_version_${NEW_VERSION} ${{ github.ref }} + ${GITHUB_ACTION_PATH}/push_new_version.sh \ + ${{ github.actor }} \ + ${{ github.ref }} \ + ${{ steps.version.outputs.VERSION }} \ + ${{ steps.bumped-version.outputs.new_version }} - # update version patch level - sed -i "s/VERSION=.*/VERSION=${NEW_VERSION}/" ./VERSION - - git add ./VERSION - - # config git to commit - git config --local user.name ${{ github.actor }} - git config --local user.email ${{ github.actor }}@scality.com - - # commit changes - git commit -m "Bump version to ${NEW_VERSION}" - - git push --set-upstream origin feature/bump_version_${NEW_VERSION} - name: Open pr id: pull-request shell: bash diff --git a/xcore/bump_version_pull_request/push_new_version.sh b/xcore/bump_version_pull_request/push_new_version.sh new file mode 100755 index 0000000..f1bd2da --- /dev/null +++ b/xcore/bump_version_pull_request/push_new_version.sh @@ -0,0 +1,62 @@ +#!/bin/bash + +set -e + +if [[ $# != 4 ]]; then + echo "usage: $0 " + exit 1 +fi + +GITHUB_ACTOR=$1 +REF=$2 +VERSION=$3 +NEW_VERSION=$4 +git fetch --all --unshallow + +git checkout -b feature/bump_version_${NEW_VERSION} ${REF} + +# update version patch level +sed -i "s/VERSION=.*/VERSION=${NEW_VERSION}/" ./VERSION + +git add ./VERSION + +# config git to commit +git config --local user.name ${GITHUB_ACTOR} +git config --local user.email ${GITHUB_ACTOR}@scality.com + +# commit changes +git commit -m "Bump version to ${NEW_VERSION}" + +# fetch all branches +all_dev_branches=$(git branch --all | grep -E 'origin/development/' | grep -v HEAD | sed 's_remotes/origin/development/__' | sort -u | tr -s '\n' ' ') +short_version=$(./semver get major ${VERSION}).$(./semver get minor ${VERSION}) + +echo "Find upper branches in: ${all_dev_branches}" +echo "based on current branch: ${short_version}" + +# Identify the upper version branches +upper_branches="" +for branch in ${all_dev_branches}; do + is_upper=$(./semver compare "${branch}.0" "${short_version}.0") + if [[ "${is_upper}" -gt 0 ]]; then + upper_branches="${upper_branches}${branch} " + fi +done + +echo "Prepare waterfall branches for: ${upper_branches}" +base_branch="feature/bump_version_${NEW_VERSION}" + +for branch in ${upper_branches}; do + echo "Create and push waterfall branch for origin/development/${branch}" + git checkout -B w/${branch}/feature/bump_version_${NEW_VERSION} origin/development/${branch} + + # We now we can always use 'ours' as this sould only update the version file for the current branch only + git merge --strategy=ours --no-edit ${base_branch} + + git push -u origin w/${branch}/feature/bump_version_${NEW_VERSION} + base_branch="w/${branch}/feature/bump_version_${NEW_VERSION}" +done + +# don't forget to checkout the original branch too +git checkout feature/bump_version_${NEW_VERSION} +git push --set-upstream origin feature/bump_version_${NEW_VERSION} From ba74209931b6362bd519c74021f3813a009ef560 Mon Sep 17 00:00:00 2001 From: Alexandre Lavigne Date: Tue, 12 Sep 2023 13:54:19 +0200 Subject: [PATCH 2/4] add pre-cleanup process in the CI In case of left over from previous failed run, cleanup any branches that could prevent the workflow from running --- .github/workflows/bump_version.yaml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/bump_version.yaml b/.github/workflows/bump_version.yaml index aedf80d..c710c6e 100644 --- a/.github/workflows/bump_version.yaml +++ b/.github/workflows/bump_version.yaml @@ -1,4 +1,4 @@ -name: 'Test upload Dockerfile' +name: 'Test Bump version' on: push @@ -13,6 +13,16 @@ jobs: - name: create fake version file run: | echo "VERSION=1.2.3" > VERSION + - name: Check the feature branch does not exists + env: + BUMP_BRANCH: feature/bump_version_1.2.4 + run: | + # disable error as grep return 1 if nothing is found + res=$(git branch --list --all | grep ${BUMP_BRANCH}) + if [[ "${res}" != "" ]]; then + git branch -D ${BUMP_BRANCH} + git push --delete origin ${BUMP_BRANCH} + if - uses: ./xcore/bump_version_pull_request id: pull-request - name: check version is bumped From e98731cc57f02c640425ac973d924a3b0abd4626 Mon Sep 17 00:00:00 2001 From: Alexandre Lavigne Date: Tue, 12 Sep 2023 13:56:50 +0200 Subject: [PATCH 3/4] prevent exit on error --- .github/workflows/bump_version.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/bump_version.yaml b/.github/workflows/bump_version.yaml index c710c6e..d0ab3eb 100644 --- a/.github/workflows/bump_version.yaml +++ b/.github/workflows/bump_version.yaml @@ -18,7 +18,9 @@ jobs: BUMP_BRANCH: feature/bump_version_1.2.4 run: | # disable error as grep return 1 if nothing is found + set +e res=$(git branch --list --all | grep ${BUMP_BRANCH}) + set -e if [[ "${res}" != "" ]]; then git branch -D ${BUMP_BRANCH} git push --delete origin ${BUMP_BRANCH} From 6a0cd771be988587623956580df7a3aba35f5712 Mon Sep 17 00:00:00 2001 From: Alexandre Lavigne Date: Tue, 12 Sep 2023 13:58:36 +0200 Subject: [PATCH 4/4] fix typo in shell script --- .github/workflows/bump_version.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/bump_version.yaml b/.github/workflows/bump_version.yaml index d0ab3eb..91e4a9e 100644 --- a/.github/workflows/bump_version.yaml +++ b/.github/workflows/bump_version.yaml @@ -24,7 +24,8 @@ jobs: if [[ "${res}" != "" ]]; then git branch -D ${BUMP_BRANCH} git push --delete origin ${BUMP_BRANCH} - if + fi + - uses: ./xcore/bump_version_pull_request id: pull-request - name: check version is bumped