Skip to content

Commit d9cbefc

Browse files
committed
verify release branch logic
Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
1 parent 46c8b22 commit d9cbefc

File tree

1 file changed

+34
-13
lines changed

1 file changed

+34
-13
lines changed

make-release.sh

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ if [[ $# -lt 1 ]]; then usage; fi
2626
SCHEMA_VERSION=$1
2727
FIRST_DIGIT="${SCHEMA_VERSION%%.*}"
2828
RELEASE_BRANCH="release-v${FIRST_DIGIT}"
29+
DEVFILE_REPO="git@github.com:devfile/registry-operator.git"
30+
## This will be uncommented for actual devfile repo
31+
RELEASE_UPSTREAM_NAME="devfile-upstream-release"
32+
# This goes to my origin for testing
33+
#RELEASE_UPSTREAM_NAME="origin"
2934

3035
if ! command -v hub > /dev/null; then
3136
echo "[ERROR] The hub CLI needs to be installed. See https://github.com/github/hub/releases"
@@ -40,14 +45,23 @@ if ! [[ "$SCHEMA_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
4045
exit 1
4146
fi
4247

48+
# Sets the upstream to devfile repo to ensure that git commands are performed on the correct repo
49+
# Ensures users who don't have an upstream set will be able to run script with no setup
50+
setUpstream(){
51+
if git remote -v | grep -q "$RELEASE_UPSTREAM_NAME[[:space:]]\+$DEVFILE_REPO"; then
52+
git remote rm ${RELEASE_UPSTREAM_NAME}
53+
fi
54+
git remote add ${RELEASE_UPSTREAM_NAME} "${DEVFILE_REPO}"
55+
}
56+
4357

4458
## Ensures local branch matches the remote
4559
resetChanges() {
4660
echo "[INFO] Reset changes in $1 branch"
4761
git reset --hard
4862
git checkout $1
49-
git fetch origin --prune
50-
git pull origin $1
63+
git fetch ${RELEASE_UPSTREAM_NAME} --prune
64+
git pull ${RELEASE_UPSTREAM_NAME} $1
5165
}
5266

5367
## Branch containing releases and tags in main upstream repo will be named 'release-vx' where 'vx' is the major release
@@ -84,13 +98,14 @@ updateVersionNumbers() {
8498
yq eval ".spec.version = \"$SCHEMA_VERSION\"" --inplace ./config/manifests/bases/registry-operator.clusterserviceversion.yaml
8599
}
86100

101+
# Export env variables that are used in bundle scripts
87102
exportEnvironmentVariables() {
88103
CHANNEL=$(yq eval '.annotations."operators.operatorframework.io.bundle.channels.v1"' ./bundle/metadata/annotations.yaml)
89104
export IMG=quay.io/devfile/registry-operator:v$SCHEMA_VERSION
90105
export CHANNELS=$CHANNEL
91-
92106
}
93107

108+
# Commits version changes to your forked repository
94109
commitChanges() {
95110
echo "[INFO] Pushing changes to $SCHEMA_VERSION branch"
96111
git add -A
@@ -102,14 +117,24 @@ commitChanges() {
102117
# with the name release-vX
103118
## This func will be used when we have a new major release and there is no branch in the upstream repo
104119
createNewReleaseBranch(){
105-
git checkout -b "${RELEASE_BRANCH}" main
106-
git push origin "${RELEASE_BRANCH}"
107-
#hub sync
120+
git checkout -b "${RELEASE_BRANCH}" "${RELEASE_UPSTREAM_NAME}"/main
121+
git push "${RELEASE_UPSTREAM_NAME}" "${RELEASE_BRANCH}"
122+
#hub sync -- this supposedly will create that branch in upstream
123+
}
124+
125+
verifyReleaseBranch() {
126+
if git ls-remote --exit-code --heads ${RELEASE_UPSTREAM_NAME} "$RELEASE_BRANCH" >/dev/null 2>&1; then
127+
echo "Branch $RELEASE_BRANCH exists in the upstream repository."
128+
else
129+
echo "Branch $RELEASE_BRANCH does not exist in the upstream repository."
130+
#createNewReleaseBranch
131+
132+
fi
108133
}
109134

110135
createPullRequest(){
111136
echo "[INFO] Creating a PR"
112-
hub pull-request --base jdubrick:${RELEASE_BRANCH} --head ${SCHEMA_VERSION} -m "$1"
137+
hub pull-request --base ${RELEASE_UPSTREAM_NAME}:${RELEASE_BRANCH} --head ${SCHEMA_VERSION} -m "$1"
113138
}
114139

115140
main(){
@@ -120,12 +145,8 @@ main(){
120145
# commitChanges "chore(release): release version ${SCHEMA_VERSION}"
121146
#createPullRequest "v${SCHEMA_VERSION} Release"
122147
# Check if the branch exists in the remote repository
123-
if git ls-remote --exit-code --heads origin "$RELEASE_BRANCH" >/dev/null 2>&1; then
124-
echo "Branch $RELEASE_BRANCH exists in the remote repository."
125-
else
126-
echo "Branch $RELEASE_BRANCH does not exist in the remote repository."
127-
createNewReleaseBranch
128-
fi
148+
verifyReleaseBranch
149+
#setUpstream -- LEAVE COMMENTED AS THIS WILL SET MY ORIGIN TO DEVFILE
129150
}
130151

131152
main

0 commit comments

Comments
 (0)