1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-04-15 11:36:44 +02:00

Backport tag script from contrib repo (#934)

Also, update the releasing docs to match new command and clean up new
structure.
This commit is contained in:
Tyler Yahn 2020-07-13 13:09:59 -07:00 committed by GitHub
parent aff7a80d5a
commit 9edcad3829
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 168 additions and 64 deletions

View File

@ -7,33 +7,48 @@ on the master branch instead or released version. But they shouldn't be
depending on the master. So it is not a concern. depending on the master. So it is not a concern.
1. Run the pre-release script. It creates a branch pre_release_<tag> to make the changes. 1. Run the pre-release script. It creates a branch pre_release_<tag> 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 <new tag> ./pre_release.sh -t <new tag>
```
2. Verify the changes.
```
git diff master git diff master
```
3. Push the changes to upstream.
```
git push git push
``` ```
4. Create a PR on github and merge the PR once approved.
## Tag ## Tag
Now create a new Tag on the commit hash of the changes made in pre-release step. 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. Use the same tag as used in the pre-release step.
1. Run the tag.sh script. 1. Run the tag.sh script.
```
./tag.sh <new tag> <commit-hash>
```
2. Push tags upstream. Make sure you run this for all sub-modules as well. 2. Push tags upstream. Make sure you run this for all sub-modules as well.
``` ```
./tag.sh -t <new tag> -c <commit-hash>
git push upstream <new tag> git push upstream <new tag>
git push upstream <submodules-path/new tag> git push upstream <submodules-path/new tag>
...
``` ```
## Release ## Release
Now create a release for the new tag on github. tag.sh script generates commit logs since Now create a release for the new `<new tag>` on github.
last release. Use that to draft the new release. The release body should include all the release notes in the Changelog for this release.
Additionally, the `tag.sh` script generates commit logs since last release which can be used to suppliment the release notes.
## Verify Examples ## Verify Examples
After releasing run following script to verify that examples build outside of the otel repo. After releasing run following script to verify that examples build outside of the otel repo.

205
tag.sh
View File

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
# Copyright The OpenTelemetry Authors # Copyright The OpenTelemetry Authors
# #
@ -14,76 +14,165 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
set -e readonly PROGNAME=$(basename "$0")
readonly PROGDIR=$(readlink -m "$(dirname "$0")")
help() readonly EXCLUDE_PACKAGES="tools"
{ readonly 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-]+)*)?"
printf "\n"
printf "Usage: $0 -t tag -c commit-hash\n" usage() {
printf "\t-t New tag that you would like to create\n" cat <<- EOF
printf "\t-c Commit hash to associate with the new tag\n" Usage: $PROGNAME [OPTIONS] SEMVER_TAG COMMIT_HASH
exit 1 # Exit script after printing help
Creates git tag for all Go packages in project.
OPTIONS:
-h --help Show this help.
ARGUMENTS:
SEMVER_TAG Semantic version to tag with.
COMMIT_HASH Git commit hash to tag.
EOF
} }
while getopts "t:c:" opt cmdline() {
do local arg commit
case "$opt" in
t ) TAG="$OPTARG" ;;
c ) COMMIT_HASH="$OPTARG" ;;
? ) help ;; # Print help
esac
done
# Print help in case parameters are empty for arg
if [ -z "$TAG" ] || [ -z "${COMMIT_HASH}" ] do
then local delim=""
printf "Some or all of the parameters are missing\n"; case "$arg" in
help # Translate long form options to short form.
fi --help) args="${args}-h ";;
# Pass through for everything else.
*) [[ "${arg:0:1}" == "-" ]] || delim="\""
args="${args}${delim}${arg}${delim} ";;
esac
done
# Validate semver # Reset and process short form options.
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-]+)*)?$" eval set -- "$args"
while getopts "h" OPTION
do
case $OPTION in
h)
usage
exit 0
;;
*)
echo "unknown option: $OPTION"
usage
exit 1
;;
esac
done
if [[ "${TAG}" =~ ${SEMVER_REGEX} ]]; then # Positional arguments.
printf "${TAG} is valid semver tag.\n" shift $((OPTIND-1))
else readonly TAG="$1"
printf "${TAG} is not a valid semver tag.\n" if [ -z "$TAG" ]
exit -1 then
fi echo "missing SEMVER_TAG"
usage
exit 1
fi
if [[ ! "$TAG" =~ $SEMVER_REGEX ]]
then
printf "invalid semantic version: %s\n" "$TAG"
exit 2
fi
if [[ "$( git tag --list "$TAG" )" ]]
then
printf "tag already exists: %s\n" "$TAG"
exit 2
fi
cd $(dirname $0) shift
commit="$1"
if [ -z "$commit" ]
then
echo "missing COMMIT_HASH"
usage
exit 1
fi
# Verify rev is for a commit and unify hashes into a complete SHA1.
readonly SHA="$( git rev-parse --quiet --verify "${commit}^{commit}" )"
if [ -z "$SHA" ]
then
printf "invalid commit hash: %s\n" "$commit"
exit 2
fi
if [ "$( git merge-base "$SHA" HEAD )" != "$SHA" ]
then
printf "commit '%s' not found on this branch\n" "$commit"
exit 2
fi
}
# Check if the commit-hash is valid package_dirs() {
COMMIT_FOUND=`git log -50 --pretty=format:"%H" | grep ${COMMIT_HASH}` # Return a list of package directories in the form:
if [ "${COMMIT_FOUND}" != "${COMMIT_HASH}" ] ; then #
printf "Commit ${COMMIT_HASH} not found\n" # package/directory/a
exit -1 # package/directory/b
fi # deeper/package/directory/a
# ...
#
# Making sure to exclude any packages in the EXCLUDE_PACKAGES regexp.
find . -mindepth 2 -type f -name 'go.mod' -exec dirname {} \; \
| grep -E -v "$EXCLUDE_PACKAGES" \
| sed 's/^\.\///' \
| sort
}
# Check if the tag doesn't alread exists. git_tag() {
TAG_FOUND=`git tag --list ${TAG}` local tag="$1"
if [ "${TAG_FOUND}" = "${TAG}" ] ; then local commit="$2"
printf "Tag ${TAG} already exists\n"
exit -1
fi
# Save most recent tag for generating logs git tag -a "$tag" -s -m "Version $tag" "$commit"
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) previous_version() {
local current="$1"
# Create tag for root module # Requires git > 2.0
git tag -a "${TAG}" -s -m "Version ${TAG}" ${COMMIT_HASH} git tag -l --sort=v:refname \
| grep -E "^${SEMVER_REGEX}$" \
| grep -v "$current" \
| tail -1
}
# Create tag for submodules print_changes() {
for dir in $PACKAGE_DIRS; do local tag="$1"
git tag -a "${dir}/${TAG}" -s -m "Version ${dir}/${TAG}" ${COMMIT_HASH} local previous
done
# Generate commit logs previous="$( previous_version "$tag" )"
printf "New tag ${TAG} created.\n" if [ -n "$previous" ]
printf "\n\n\nChange log since previous tag ${TAG_CURRENT}\n" then
printf "======================================\n" printf "\nRaw changes made between %s and %s\n" "$previous" "$tag"
git --no-pager log --pretty=oneline ${TAG_CURRENT}..${TAG} printf "======================================\n"
git --no-pager log --pretty=oneline "${previous}..$tag"
fi
}
main() {
local dir
cmdline "$@"
cd "$PROGDIR" || exit 3
# Create tag for root package.
git_tag "$TAG" "$SHA"
printf "created tag: %s\n" "$TAG"
# Create tag for all sub-packages.
for dir in $( package_dirs )
do
git_tag "${dir}/$TAG" "$SHA"
printf "created tag: %s\n" "${dir}/$TAG"
done
print_changes "$TAG"
}
main "$@"