From 784976625e1e58008363fddf9e79a54410e3034f Mon Sep 17 00:00:00 2001 From: Mahmoud Mazouz Date: Thu, 11 Apr 2024 11:26:43 +0200 Subject: [PATCH] feat: Add `version.txt` and infer version in `bump-and-tag.bash` --- CMakeLists.txt | 6 ++-- ci/scripts/bump-and-tag.bash | 68 +++++++++++++++++++----------------- docs/conf.py | 3 +- version.txt | 1 + 4 files changed, 40 insertions(+), 38 deletions(-) create mode 100644 version.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index e264ffb1d..6dd057a0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,10 @@ cmake_minimum_required(VERSION 3.16) -# NOTE(fuzzpixelz): The ci/scripts/bump-and-tag.bash script sets the project -# version using regular expressions on this statement. -set(ZENOHC_VERSION 0.11.0.0) +file(READ ${CMAKE_CURRENT_SOURCE_DIR}/version.txt version) project( zenohc - VERSION ${ZENOHC_VERSION} + VERSION ${version} DESCRIPTION "The C bindings for Zenoh" HOMEPAGE_URL "https://github.com/eclipse-zenoh/zenoh-c" LANGUAGES C diff --git a/ci/scripts/bump-and-tag.bash b/ci/scripts/bump-and-tag.bash index 3c3bae3cf..8caa3ce22 100644 --- a/ci/scripts/bump-and-tag.bash +++ b/ci/scripts/bump-and-tag.bash @@ -3,23 +3,23 @@ set -eo pipefail # Repository -readonly REPO +readonly repo=${REPO:?input REPO is required} # Release number -readonly VERSION +readonly version=${VERSION:-''} # Release branch -readonly BRANCH +readonly branch=${BRANCH:?input BRANCH is required} # Dependencies' pattern -readonly BUMP_DEPS_PATTERN +readonly bump_deps_pattern=${BUMP_DEPS_PATTERN:-''} # Dependencies' version -readonly BUMP_DEPS_VERSION +readonly bump_deps_version=${BUMP_DEPS_VERSION:-''} # Dependencies' git branch -readonly BUMP_DEPS_BRANCH +readonly bump_deps_branch=${BUMP_DEPS_BRANCH:-''} # GitHub token -readonly GH_TOKEN +readonly gh_token=${GH_TOKEN:?input GH_TOKEN is required} # Git actor name -readonly GIT_USER_NAME +readonly git_user_name=${GIT_USER_NAME:?input GIT_USER_NAME is required} # Git actor email -readonly GIT_USER_EMAIL +readonly git_user_email=${GIT_USER_EMAIL:?input GIT_USER_EMAIL is required} cargo +stable install toml-cli @@ -31,49 +31,51 @@ function toml_set_in_place() { mv "$tmp" "$1" } -export GIT_AUTHOR_NAME=$GIT_USER_NAME -export GIT_AUTHOR_EMAIL=$GIT_USER_EMAIL -export GIT_COMMITTER_NAME=$GIT_USER_NAME -export GIT_COMMITTER_EMAIL=$GIT_USER_EMAIL +export GIT_AUTHOR_NAME=$git_user_name +export GIT_AUTHOR_EMAIL=$git_user_email +export GIT_COMMITTER_NAME=$git_user_name +export GIT_COMMITTER_EMAIL=$git_user_email -git clone --recursive --single-branch --branch "$BRANCH" "https://github.com/$REPO" +git clone --recursive --single-branch --branch "$branch" "https://github.com/$repo" + +# If not version has been specified, infer it using git-describe +if [[ "$version" == '' ]]; then + printf '%s' "$(git describe)" > version.txt +fi # Bump CMake project version -sed -i "s;^set(ZENOHC_VERSION .*)$;set(ZENOHC_VERSION $VERSION);" CMakeLists.txt +echo "$version" > version.txt # Propagate version change to Cargo.toml and Cargo.toml.in cmake . -DZENOHC_BUILD_IN_SOURCE_TREE=TRUE -DCMAKE_BUILD_TYPE=Release -# Update Read the Docs version -sed -i "s;^release = .*$;release = '$VERSION';" docs/conf.py # Update Debian dependency of libzenohc-dev -toml_set_in_place Cargo.toml "package.metadata.deb.variants.libzenohc-dev.depends" "libzenohc (=$VERSION)" -toml_set_in_place Cargo.toml.in "package.metadata.deb.variants.libzenohc-dev.depends" "libzenohc (=$VERSION)" +toml_set_in_place Cargo.toml "package.metadata.deb.variants.libzenohc-dev.depends" "libzenohc (=$version)" +toml_set_in_place Cargo.toml.in "package.metadata.deb.variants.libzenohc-dev.depends" "libzenohc (=$version)" -git commit CMakeLists.txt Cargo.toml Cargo.toml.in Cargo.lock -m "chore: Bump version to $VERSION" +git commit version.txt Cargo.toml Cargo.toml.in Cargo.lock -m "chore: Bump version to $version" -# Select all package dependencies that match $BUMP_DEPS_PATTERN and bump them to $BUMP_DEPS_VERSION -deps=$(toml get Cargo.toml dependencies | jq -r "keys.[] | select(test(\"$BUMP_DEPS_PATTERN\"))") +# Select all package dependencies that match $bump_deps_pattern and bump them to $bump_deps_version +deps=$(toml get Cargo.toml dependencies | jq -r "keys.[] | select(test(\"$bump_deps_pattern\"))") for dep in $deps; do - if [[ -n $BUMP_DEPS_VERSION ]]; then - toml_set_in_place Cargo.toml "dependencies.$dep.version" "$BUMP_DEPS_VERSION" - toml_set_in_place Cargo.toml.in "dependencies.$dep.version" "$BUMP_DEPS_VERSION" + if [[ -n $bump_deps_version ]]; then + toml_set_in_place Cargo.toml "dependencies.$dep.version" "$bump_deps_version" + toml_set_in_place Cargo.toml.in "dependencies.$dep.version" "$bump_deps_version" fi - if [[ -n $BUMP_DEPS_BRANCH ]]; then - toml_set_in_place Cargo.toml "dependencies.$dep.branch" "$BUMP_DEPS_BRANCH" - toml_set_in_place Cargo.toml.in "dependencies.$dep.branch" "$BUMP_DEPS_BRANCH" + if [[ -n $bump_deps_branch ]]; then + toml_set_in_place Cargo.toml "dependencies.$dep.branch" "$bump_deps_branch" + toml_set_in_place Cargo.toml.in "dependencies.$dep.branch" "$bump_deps_branch" fi done # Update lockfile cargo check -if [[ -n $BUMP_DEPS_VERSION || -n $BUMP_DEPS_BRANCH ]]; then - git commit Cargo.toml Cargo.toml.in Cargo.lock -m "chore: Bump $BUMP_DEPS_PATTERN - version to $BUMP_DEPS_VERSION" +if [[ -n $bump_deps_version || -n $bump_deps_branch ]]; then + git commit Cargo.toml Cargo.toml.in Cargo.lock -m "chore: Bump $bump_deps_pattern version to $bump_deps_version" else echo "info: no changes have been made to any dependencies" fi -git tag "$VERSION" -m "v$VERSION" +git tag "$version" -m "v$version" git log -10 git show-ref --tags -git push "https://$GH_TOKEN@github.com/$REPO" "$BRANCH" "$VERSION" +git push "https://$gh_token@github.com/$repo" "$branch" "$version" diff --git a/docs/conf.py b/docs/conf.py index a9ab9a153..0ce6d7d44 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -19,7 +19,8 @@ project = 'zenoh-c' copyright = '2017, 2022 ZettaScale Technology' author = 'ZettaScale Zenoh team' -release = '0.11.0.0' +with open("../version.txt", "rt") as f: + release = f.read() # -- General configuration --------------------------------------------------- master_doc = 'index' diff --git a/version.txt b/version.txt new file mode 100644 index 000000000..6e5d683f0 --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +0.11.0.0 \ No newline at end of file