Skip to content

Commit

Permalink
update readme and finalize script
Browse files Browse the repository at this point in the history
Signed-off-by: Jordan Dubrick <[email protected]>
  • Loading branch information
Jdubrick committed Dec 9, 2024
1 parent c951b62 commit aa7923f
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 34 deletions.
46 changes: 40 additions & 6 deletions release/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# Cutting New Releases

## Requirements
<!--
TODO: Make this more official and up to date
-->
- GitHub CLI (Insert Link Here)
- User logged into CLI with write access to registry-support repo

- SSH key setup with GitHub
- See [GitHub documentation](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account) for more information
- Write access to the [devfile/registry-support](https://github.com/devfile/registry-support) repository

## Process
<!--
Expand All @@ -16,5 +15,40 @@ TODO: Update this process for the various ways to run the script
2. Or "I want to cut version 2.1.0, which is a Minor release"
2. Set the appropriate environment variables
1. `VERSION`
- In the form [Major].[Minor].[Patch]
2. `RELEASE_TYPE`
3. `RELEASE_CANDIDATE` - optional, defaults to `false` if unset
- One of [major, minor, patch]
3. `RELEASE_CANDIDATE`
- Defaults to `false` if unset
- Only applicable for `major` release types

## Examples

Major release v1.1.1
```
export VERISON=1.1.1
export RELEASE_TYPE=major
bash release.sh
```

Major release v2.0.0 that is a release candidate
```
export VERSION=2.0.0
export RELEASE_CANDIDATE=true
export RELEASE_TYPE=major
bash release.sh
```

Minor release v2.1.0
```
export VERSION=2.1.0
export RELEASE_TYPE=minor
bash release.sh
```

Patch release v2.1.1
```
export VERSION=2.1.1
export RELEASE_TYPE=patch
bash release.sh
```
62 changes: 34 additions & 28 deletions release/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,45 @@
# See the License for the specific language governing permissions and
# limitations under the License.

fetch_push_prior_release () {
git fetch $upstream_name --tags
LATEST_TAG=$(git tag --sort=-v:refname | head -n 1)
MODIFIED_TAG=$(echo "$LATEST_TAG" | awk -F. '{print $1 "." $2 ".x"}') # convert to [major].[minor].x format from [major].[minor].[patch]
git branch release/$MODIFIED_TAG $LATEST_TAG
git push $upstream_name release/$MODIFIED_TAG
git branch -D release/$MODIFIED_TAG
}

# append rc for release-candidate if necessary
tag_and_push () {
final_version="v$VERSION"
if [ "$1" == "rc" ]; then
final_version+="-rc"
fi
git tag $final_version
git push $upstream_name $final_version
}

TYPES=(
"major"
"minor"
"patch"
)

UPSTREAM="https://github.com/devfile/registry-support.git"


# $VERSION has to be set by the user in [major].[minor].[patch] format
if [ -z "${VERSION}" ]; then
echo "Environment variable \$VERSION not set. Aborting ..."
exit 1
fi

# RELEASE_CANDIDATE should be set to true for major version release candidates
if [[ ! $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Environment variable \$VERSION set to "$VERSION". Must be in [major].[minor].[patch] format ..."
exit 1
fi

# RELEASE_CANDIDATE should be set to true only for major version release candidates
if [ -z "${RELEASE_CANDIDATE}" ]; then
echo "Environment variable \$RELEASE_CANDIDATE not set. Defaulting to false ..."
RELEASE_CANDIDATE=false
Expand All @@ -54,12 +78,9 @@ else
fi
fi

exit 0

# Set upstream repo tracking if not already set
upstream_name=$(git remote -v | awk -v url="$UPSTREAM" '$2 == url {print $1; exit}')

# Setup upstream if not set
if [ -n "$upstream_name" ]; then
echo "Upstream repo found ... Name = $upstream_name, url=$UPSTREAM"
else
Expand All @@ -69,30 +90,15 @@ else
upstream_name="release-upstream"
fi


if [ "${RELEASE_TYPE}" == "major" ] && [ "${RELEASE_CANDIDATE}" == "true" ]; then
# 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
echo "Major release and release-candidate"
fetch_push_prior_commit
git push $upstream_name $upstream_name/main:rc/$VERSION
git tag $VERSION-rc
git push $upstream_name $VERSION-rc
fetch_push_prior_release
git push $upstream_name $upstream_name/main:refs/heads/rc/$VERSION
tag_and_push rc
elif [ "${RELEASE_TYPE}" == "patch" ]; then
tag_and_push
else
# major/minor normal workflow
echo "Major or Minor release"
fetch_push_prior_commit
# Create new tag in upstream
git tag $VERSION
git push $upstream_name $VERSION
fi

fetch_push_prior_commit () {
git fetch $upstream_name --tags
LATEST_TAG=$(git tag --sort=-v:refname | head -n 1)
MODIFIED_TAG=$(echo "$LATEST_TAG" | awk -F. '{print $1 "." $2 ".x"}') # convert to [major].[minor].x format from [major].[minor].[patch]
git checkout -b test-fetch-tag $LATEST_TAG #TODO: fix the test-fetch-tag to something better
git push $upstream_name release/$MODIFIED_TAG

# navigate back to main
git checkout main
}
fetch_push_prior_release
tag_and_push
fi

0 comments on commit aa7923f

Please sign in to comment.