# Read argument from command line (version). # If no argument is provided, the script will exit. # If the argument is "major", the script will increment the major version. # If the argument is "minor", the script will increment the minor version. # If the argument is "patch", the script will increment the patch version. # If the argument is not "major", "minor" or "patch", the script will exit. # The script will update the version in Cargo.toml, commit the change and push it to the remote repository. # The script will create a git tag with the new version and push it to the remote repository. # The script will build the project and publish it to crates.io. # Usage: "./release.sh " # Example: "./release.sh patch" # Read argument from command line (version). if [ -z "$1" ]; then echo "No version provided. Usage: \"./release.sh \"" exit 1 else version=$1 fi if [ "$version" != "major" ] && [ "$version" != "minor" ] && [ "$version" != "patch" ]; then echo "Invalid version provided. Usage: \"./release.sh \"" exit 1 fi # Check if $version equals "major" word. # If it is, the script will increment the major version. if [ "$version" = "major" ]; then current_major_version=$(grep version Cargo.toml | head -n1 | cut -d '"' -f2 | cut -d '.' -f1) major_version=$((current_major_version + 1)) version="$major_version.0.0" fi # Check if $version equals "minor" word. # If it is, the script will increment the minor version. if [ "$version" = "minor" ]; then current_minor_version=$(grep version Cargo.toml | head -n1 | cut -d '"' -f2 | cut -d '.' -f2) minor_version=$((current_minor_version + 1)) current_major_version=$(grep version Cargo.toml | head -n1 | cut -d '"' -f2 | cut -d '.' -f1) version="$current_major_version.$minor_version.0" fi # Check if $version equals "patch" word. # If it is, the script will increment the patch version. if [ "$version" = "patch" ]; then current_patch_version=$(grep version Cargo.toml | head -n1 | cut -d '"' -f2 | cut -d '.' -f3) patch_version=$((current_patch_version + 1)) current_minor_version=$(grep version Cargo.toml | head -n1 | cut -d '"' -f2 | cut -d '.' -f2) current_major_version=$(grep version Cargo.toml | head -n1 | cut -d '"' -f2 | cut -d '.' -f1) version="$current_major_version.$current_minor_version.$patch_version" fi # Print the new version. echo "Releasing $version" # Update Cargo.toml with the new version. sed -i '' "s/^version = \".*\"/version = \"$version\"/" Cargo.toml # Build the project. ./build.sh # Add Cargo.toml to repository. git add Cargo.toml git add Cargo.lock git commit -m "Change version to $version" git push # Add git tag and push it to the remote repository. git tag -a $version -m "Release $version" git push origin $version # Publish the new release. ./publish.sh