From c72215375bef4869fc61b1a94c419cc7db76dff1 Mon Sep 17 00:00:00 2001
From: Christoph Otter <chris@confio.gmbh>
Date: Wed, 8 May 2024 15:12:52 +0200
Subject: [PATCH 1/2] Set the crate version centrally via the workspace

---
 Cargo.toml                        | 4 ++++
 packages/check/Cargo.toml         | 2 +-
 packages/crypto/Cargo.toml        | 2 +-
 packages/derive/Cargo.toml        | 2 +-
 packages/schema-derive/Cargo.toml | 2 +-
 packages/schema/Cargo.toml        | 2 +-
 packages/std/Cargo.toml           | 2 +-
 packages/storage/Cargo.toml       | 2 +-
 packages/vm/Cargo.toml            | 2 +-
 9 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml
index 311069d0cf..fc6fc02e85 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -5,3 +5,7 @@ exclude = ["contracts"]
 # Resolver has to be set explicitely in workspaces
 # due to https://github.com/rust-lang/cargo/issues/9956
 resolver = "2"
+
+[workspace.package]
+version = "1.5.4"
+
diff --git a/packages/check/Cargo.toml b/packages/check/Cargo.toml
index 647a4c021b..c06376bbd2 100644
--- a/packages/check/Cargo.toml
+++ b/packages/check/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "cosmwasm-check"
-version = "1.5.4"
+version.workspace = true
 authors = ["Mauro Lacy <mauro@lacy.com.es>"]
 edition = "2021"
 description = "A CLI tool for verifying CosmWasm smart contracts"
diff --git a/packages/crypto/Cargo.toml b/packages/crypto/Cargo.toml
index da62f0c99b..fc86945f36 100644
--- a/packages/crypto/Cargo.toml
+++ b/packages/crypto/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "cosmwasm-crypto"
-version = "1.5.4"
+version.workspace = true
 authors = ["Mauro Lacy <maurolacy@users.noreply.github.com>"]
 edition = "2021"
 description = "Crypto bindings for cosmwasm contracts"
diff --git a/packages/derive/Cargo.toml b/packages/derive/Cargo.toml
index 7e87c2d5fb..f0722ec99c 100644
--- a/packages/derive/Cargo.toml
+++ b/packages/derive/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "cosmwasm-derive"
-version = "1.5.4"
+version.workspace = true
 authors = ["Simon Warta <webmaster128@users.noreply.github.com>"]
 edition = "2021"
 description = "A package for auto-generated code used for CosmWasm contract development. This is shipped as part of cosmwasm-std. Do not use directly."
diff --git a/packages/schema-derive/Cargo.toml b/packages/schema-derive/Cargo.toml
index 707c655ee5..97bc6e8a0b 100644
--- a/packages/schema-derive/Cargo.toml
+++ b/packages/schema-derive/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "cosmwasm-schema-derive"
-version = "1.5.4"
+version.workspace = true
 authors = ["Tomasz Kurcz <tom@confio.gmbh>"]
 edition = "2021"
 description = "Derive macros for cosmwasm-schema"
diff --git a/packages/schema/Cargo.toml b/packages/schema/Cargo.toml
index 20fcbc0416..cfefcd0cd1 100644
--- a/packages/schema/Cargo.toml
+++ b/packages/schema/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "cosmwasm-schema"
-version = "1.5.4"
+version.workspace = true
 authors = ["Simon Warta <webmaster128@users.noreply.github.com>", "Ethan Frey <ethanfrey@users.noreply.github.com>"]
 edition = "2021"
 description = "A dev-dependency for CosmWasm contracts to generate JSON Schema files."
diff --git a/packages/std/Cargo.toml b/packages/std/Cargo.toml
index 1a0b33d4af..ff2745b338 100644
--- a/packages/std/Cargo.toml
+++ b/packages/std/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "cosmwasm-std"
-version = "1.5.4"
+version.workspace = true
 authors = ["Ethan Frey <ethanfrey@users.noreply.github.com>"]
 edition = "2021"
 description = "Standard library for Wasm based smart contracts on Cosmos blockchains"
