From e9cea38b4ae4a98174f0fa528fd4d8ce4eda01bb Mon Sep 17 00:00:00 2001 From: Guilherme Branco Date: Fri, 16 Dec 2022 16:53:07 -0300 Subject: [PATCH] chore: adding hack scripts to help release process --- hack/README.md | 27 ++++++++++++++ hack/commit-release.sh | 84 ++++++++++++++++++++++++++++++++++++++++++ hack/tag-release.sh | 42 +++++++++++++++++++++ 3 files changed, 153 insertions(+) create mode 100644 hack/README.md create mode 100755 hack/commit-release.sh create mode 100755 hack/tag-release.sh diff --git a/hack/README.md b/hack/README.md new file mode 100644 index 00000000..6ffb7d45 --- /dev/null +++ b/hack/README.md @@ -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. diff --git a/hack/commit-release.sh b/hack/commit-release.sh new file mode 100755 index 00000000..d658b708 --- /dev/null +++ b/hack/commit-release.sh @@ -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 + diff --git a/hack/tag-release.sh b/hack/tag-release.sh new file mode 100755 index 00000000..f1a3d5fd --- /dev/null +++ b/hack/tag-release.sh @@ -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