Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions scripts/release/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Release Script(s) Usage

## Versioning

This script needs:
- An existing `openvalidators/__init__.py` file
- An existing `__version__` variable in that file
- An existing version for that variable

This process will generate:
- A modified version in `__version__` for the update type specified

### Example Usage
`./scripts/release/versioning.sh -U patch -A`

Where:
* `-U` (major|minor|patch) the type of update
* `-A` is to apply the script changes


## Add Notes Changelog

This script needs:
- An existing `CHANGELOG.md` file with at least three lines
- An existing git tag for the previous version

This process will generate:
- A new entry in `CHANGELOG.md`

##### *Note: This will only list merge commits into the release branch since the last tag*

### Example Usage
`./scripts/release/add_notes_changelog.sh -P 1.1.7 -V 1.1.8 -B hotfix/serve-val-axon -T $GIT -A`

Where:
* `-P` is the old version
* `-V` is the new version
* `-B` is the release branch name (default: `release/vX.X.X`)
* `-T` is the GIT API token
* `-A` is to apply the script changes

## Release

This script needs:
- An existing `__version__` variable in the `openvalidators/__init__.py` file
- Version in the `__version__` variable is not a git tag already

This process will generate:
- Tag in Github repo: https://github.com/opentensor/validators/tags
- Release in Github: https://github.com/opentensor/validators/releases


### Example Usage
`./scripts/release/release.sh -T $GIT -A`

Where:
* `-T` is the GIT API token
* `-A` is to apply the script changes

106 changes: 106 additions & 0 deletions scripts/release/add_notes_changelog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/bin/bash

####
# Utils
####
source ${BASH_SOURCE%/*}/utils.sh
source ${BASH_SOURCE%/*}/github_utils.sh
###

# 1. Get options

## Defaults
APPLY="false"

while [[ $# -gt 0 ]]; do
case $1 in
-A|--apply)
APPLY="true"
shift # past argument
;;
-P|--previous-version-tag)
PREV_TAG_VERSION="$2"
shift # past argument
shift # past value
;;
-V|--version)
VERSION="$2"
shift # past argument
shift # past value
;;
-T|--github-token)
GITHUB_TOKEN="$2"
shift # past argument
shift # past value
;;
-B|--release-branch)
RELEASE_BRANCH="$2"
shift # past argument
shift # past value
;;
-*|--*)
echo "Unknown option $1"
exit 1
;;
*)
POSITIONAL_ARGS+=("$1") # save positional arg
shift # past argument
;;
esac
done

if [[ -z $GITHUB_TOKEN && $APPLY == "true" ]]; then
echo_error "Github token required (-T, --github-token)"
exit 1
fi

if [[ -z $PREV_TAG_VERSION ]]; then
echo_error "Previous version tag required (-P, --previous-version-tag)"
exit 1
fi

if [[ -z $VERSION ]]; then
echo_error "Version to release required (-V, --version)"
exit 1
fi

if [[ -z $RELEASE_BRANCH ]]; then
echo_warning "Release branch not specified with (-B, --release-branch) assuming: release/$VERSION"
RELEASE_BRANCH=release/$VERSION
fi

DATE=$(date +"%Y-%m-%d")
RELEASE_NAME="$VERSION / $DATE"
TAG_NAME=v$VERSION
PREV_TAG_NAME=v$PREV_TAG_VERSION

# 2.2. Generate release notes
if [[ $APPLY == "true" ]]; then
echo_info "Generating Github release notes"
RESPONSE=$(generate_github_release_notes_for_changelog $GITHUB_TOKEN)
DESCRIPTION=$(echo $RESPONSE | jq '.body' | tail -1 | sed "s/\"//g")

if [ $(echo $RESPONSE | jq '.body' | wc -l) -eq 1 ]; then
if [ $(echo $RESPONSE | jq '.' | grep 'documentation_url' | wc -l) -gt 0 ]; then
echo_error "Something went wrong generating Github release notes"
echo $RESPONSE | jq --slurp '.[0]'
exit 1
fi

if [ $(echo $RESPONSE | jq '.type' | grep 'error' | wc -l) -gt 0 ]; then
echo_error "Something went wrong generating Github release notes"
echo $RESPONSE | jq --slurp '.[1]'
exit 1
fi
fi
else
echo_warning "Dry run execution. Not generating Github release notes"
fi

if [[ $APPLY == "true" ]]; then
echo_info "Adding release notes to CHANGELOG.md"
sed -i "2 i\\\n## $RELEASE_NAME" CHANGELOG.md
sed -i "4 i\\\n$DESCRIPTION\n" CHANGELOG.md
else
echo_warning "Dry run execution. Not adding release notes to CHANGELOG.md"
fi
105 changes: 105 additions & 0 deletions scripts/release/github_release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/bin/bash

####
# Utils
####
source ${BASH_SOURCE%/*}/utils.sh
source ${BASH_SOURCE%/*}/github_utils.sh
###

# 1. Get options

## Defaults
APPLY="false"

while [[ $# -gt 0 ]]; do
case $1 in
-A|--apply)
APPLY="true"
shift # past argument
;;
-P|--previous-version-tag)
PREV_TAG_VERSION="$2"
shift # past argument
shift # past value
;;
-V|--version)
VERSION="$2"
shift # past argument
shift # past value
;;
-T|--github-token)
GITHUB_TOKEN="$2"
shift # past argument
shift # past value
;;
-*|--*)
echo "Unknown option $1"
exit 1
;;
*)
POSITIONAL_ARGS+=("$1") # save positional arg
shift # past argument
;;
esac
done

if [[ -z $GITHUB_TOKEN && apply == "true" ]]; then
echo_error "Github token required (-T, --github-token)"
exit 1
fi

if [[ -z $PREV_TAG_VERSION ]]; then
echo_error "Previous version tag required (-P, --previous-version-tag)"
exit 1
fi

if [[ -z $VERSION ]]; then
echo_error "Version to release required (-V, --version)"
exit 1
fi

# 2. Github
DATE=$(date +"%Y-%m-%d")
RELEASE_NAME="$VERSION / $DATE"
PREV_TAG_NAME=$PREV_TAG_VERSION
TAG_NAME=v$VERSION

# 2.1 Create Git tag for the repository
if [[ $APPLY == "true" ]]; then
echo_info "Tagging repository"
tag_repository $TAG_NAME
else
echo_warning "Dry run execution. Not tagging Github repo"
fi

# 2.2. Generate release notes
if [[ $APPLY == "true" ]]; then
echo_info "Generating Github release notes"
RESPONSE=$(generate_github_release_notes $GITHUB_TOKEN)
DESCRIPTION=$(echo $RESPONSE | jq '.body' | tail -1 | sed "s/\"//g")

if [ $(echo $RESPONSE | jq '.body' | wc -l) -eq 1 ]; then
if [ $(echo $RESPONSE | jq '.' | grep 'documentation_url' | wc -l) -gt 0 ]; then
echo_error "Something went wrong generating Github release notes"
echo $RESPONSE | jq --slurp '.[0]'
exit 1
fi

if [ $(echo $RESPONSE | jq '.type' | grep 'error' | wc -l) -gt 0 ]; then
echo_error "Something went wrong generating Github release notes"
echo $RESPONSE | jq --slurp '.[1]'
exit 1
fi
fi
else
echo_warning "Dry run execution. Not generating Github release notes"
fi

# 2.3 Create Github release
if [[ $APPLY == "true" ]]; then
echo_info "Generating Github release"
create_github_release $GITHUB_TOKEN
else
echo_warning "Dry run execution. Not creating Github release"
fi
Loading