diff --git a/packages/storage/Cargo.toml b/packages/storage/Cargo.toml
index 08f405426b..c8c2ecd124 100644
--- a/packages/storage/Cargo.toml
+++ b/packages/storage/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "cosmwasm-storage"
-version = "1.5.4"
+version.workspace = true
 authors = ["Ethan Frey <ethanfrey@users.noreply.github.com>"]
 edition = "2021"
 description = "CosmWasm library with useful helpers for Storage patterns"
diff --git a/packages/vm/Cargo.toml b/packages/vm/Cargo.toml
index 908711344a..190e1b087d 100644
--- a/packages/vm/Cargo.toml
+++ b/packages/vm/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "cosmwasm-vm"
-version = "1.5.4"
+version.workspace = true
 authors = ["Ethan Frey <ethanfrey@users.noreply.github.com>"]
 edition = "2021"
 description = "VM bindings to run cosmwams contracts"

From a8f660dd21eeecbfe464070b7b802b3d466681e5 Mon Sep 17 00:00:00 2001
From: Christoph Otter <chris@confio.gmbh>
Date: Wed, 8 May 2024 15:13:02 +0200
Subject: [PATCH 2/2] Setup cargo-release

---
 CHANGELOG.md               |  4 +++
 Cargo.toml                 |  4 +++
 devtools/release_checks.sh | 11 +++++++
 devtools/set_version.sh    | 61 --------------------------------------
 packages/vm/Cargo.toml     | 12 ++++++++
 5 files changed, 31 insertions(+), 61 deletions(-)
 create mode 100755 devtools/release_checks.sh
 delete mode 100755 devtools/set_version.sh

