From 1c478b604109797bb19d7d70c04f80856ef1a14e Mon Sep 17 00:00:00 2001 From: David Simansky Date: Fri, 23 Sep 2022 16:40:06 +0200 Subject: [PATCH] Add mirror-upstream-branches.sh script (#1134) * Add mirror-upstream-branches.sh script * Fix multiple release branches * Fix commented code --- openshift/release/mirror-upstream-branches.sh | 41 +++++++++++++++++++ openshift/release/update-to-head.sh | 3 ++ 2 files changed, 44 insertions(+) create mode 100755 openshift/release/mirror-upstream-branches.sh diff --git a/openshift/release/mirror-upstream-branches.sh b/openshift/release/mirror-upstream-branches.sh new file mode 100755 index 0000000000..ec0937501c --- /dev/null +++ b/openshift/release/mirror-upstream-branches.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +# Usage: openshift/release/mirror-upstream-branches.sh +# This should be run from the basedir of the repo with no arguments + + +set -ex +readonly TMPDIR=$(mktemp -d knativeClientBranchingCheckXXXX -p /tmp/) + +git fetch upstream --tags +git fetch openshift --tags + +# We need to seed this with a few releases that, otherwise, would make +# the processing regex less clear with more anomalies +cat >> "$TMPDIR"/midstream_branches < "$TMPDIR"/upstream_branches +git branch --list -a "openshift/release-v1.*" | cut -f3 -d'/' | cut -f2 -d'v' | cut -f1,2 -d'.' >> "$TMPDIR"/midstream_branches + +sort -o "$TMPDIR"/midstream_branches "$TMPDIR"/midstream_branches +sort -o "$TMPDIR"/upstream_branches "$TMPDIR"/upstream_branches +comm -32 "$TMPDIR"/upstream_branches "$TMPDIR"/midstream_branches > "$TMPDIR"/new_branches + +UPSTREAM_BRANCHES=$(cat "$TMPDIR"/new_branches | tr '\n' ' ') + +if [ -z "$UPSTREAM_BRANCHES" ]; then + echo "no new branch, exiting" + exit 0 +fi + +for UPSTREAM_BRANCH in ${UPSTREAM_BRANCHES[@]}; do + echo "found upstream branch: $UPSTREAM_BRANCH" + UPSTREAM_TAG="knative-v$UPSTREAM_BRANCH.0" + MIDSTREAM_BRANCH="release-v$UPSTREAM_BRANCH" + $(dirname "${BASH_SOURCE[0]}")/openshift/release/create-release-branch.sh "$UPSTREAM_TAG" "$MIDSTREAM_BRANCH" + # we would check the error code, but we 'set -e', so assume we're fine + git push openshift "$MIDSTREAM_BRANCH" +done diff --git a/openshift/release/update-to-head.sh b/openshift/release/update-to-head.sh index dc23a462a7..9e45c41725 100755 --- a/openshift/release/update-to-head.sh +++ b/openshift/release/update-to-head.sh @@ -20,6 +20,9 @@ set -e REPO_NAME=$(basename $(git rev-parse --show-toplevel)) +# Check if there's an upstream release we need to mirror downstream +openshift/release/mirror-upstream-branches.sh + # Custom files custom_files=$(cat <