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