diff --git a/CHANGELOG.md b/CHANGELOG.md
index f99cfdbf4e..f7c1451f5e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
 and this project adheres to
 [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 
+<!-- next-header -->
+
 ## [Unreleased]
 
 ## [1.5.4]
@@ -657,6 +659,8 @@ and this project adheres to
 The CHANGELOG for versions before 1.0.0 was moved to
 [CHANGELOG-pre1.0.0.md](./CHANGELOG-pre1.0.0.md).
 
+<!-- next-url -->
+
 [unreleased]: https://github.com/CosmWasm/cosmwasm/compare/v1.5.4...HEAD
 [1.5.4]: https://github.com/CosmWasm/cosmwasm/compare/v1.5.3...v1.5.4
 [1.5.3]: https://github.com/CosmWasm/cosmwasm/compare/v1.5.2...v1.5.3
diff --git a/Cargo.toml b/Cargo.toml
index fc6fc02e85..6ea867096c 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -9,3 +9,7 @@ resolver = "2"
 [workspace.package]
 version = "1.5.4"
 
+[workspace.metadata.release]
+shared-version = true
+tag-message = "chore: Release cosmwasm v{{version}}"
+tag-name = "v{{version}}"
diff --git a/devtools/release_checks.sh b/devtools/release_checks.sh
new file mode 100755
index 0000000000..3a53e932f8
--- /dev/null
+++ b/devtools/release_checks.sh
@@ -0,0 +1,11 @@
+#!/usr/bin/env bash
+
+# Move to the workspace root
+WORKSPACE_PATH=$(dirname $(cargo locate-project --workspace --message-format=plain))
+cd $WORKSPACE_PATH
+
+cargo build
+
+for contract_dir in contracts/*/; do
+  (cd "$contract_dir" && cargo build)
+done
diff --git a/devtools/set_version.sh b/devtools/set_version.sh
deleted file mode 100755
index 5dd6bc9034..0000000000
--- a/devtools/set_version.sh
+++ /dev/null
@@ -1,61 +0,0 @@
-#!/bin/bash
-set -o errexit -o nounset -o pipefail
-command -v shellcheck >/dev/null && shellcheck "$0"
-
-gnused="$(command -v gsed || echo sed)"
-
-function print_usage() {
-  echo "Usage: $0 NEW_VERSION"
-  echo ""
-  echo "e.g. $0 0.8.0"
-}
-
-if [ "$#" -ne 1 ]; then
-  print_usage
-  exit 1
-fi
-
-# Check repo
-SCRIPT_DIR="$(realpath "$(dirname "$0")")"
-if [[ "$(realpath "$SCRIPT_DIR/..")" != "$(pwd)" ]]; then
-  echo "Script must be called from the repo root"
-  exit 2
-fi
-
-# Ensure repo is not dirty
-CHANGES_IN_REPO=$(git status --porcelain)
-if [[ -n "$CHANGES_IN_REPO" ]]; then
-  echo "Repository is dirty. Showing 'git status' and 'git --no-pager diff' for debugging now:"
-  git status && git --no-pager diff
-  exit 3
-fi
-
-NEW="$1"
-OLD=$("$gnused" -n -e 's/^version[[:space:]]*=[[:space:]]*"\(.*\)"/\1/p' packages/std/Cargo.toml)
-echo "Updating old version $OLD to new version $NEW ..."
-
-FILES_MODIFIED=()
-
-for package_dir in packages/*/; do
-  CARGO_TOML="$package_dir/Cargo.toml"
-  # The `version = "1.0.0"` cases
-  "$gnused" -i -e "s/version[[:space:]]*=[[:space:]]*\"$OLD\"/version = \"$NEW\"/" "$CARGO_TOML"
-  # The `version = "=1.0.0"` cases
-  "$gnused" -i -e "s/version[[:space:]]*=[[:space:]]*\"=$OLD\"/version = \"=$NEW\"/" "$CARGO_TOML"
-  FILES_MODIFIED+=("$CARGO_TOML")
-done
-
-cargo build
-FILES_MODIFIED+=("Cargo.lock")
-
-for contract_dir in contracts/*/; do
-  CARGO_LOCK="$contract_dir/Cargo.lock"
-
-  (cd "$contract_dir" && cargo build)
-
-  FILES_MODIFIED+=("$CARGO_LOCK")
-done
-
-echo "Staging ${FILES_MODIFIED[*]} ..."
-git add "${FILES_MODIFIED[@]}"
-git commit -m "Set version: $NEW"
diff --git a/packages/vm/Cargo.toml b/packages/vm/Cargo.toml
index 190e1b087d..617bdb58f6 100644
--- a/packages/vm/Cargo.toml
+++ b/packages/vm/Cargo.toml
@@ -7,6 +7,18 @@ description = "VM bindings to run cosmwams contracts"
 repository = "https://github.com/CosmWasm/cosmwasm/tree/main/packages/vm"
 license = "Apache-2.0"
 
+[package.metadata.release]
+pre-release-hook = [
+    "../../devtools/release_checks.sh"
+]
+pre-release-replacements = [
+    { file="../../CHANGELOG.md", search="## \\[Unreleased\\]", replace="## [{{version}}] - {{date}}", exactly=1 },
+    { file="../../CHANGELOG.md", search="(U|u)nreleased", replace="{{version}}" },
+    { file="../../CHANGELOG.md", search="<!-- next-header -->", replace="<!-- next-header -->\n\n## [Unreleased]", exactly=1 },
+    { file="../../CHANGELOG.md", search="\\.\\.\\.HEAD", replace="...{{tag_name}}", exactly=1 },
+    { file="../../CHANGELOG.md", search="<!-- next-url -->\n", replace="<!-- next-url -->\n\n[unreleased]: https://github.com/CosmWasm/cosmwasm/compare/{{tag_name}}...HEAD", exactly=1 },
+]
+
 [features]
 default = ["staking", "iterator"]
 # backtraces provides much better context at runtime errors (in non-wasm code)