Skip to content

Commit

Permalink
Merge pull request #418 from gdbranco/chore/hack-scripts-to-help-release
Browse files Browse the repository at this point in the history
Adding hack scripts to help release process
  • Loading branch information
Irit Goihman authored Dec 19, 2022
2 parents 0f4fd21 + e9cea38 commit 25d7a0b
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 0 deletions.
27 changes: 27 additions & 0 deletions hack/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# OCM Helper Scripts

These scripts help in the process of releasing new versions of `ocm`.

Once all changes for a specific release are in `main`, the next step is to
create a release commit:

./hack/commit-release.sh

This creates a new branch, updates the OCM build version and changelog file
then commits and pushes to GitHub. Any potentially destructing action has a
confirmation prompt.

Once this new branch is pushed, someone has to merge it. Once merged, make sure
to update your local copy. Then you can tag the actual release:

./hack/tag-release.sh

This will create a new annotated tag and push it to the upstream OCM
repository.

Now that the tag is in place, you will go to the
[tags page](https://github.com/openshift/ocm/tags) and edit the latest one. In
there make sure that the release title and description match the release tag
annotation.

Publish the release and you're done.
84 changes: 84 additions & 0 deletions hack/commit-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/bin/bash
#
# Copyright (c) 2022 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# This generates the commit necessary for release of the next z-stream tag.

git fetch --tags
tagcommit=$(git rev-list --tags --max-count=1)
current=$(git describe --tags $tagcommit | sed 's/v//')
echo "Current version is $current"

base=$(echo $current | grep -o ".*\.")
next_z=$(echo $current | sed -E "s/.*\.([0-9]*)/\1+1/" | bc)
base_y=$(echo $current | grep -o "^[0-9]*\.[0-9]*")
next_y=$(echo $base_y | awk -F. '{$NF = $NF + 1;} 1' | sed 's/ /./g')

# Update version
read -r -p "Bump minor version for '$current' ocm cli? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]
then
next=$next_y.0
else
next=$base$next_z
fi

echo "Next version will be $next"

# Update version
read -r -p "Update version to '$next'? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]
then
sed -i "s/$current/$next/" pkg/info/info.go
fi

# Update changelog
read -r -p "Update changelog? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]
then
log=$(git log v$current..HEAD --oneline --no-merges --no-decorate --reverse | sed "s/^\w*/-/")
echo "$log"

rest=$(awk "/ $current /{found=1} found" CHANGES.md)
header=$(cat << EOM
# Changes
This document describes the relevant changes between releases of the\n\`ocm\` command line tool.
EOM
)
echo -e "$header\n\n## $next $(date "+%b %-d %Y")\n\n$log\n\n$rest" > CHANGES.md
fi

# Commit changes
branch="release_$next"
read -r -p "Commit changes to branch '$branch'? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]
then
git checkout -b $branch
git commit --all --message "Release v$next" --message "$log"
else
echo -e "\tgit checkout -b $branch"
echo -e "\tgit commit --all"
fi

read -r -p "Push branch '$branch' to GitHub? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]
then
git push --set-upstream origin $branch
else
echo -e "\tgit push --set-upstream origin $branch"
fi

42 changes: 42 additions & 0 deletions hack/tag-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash
#
# Copyright (c) 2022 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# This tags the latest release

current=$(git tag --list --sort version:refname | tail -n1)
next="v$(cat pkg/info/info.go | grep -o '[0-9.]*' | tail -n1)"
echo "Tagging release $next"

# Create git release tag
log=$(git log $current..HEAD --oneline --no-merges --no-decorate --reverse | grep -v $next | sed "s/^\w*/-/")
read -r -p "Create release tag '$next'? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]
then
git tag --annotate --message "Release $next" --message "$log" $next
else
echo -e "\tgit tag --annotate $next"
fi

# Push git release tag to upstream GitHub repository
upstream=$(git remote --verbose | grep "github\.com.openshift-online\/ocm-cli\.git" | tail -n1 | awk '{print $1}')
read -r -p "Push tag '$next' to GitHub? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]
then
git push $upstream $next
else
echo -e "\tgit push $upstream $next"
fi

0 comments on commit 25d7a0b

Please sign in to comment.