From a15e507b2ec10eab06a9181be420b7b50da99246 Mon Sep 17 00:00:00 2001 From: Rahul Patel Date: Fri, 20 Mar 2020 22:22:21 -0700 Subject: [PATCH] Scripts for releasing. (#576) * Scripts for releasing. - fixes #510 * fix review comments. Co-authored-by: Joshua MacDonald --- RELEASING.md | 36 ++++++++++++++++++++++++ pre_release.sh | 64 ++++++++++++++++++++++++++++++++++++++++++ tag.sh | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 175 insertions(+) create mode 100644 RELEASING.md create mode 100755 pre_release.sh create mode 100755 tag.sh diff --git a/RELEASING.md b/RELEASING.md new file mode 100644 index 000000000..7bbaffa04 --- /dev/null +++ b/RELEASING.md @@ -0,0 +1,36 @@ +# Release Process + +## Pre-Release +Update go.mod for submodules to depend on the new release which will happen +in the next step. This will create build failure for those who depend +on the master branch instead or released version. But they shouldn't be +depending on the master. So it is not a concern. + +1. Run the pre-release script. It creates a branch pre_release_ to make the changes. +2. Verify the changes. +3. Push the changes to upstream. +4. Create a PR on github and merge the PR once approved. + + ``` + ./pre-release.sh -t + git diff master + git push + ``` + + +## Tag +Now create a new Tag on the commit hash of the changes made in pre-release step. +Use the same tag as used in the pre-release step. + +1. Run the tag.sh script. +2. Push tags upstream. Make sure you run this for all sub-modules as well. + + ``` + ./tag.sh -t -c + git push upstream + git push upstream + ``` + +## Release +Now create a release for the new tag on github. tag.sh script generates commit logs since +last release. Use that to draft the new release. diff --git a/pre_release.sh b/pre_release.sh new file mode 100755 index 000000000..af1c5d68c --- /dev/null +++ b/pre_release.sh @@ -0,0 +1,64 @@ +#!/bin/sh + +set -e + +help() +{ + printf "\n" + printf "Usage: $0 -t tag\n" + printf "\t-t Unreleased tag. Update all go.mod with this tag.\n" + exit 1 # Exit script after printing help +} + +while getopts "t:" opt +do + case "$opt" in + t ) TAG="$OPTARG" ;; + ? ) help ;; # Print help + esac +done + +# Print help in case parameters are empty +if [ -z "$TAG" ] +then + printf "Tag is missing\n"; + help +fi + +# Validate semver +SEMVER_REGEX="^v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(\\-[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?(\\+[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?$" +if [[ "${TAG}" =~ ${SEMVER_REGEX} ]]; then + printf "${TAG} is valid semver tag.\n" +else + printf "${TAG} is not a valid semver tag.\n" + exit -1 +fi + +TAG_FOUND=`git tag --list ${TAG}` +if [ ${TAG_FOUND} = ${TAG} ] ; then + printf "Tag ${TAG} already exists\n" + exit -1 +fi + + +cd $(dirname $0) + +# Update go.mod +git checkout -b pre_release_${TAG} master +PACKAGE_DIRS=$(find . -mindepth 2 -type f -name 'go.mod' -exec dirname {} \; | egrep -v 'tools' | sed 's/^\.\///' | sort) + +for dir in $PACKAGE_DIRS; do + sed -i .bak "s/opentelemetry.io\/otel\([^ ]*\) v[0-9]*\.[0-9]*\.[0-9]/opentelemetry.io\/otel\1 ${TAG}/" ${dir}/go.mod + rm -f ${dir}/go.mod.bak +done + +# Run lint to update go.sum +make lint + +# Add changes and commit. +git add . +make ci +git commit -m "Prepare for releasing $TAG" + +printf "Now run following to verify the changes.\ngit diff master\n" +printf "\nThen push the changes to upstream\n" diff --git a/tag.sh b/tag.sh new file mode 100755 index 000000000..6235d8132 --- /dev/null +++ b/tag.sh @@ -0,0 +1,75 @@ +#!/bin/bash + +set -e + +help() +{ + printf "\n" + printf "Usage: $0 -t tag -c commit-hash\n" + printf "\t-t New tag that you would like to create\n" + printf "\t-c Commit hash to associate with the new tag\n" + exit 1 # Exit script after printing help +} + +while getopts "t:c:" opt +do + case "$opt" in + t ) TAG="$OPTARG" ;; + c ) COMMIT_HASH="$OPTARG" ;; + ? ) help ;; # Print help + esac +done + +# Print help in case parameters are empty +if [ -z "$TAG" ] || [ -z "${COMMIT_HASH}" ] +then + printf "Some or all of the parameters are missing\n"; + help +fi + +# Validate semver +SEMVER_REGEX="^v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(\\-[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?(\\+[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?$" + + +if [[ "${TAG}" =~ ${SEMVER_REGEX} ]]; then + printf "${TAG} is valid semver tag.\n" +else + printf "${TAG} is not a valid semver tag.\n" + exit -1 +fi + +cd $(dirname $0) + +# Check if the commit-hash is valid +COMMIT_FOUND=`git log -50 --pretty=format:"%H" | grep ${COMMIT_HASH}` +if [ "${COMMIT_FOUND}" != "${COMMIT_HASH}" ] ; then + printf "Commit ${COMMIT_HASH} not found\n" + exit -1 +fi + +# Check if the tag doesn't alread exists. +TAG_FOUND=`git tag --list ${TAG}` +if [ "${TAG_FOUND}" = "${TAG}" ] ; then + printf "Tag ${TAG} already exists\n" + exit -1 +fi + +# Save most recent tag for generating logs +TAG_CURRENT=`git tag | grep '^v' | tail -1` + +PACKAGE_DIRS=$(find . -mindepth 2 -type f -name 'go.mod' -exec dirname {} \; | egrep -v 'tools' | sed 's/^\.\///' | sort) + +# Create tag for root module +git tag -a "${TAG}" -m "Version ${TAG}" ${COMMIT_HASH} + +# Create tag for submodules +for dir in $PACKAGE_DIRS; do + git tag -a "${dir}/${TAG}" -m "Version ${dir}/${TAG}" ${COMMIT_HASH} +done + +# Generate commit logs +printf "New tag ${TAG} created.\n" +printf "\n\n\nChange log since previous tag ${TAG_CURRENT}\n" +printf "======================================\n" +git --no-pager log --pretty=oneline ${TAG_CURRENT}..${TAG} +