diff --git a/.github/workflows/docker_release.yml b/.github/workflows/docker_release.yml new file mode 100644 index 0000000000..dbb6c3bab8 --- /dev/null +++ b/.github/workflows/docker_release.yml @@ -0,0 +1,51 @@ +name: Build and Push Docker Image +# https://github.com/sigstore/cosign +on: + workflow_dispatch: + inputs: + tag: + description: 'Docker image tag' + required: true + default: 'latest' + +jobs: + build-and-push: + runs-on: ubuntu-latest + + permissions: + contents: read + id-token: write + + steps: + - name: Check out code + uses: actions/checkout@v3 + + - name: Install cosign + uses: sigstore/cosign-installer@v3 + + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + registry: docker.io + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: . + push: true + tags: | + opentensorfdn/bittensor:${{ github.event.inputs.tag }} + opentensorfdn/bittensor:latest + provenance: false + + - name: Sign the images with GitHub OIDC Token + env: + DIGEST: ${{ steps.build.outputs.digest }} + TAGS: ${{ steps.build.outputs.tags }} + run: | + echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST} \ No newline at end of file diff --git a/scripts/release/add_notes_changelog.sh b/scripts/release/add_notes_changelog.sh deleted file mode 100755 index d0f7594f55..0000000000 --- a/scripts/release/add_notes_changelog.sh +++ /dev/null @@ -1,106 +0,0 @@ -#!/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 \ No newline at end of file diff --git a/scripts/release/github_release.sh b/scripts/release/github_release.sh deleted file mode 100755 index 08a551e54a..0000000000 --- a/scripts/release/github_release.sh +++ /dev/null @@ -1,105 +0,0 @@ -#!/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 \ No newline at end of file diff --git a/scripts/release/github_utils.sh b/scripts/release/github_utils.sh deleted file mode 100644 index e10cb96166..0000000000 --- a/scripts/release/github_utils.sh +++ /dev/null @@ -1,169 +0,0 @@ -#!/bin/bash - -#### -# Utils -#### -source ${BASH_SOURCE%/*}/utils.sh - -# -# Params: -# - First positional argument: version of the tag -# -function tag_repository() -{ - VERSION=$1 - - if [[ -z $VERSION ]]; then - echo_error "tag_repository needs VERSION" - exit 1 - fi - - git tag -a $VERSION -m "Release $VERSION" - git push origin --tags -} - -# -# Params: -# - First positional argument: version of the tag -# -function remove_tag() -{ - VERSION=$1 - - if [[ -z $VERSION ]]; then - echo_error "remove_tag needs VERSION" - exit 1 - fi - - git tag -d $VERSION - git push --delete origin $VERSION -} - -# -# Needs: -# - TAG_NAME -# - PREV_TAG_NAME -# - RELEASE_NAME -# -function generate_github_release_notes_post_data() -{ - cat < /dev/null -} \ No newline at end of file diff --git a/scripts/release/release.sh b/scripts/release/release.sh deleted file mode 100755 index 4c4c7288ef..0000000000 --- a/scripts/release/release.sh +++ /dev/null @@ -1,153 +0,0 @@ -#!/bin/bash - -# -# In this script you are going to find the process of releasing bittensor. -# -# This script needs: -# - An existing VERSION file -# - Version in VERSION file is not a git tag already -# -# This process will generate: -# - Tag in Github repo: https://github.com/opentensor/bittensor/tags -# - Release in Github: https://github.com/opentensor/bittensor/releases -# - New entry in CHANGELOG.md file -# - Python wheel in pypi: https://pypi.org/project/bittensor/ -# - Docker image in dockerhub: https://hub.docker.com/r/opentensorfdn/bittensor/tags (TODO) -# - -### -# Utils -### - -source ${BASH_SOURCE%/*}/utils.sh - -function help(){ - echo Usage: - echo \ \ $0 - echo - echo This script release a bittensor version. - echo - echo This script needs: - echo \ \ - An existing VERSION file - echo \ \ - Version in VERSION file is not a git tag already - echo -} -### - -### -# Start of release process -### - -# 0. Check requirements -# Expected state for the execution environment -# - VERSION file exists -# - __version__ exists inside file 'bittensor/__init__.py' -# - Both versions have the expected format and are the same - -VERSION_FILENAME='VERSION' -CODE_WITH_VERSION='bittensor/__init__.py' - -if [[ ! -f $VERSION_FILENAME ]]; then - echo_error "Requirement failure: $VERSION_FILENAME does not exist" - help - exit 1 -fi - -CODE_VERSION=`grep '__version__\ \=\ ' $CODE_WITH_VERSION | awk '{print $3}' | sed 's/"//g'` -VERSION=$(cat $VERSION_FILENAME) - -if ! [[ "$CODE_VERSION" =~ ^[0-9]+.[0-9]+.[0-9]+$ ]];then - echo_error "Requirement failure: Version in code '$CODE_VERSION' with wrong format" - exit 1 -fi - -if ! [[ "$VERSION" =~ ^[0-9]+.[0-9]+.[0-9]+$ ]];then - echo_error "Requirement failure: Version in file '$VERSION' with wrong format" - exit 1 -fi - -if [[ $CODE_VERSION != $VERSION ]]; then - echo_error "Requirement failure: version in code ($CODE_VERSION) and version in file ($VERSION) are not the same. You should fix that before release code." - help - exit 1 -fi - -# 1. Get options - -## Defaults -APPLY="false" -APPLY_ACTION="" - -while [[ $# -gt 0 ]]; do - case $1 in - -h|--help) - help - exit 0 - ;; - -A|--apply) - APPLY="true" - APPLY_ACTION="--apply" - shift # past argument - ;; - -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 [[ $APPLY == "true" ]]; then - echo_warning "Not a Dry run exection" -else - echo_warning "Dry run execution" -fi - -if [[ -z $GITHUB_TOKEN && $APPLY == "true" ]]; then - echo_error "Github token required (-T, --github-token)" - exit 1 -fi - -# 2. Checking version - -CURRENT_VERSION_EXISTS=$(git tag | grep $VERSION) -if [[ ! -z $CURRENT_VERSION_EXISTS ]]; then - echo_error "Current version '$VERSION' already exists" - help - exit 1 -fi - -VERSION=$(cat $VERSION_FILENAME) -PREV_VERSION_TAG=`get_git_tag_higher_version` - -TAG_NAME=v$VERSION - -## 2.1. Current VERSION is not already a tag - -echo_info "Detected new version tag: $VERSION" -echo_info "Previous version tag: $PREV_VERSION_TAG" -echo_info "Tag generated: $TAG_NAME" - -# 3. Create Github resources -if [[ $APPLY == "true" ]]; then - ${BASH_SOURCE%/*}/github_release.sh $APPLY_ACTION --github-token $GITHUB_TOKEN -P $PREV_VERSION_TAG -V $VERSION -else - ${BASH_SOURCE%/*}/github_release.sh $APPLY_ACTION $GITHUB_TOKEN -P $PREV_VERSION_TAG -V $VERSION -fi - -# 4. Generate python wheel and upload it to Pypi -echo_info "Releasing pip package" -${BASH_SOURCE%/*}/release_pip.sh $APPLY_ACTION - -# 5. Creating docker image and upload -echo_info "Releasing docker image" -${BASH_SOURCE%/*}/release_docker.sh $APPLY_ACTION --version $VERSION - diff --git a/scripts/release/release_docker.sh b/scripts/release/release_docker.sh deleted file mode 100755 index aef17504c0..0000000000 --- a/scripts/release/release_docker.sh +++ /dev/null @@ -1,66 +0,0 @@ -#!/bin/bash - -#### -# Utils -#### -source ${BASH_SOURCE%/*}/utils.sh -### - -# 1. Get options - -## Defaults -APPLY="false" - -while [[ $# -gt 0 ]]; do - case $1 in - -A|--apply) - APPLY="true" - shift # past argument - ;; - -V|--version) - VERSION="$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 $VERSION ]]; then - echo_error "Version to release required (-V, --version)" - exit 1 -fi - -DOCKER_IMAGE_NAME="opentensorfdn/bittensor:$VERSION" - -# 2. Login -if [[ $APPLY == "true" ]]; then - echo_info "Docker registry login" - sudo docker login -else - echo_warning "Dry run execution. Not login into docker registry" -fi - -# 3. Creating docker image -if [[ $APPLY == "true" ]]; then - echo_info "Building docker image" -else - echo_warning "Dry run execution. Building docker image '$DOCKER_IMAGE_NAME' but not pushing it" -fi - -sudo docker build -t $DOCKER_IMAGE_NAME . - -# 4. Uploading docker image -if [[ $APPLY == "true" ]]; then - echo_info "Pushing docker image" - sudo docker push $DOCKER_IMAGE_NAME -else - echo_warning "Dry run execution. Not pushing docker image '$DOCKER_IMAGE_NAME'" -fi diff --git a/scripts/release/release_pip.sh b/scripts/release/release_pip.sh deleted file mode 100755 index 887b8f47cf..0000000000 --- a/scripts/release/release_pip.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash - -#### -# Utils -#### -source ${BASH_SOURCE%/*}/utils.sh -### - -# 1. Get options - -## Defaults -APPLY="false" - -while [[ $# -gt 0 ]]; do - case $1 in - -A|--apply) - APPLY="true" - shift # past argument - ;; - -*|--*) - echo "Unknown option $1" - exit 1 - ;; - *) - POSITIONAL_ARGS+=("$1") # save positional arg - shift # past argument - ;; - esac -done - -# 2. Cleaning up -echo_info "Removing dirs: dist/ and build/" -rm -rf dist/ -rm -rf build/ - -# 3. Creating python wheel -echo_info "Generating python wheel" -python3 setup.py sdist bdist_wheel - -# 3. Upload wheel to pypi -if [[ $APPLY == "true" ]]; then - echo_info "Uploading python wheel" - python3 -m twine upload --repository bittensor dist/* -else - echo_warning "Dry run execution. Not uploading python wheel" -fi diff --git a/scripts/release/utils.sh b/scripts/release/utils.sh deleted file mode 100755 index 91ba2f442f..0000000000 --- a/scripts/release/utils.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[0;33m' -NC='\033[0m' # No Color - -function echo_error { - echo -e "${RED}[ERROR]${NC} $1" -} - -function echo_warning { - echo -e "${YELLOW}[WARNING]${NC} $1" -} - -function echo_info { - echo -e "${GREEN}[INFO]${NC} $1" -} - -function echo_json { - echo "{\"type\":\"$1\",\"message\":\"$2\"}" -} - -function get_git_tag_higher_version { - echo `git tag -l --sort -version:refname | head -n 1` -} \ No newline at end of file diff --git a/scripts/release/versioning.sh b/scripts/release/versioning.sh deleted file mode 100755 index 0c3ed9ab3d..0000000000 --- a/scripts/release/versioning.sh +++ /dev/null @@ -1,95 +0,0 @@ -#!/bin/bash - -#### -# Utils -#### -source ${BASH_SOURCE%/*}/utils.sh -### - -# 1. Get options - -## Defaults -APPLY="false" - -while [[ $# -gt 0 ]]; do - case $1 in - -A|--apply) - APPLY="true" - shift # past argument - ;; - -U|--update) - VERSION_TYPE="$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 [[ $VERSION_TYPE != "major" && $VERSION_TYPE != "minor" && $VERSION_TYPE != "patch" && $VERSION_TYPE != "rc" ]]; then - echo_error "Incorrect version type (-U|--update). Version types accepted: {major, minor, patch}" - exit 1 -fi - -VERSION=$(cat VERSION) -CODE_WITH_VERSION='bittensor/__init__.py' - -MAJOR=$(awk -F. '{print $1}' <<< $VERSION) -MINOR=$(awk -F. '{print $2}' <<< $VERSION) -PATCH=$(awk -F. '{print $3}' <<< $VERSION) - -# RC version -RC=$(awk -F- '{print $NF}' <<< $version) -if [ -z $RC ]; then - CURRENT_VERSION="$MAJOR.$MINOR.$PATCH" -else - CURRENT_VERSION="$MAJOR.$MINOR.$PATCH-$RC" -fi - -case $VERSION_TYPE in - "major") - echo_info "Applying a $VERSION_TYPE update" - NEW_VERSION="$((MAJOR + 1)).0.0" - ;; - "minor") - echo_info "Applying a $VERSION_TYPE update" - NEW_VERSION="$MAJOR.$((MINOR + 1)).0" - ;; - "patch") - echo_info "Applying a $VERSION_TYPE update" - NEW_VERSION="$MAJOR.$MINOR.$((PATCH + 1))" - ;; - "rc") - SUFFIX=$2 - if [ -z $SUFFIX ]; then - echo_error "Suffix is needed when updating version to a RC" - exit 1 - fi - NEW_VERSION="$MAJOR.$MINOR.$PATCH-$SUFFIX" - ;; - *) - echo_error "This operation is not allowed. Try one of the following: {major, minor, patch, rc}" - exit 1 - ;; -esac - - -echo_info "Current version: $CURRENT_VERSION" -echo_info "New version: $NEW_VERSION" - -if [[ $APPLY == "true" ]]; then - echo_info "Updating version in code: sed -i "18,30s/$VERSION/$NEW_VERSION/g" $CODE_WITH_VERSION" - sed -i "18,30s/$VERSION/$NEW_VERSION/g" $CODE_WITH_VERSION - echo_info "Updating version in file: echo -n $NEW_VERSION > VERSION" - echo -n $NEW_VERSION > VERSION -else - echo_warning "Dry run execution. Version update not applied" - echo_info "Use -A or --apply to apply changes" -fi \ No newline at end of file