1+ #! /bin/bash
2+
3+ set -e
4+
5+ # Step 1: Read the version from Cargo.toml
6+ version=$( grep ' ^version = ' Cargo.toml | head -n 1 | sed ' s/version = "\(.*\)"/\1/' )
7+
8+ if [ -z " $version " ]; then
9+ echo " Version not found in Cargo.toml"
10+ exit 1
11+ fi
12+
13+ echo " Aligning for version: $version "
14+
15+ # GNU/BSD compat
16+ sedi=(-i' ' )
17+ case " $( uname) " in
18+ # For macOS, use two parameters
19+ Darwin* ) sedi=(-i ' ' )
20+ esac
21+
22+ # Update the version for all crates in the Cargo.toml workspace.dependencies section
23+ sed " ${sedi[@]} " " /\[workspace.dependencies\]/,/\## External crates/s/version = \" =.*\" /version = \" =$version \" /" Cargo.toml
24+
25+ # Update the version in clients/bolt-sdk/package.json
26+ jq --arg version " $version " ' .version = $version' clients/bolt-sdk/package.json > temp.json && mv temp.json clients/bolt-sdk/package.json
27+
28+ # Update the version in cli/npm-package/package.json.tmpl
29+ jq --arg version " $version " ' .version = $version' cli/npm-package/package.json.tmpl > temp.json && mv temp.json cli/npm-package/package.json.tmpl
30+
31+ # Update the main package version and all optionalDependencies versions in cli/npm-package/package.json
32+ jq --arg version " $version " ' (.version = $version) | (.optionalDependencies[] = $version)' cli/npm-package/package.json > temp.json && mv temp.json cli/npm-package/package.json
33+
34+ # Potential for collisions in Cargo.lock, use cargo update to update it
35+ cargo update --workspace
36+
37+
38+ # Check if the any changes have been made to the specified files, if running with --check
39+ if [[ " $1 " == " --check" ]]; then
40+ files_to_check=(
41+ " clients/bolt-sdk/package.json"
42+ " cli/npm-package/package.json.tmpl"
43+ " cli/npm-package/package.json"
44+ " Cargo.toml"
45+ )
46+
47+ for file in " ${files_to_check[@]} " ; do
48+ # Check if the file has changed from the previous commit
49+ if git diff --name-only | grep -q " $file " ; then
50+ echo " Error: version not aligned for $file . Align the version, commit and try again."
51+ exit 1
52+ fi
53+ done
54+ exit 0
55+ fi
0 commit comments