From 7823c22a4c2c166a5dbfb2dfbcb202d513047476 Mon Sep 17 00:00:00 2001 From: Mahmoud Mazouz Date: Wed, 17 Apr 2024 12:58:52 +0200 Subject: [PATCH] fix: Bump version in pyproject.toml --- .github/workflows/release.yml | 39 +++++++++++++++------ ci/scripts/bump-and-tag.bash | 66 +++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 10 deletions(-) create mode 100644 ci/scripts/bump-and-tag.bash diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 165c1115..eec1c03d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -20,16 +20,35 @@ on: jobs: tag: - name: Bump and tag crates - uses: eclipse-zenoh/ci/.github/workflows/branch-bump-tag-crates.yml@main - with: - repo: ${{ github.repository }} - live-run: ${{ inputs.live-run || false }} - version: ${{ inputs.version }} - bump-deps-version: ${{ inputs.zenoh-version }} - bump-deps-pattern: ${{ inputs.zenoh-version && 'zenoh.*' || '^$' }} - bump-deps-branch: ${{ inputs.zenoh-version && format('release/{0}', inputs.zenoh-version) || '' }} - secrets: inherit + name: Branch, Bump & tag + runs-on: ubuntu-latest + outputs: + version: ${{ steps.create-release-branch.outputs.version }} + branch: ${{ steps.create-release-branch.outputs.branch }} + steps: + - id: create-release-branch + uses: eclipse-zenoh/ci/create-release-branch@main + with: + repo: ${{ github.repository }} + live-run: ${{ inputs.live-run || false }} + version: ${{ inputs.version }} + github-token: ${{ secrets.BOT_TOKEN_WORKFLOW }} + + - name: Checkout this repository + uses: actions/checkout@v4 + with: + ref: ${{ steps.create-release-branch.outputs.branch }} + token: ${{ secrets.BOT_TOKEN_WORKFLOW }} + + - name: Bump and tag project + run: bash ci/scripts/bump-and-tag.bash + env: + VERSION: ${{ steps.create-release-branch.outputs.version }} + BUMP_DEPS_VERSION: ${{ inputs.zenoh-version }} + BUMP_DEPS_PATTERN: ${{ inputs.zenoh-version && 'zenoh.*' || '' }} + BUMP_DEPS_BRANCH: ${{ inputs.zenoh-version && format('release/{0}', inputs.zenoh-version) || '' }} + GIT_USER_NAME: eclipse-zenoh-bot + GIT_USER_EMAIL: eclipse-zenoh-bot@users.noreply.github.com build-macos: needs: tag diff --git a/ci/scripts/bump-and-tag.bash b/ci/scripts/bump-and-tag.bash new file mode 100644 index 00000000..301eaf17 --- /dev/null +++ b/ci/scripts/bump-and-tag.bash @@ -0,0 +1,66 @@ +#!/usr/bin/env bash + +set -xeo pipefail + +# Release number +readonly version=${VERSION:?input VERSION is required} +# Dependencies' pattern +readonly bump_deps_pattern=${BUMP_DEPS_PATTERN:-''} +# Dependencies' version +readonly bump_deps_version=${BUMP_DEPS_VERSION:-''} +# Dependencies' git branch +readonly bump_deps_branch=${BUMP_DEPS_BRANCH:-''} +# Git actor name +readonly git_user_name=${GIT_USER_NAME:?input GIT_USER_NAME is required} +# Git actor email +readonly git_user_email=${GIT_USER_EMAIL:?input GIT_USER_EMAIL is required} + +cargo +stable install toml-cli + +# NOTE(fuzzypixelz): toml-cli doesn't yet support in-place modification +# See: https://github.com/gnprice/toml-cli?tab=readme-ov-file#writing-ish-toml-set +function toml_set_in_place() { + local tmp=$(mktemp) + toml set "$1" "$2" "$3" > "$tmp" + 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 + +# Bump Cargo version +toml_set_in_place Cargo.toml "package.version" "$version" +# Propagate version change to pyproject.toml +toml_set_in_place pyproject.toml "project.version" "$version" + +git commit version.txt Cargo.toml pyproject.toml -m "chore: Bump version to $version" + +# Select all package dependencies that match $bump_deps_pattern and bump them to $bump_deps_version +if [[ "$bump_deps_pattern" != '' ]]; then + 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" + fi + + if [[ -n $bump_deps_branch ]]; then + toml_set_in_place Cargo.toml "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.lock -m "chore: Bump $bump_deps_pattern version to $bump_deps_version" + else + echo "warn: no changes have been made to any dependencies matching $bump_deps_pattern" + fi +fi + +git tag --force "$version" -m "v$version" +git log -10 +git show-ref --tags +git push origin +git push --force origin "$version"