Skip to content

Commit c951b62

Browse files
committed
initial setup for release script and docs
Signed-off-by: Jordan Dubrick <[email protected]>
1 parent dcd68f7 commit c951b62

File tree

2 files changed

+118
-0
lines changed

2 files changed

+118
-0
lines changed

release/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Cutting New Releases
2+
3+
## Requirements
4+
<!--
5+
TODO: Make this more official and up to date
6+
-->
7+
- GitHub CLI (Insert Link Here)
8+
- User logged into CLI with write access to registry-support repo
9+
10+
## Process
11+
<!--
12+
TODO: Update this process for the various ways to run the script
13+
-->
14+
1. Determine version and type you wish to cut
15+
1. E.g. "I want to cut version 2.0.0, which is a Major release"
16+
2. Or "I want to cut version 2.1.0, which is a Minor release"
17+
2. Set the appropriate environment variables
18+
1. `VERSION`
19+
2. `RELEASE_TYPE`
20+
3. `RELEASE_CANDIDATE` - optional, defaults to `false` if unset

release/release.sh

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/bin/bash
2+
3+
#
4+
# Copyright Red Hat
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
TYPES=(
19+
"major"
20+
"minor"
21+
)
22+
23+
UPSTREAM="https://github.com/devfile/registry-support.git"
24+
25+
26+
# $VERSION has to be set by the user in [major].[minor].[patch] format
27+
if [ -z "${VERSION}" ]; then
28+
echo "Environment variable \$VERSION not set. Aborting ..."
29+
exit 1
30+
fi
31+
32+
# RELEASE_CANDIDATE should be set to true for major version release candidates
33+
if [ -z "${RELEASE_CANDIDATE}" ]; then
34+
echo "Environment variable \$RELEASE_CANDIDATE not set. Defaulting to false ..."
35+
RELEASE_CANDIDATE=false
36+
fi
37+
38+
# RELEASE_TYPE should be one of $TYPES defined above
39+
if [ -z "${RELEASE_TYPE}" ]; then
40+
echo "Environment variable \$RELEASE_TYPE not set. Aborting ..."
41+
exit 1
42+
else
43+
found=false
44+
for type in "${TYPES[@]}"; do
45+
if [ "$type" == "$RELEASE_TYPE" ]; then
46+
found=true
47+
break
48+
fi
49+
done
50+
51+
if [ "$found" == "false" ]; then
52+
echo "Environment variable \$RELEASE_TYPE set to: "${RELEASE_TYPE}". Must be one of: "${TYPES[@]}" ..."
53+
exit 1
54+
fi
55+
fi
56+
57+
exit 0
58+
59+
# Set upstream repo tracking if not already set
60+
upstream_name=$(git remote -v | awk -v url="$UPSTREAM" '$2 == url {print $1; exit}')
61+
62+
# Setup upstream if not set
63+
if [ -n "$upstream_name" ]; then
64+
echo "Upstream repo found ... Name = $upstream_name, url=$UPSTREAM"
65+
else
66+
echo "Upstream not set ..."
67+
echo "Setting upstream to ... Name = release-upstream, url=$UPSTREAM"
68+
git remote add release-upstream $UPSTREAM
69+
upstream_name="release-upstream"
70+
fi
71+
72+
73+
if [ "${RELEASE_TYPE}" == "major" ] && [ "${RELEASE_CANDIDATE}" == "true" ]; then
74+
# the release associated with this tag will be a pre-release, and we should be moving the code to a rc/<name> branch alongside the prev release
75+
echo "Major release and release-candidate"
76+
fetch_push_prior_commit
77+
git push $upstream_name $upstream_name/main:rc/$VERSION
78+
git tag $VERSION-rc
79+
git push $upstream_name $VERSION-rc
80+
else
81+
# major/minor normal workflow
82+
echo "Major or Minor release"
83+
fetch_push_prior_commit
84+
# Create new tag in upstream
85+
git tag $VERSION
86+
git push $upstream_name $VERSION
87+
fi
88+
89+
fetch_push_prior_commit () {
90+
git fetch $upstream_name --tags
91+
LATEST_TAG=$(git tag --sort=-v:refname | head -n 1)
92+
MODIFIED_TAG=$(echo "$LATEST_TAG" | awk -F. '{print $1 "." $2 ".x"}') # convert to [major].[minor].x format from [major].[minor].[patch]
93+
git checkout -b test-fetch-tag $LATEST_TAG #TODO: fix the test-fetch-tag to something better
94+
git push $upstream_name release/$MODIFIED_TAG
95+
96+
# navigate back to main
97+
git checkout main
98+
}

0 commit comments

Comments
 (0)