Skip to content

Commit 67bbfde

Browse files
authored
GH-679: Create a script for bumping version (#242)
* initialize bump_version script * GH-679: add the ability to generate lockfile * GH-679: minor improvements * GH-679: add the ability to print the names of failed crates * GH-679: conditionally print the output message * GH-679: remove the error coming from the asterisk * GH-679: iterate through loops for the crates * GH-679: check if the right number of args were supplied * GH-679: quotes cleanup * GH-679: improve the regex * GH-679: decouple pattern from the sed command * GH-679: check the pattern with grep * GH-679: conditionally print message for failed crates * GH-679: migrate pushd and popd to the for loop * GH-679: add the ability to find crates * GH-679: review 2 changes
1 parent 1abd77f commit 67bbfde

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

ci/bump_version.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash
2+
3+
if [ $# != 1 ]
4+
then
5+
echo "Please provide version as the first argument"
6+
exit 1
7+
fi
8+
9+
version="$1"
10+
CI_DIR="$( cd "$( dirname "$0" )" && pwd )"
11+
pushd "$CI_DIR/../"
12+
13+
echo "Searching for crates..."
14+
15+
crates=($(find . -type d -exec bash -c '[ -f "$0"/Cargo.toml ]' '{}' \; -print))
16+
17+
if [[ "${#crates[@]}" == "0" ]]; then
18+
echo "No crates found."
19+
exit 1
20+
else
21+
echo "Found ${#crates[@]} crate(s): ${crates[*]}"
22+
fi
23+
24+
file=Cargo.toml
25+
final_exit_code=0
26+
declare -a grep_failures
27+
declare -a lockfile_failures
28+
29+
bump_version() {
30+
# Catches every `version` that begins a line and doesn't end with a comma.
31+
find_pattern='^version\s*=.*[^,]\s*$'
32+
replace_pattern='s/'$find_pattern'/version = "'"$version"'"/'
33+
34+
grep -q "$find_pattern" "$file" && sed -i "$replace_pattern" "$file"
35+
exit_code="$?"
36+
if [[ "$exit_code" != "0" ]]; then
37+
final_exit_code=1
38+
grep_failures+=($1)
39+
return
40+
fi
41+
42+
cargo generate-lockfile
43+
exit_code="$?"
44+
if [[ "$exit_code" != "0" ]]; then
45+
final_exit_code=1
46+
lockfile_failures+=($1)
47+
fi
48+
}
49+
50+
for crate in "${crates[@]}"
51+
do
52+
pushd "$crate"
53+
bump_version "$crate"
54+
popd
55+
done
56+
57+
if [[ $final_exit_code != 0 ]]; then
58+
[[ "${#grep_failures[@]}" != "0" ]] && echo "Failed to find 'version' for ${#grep_failures[@]} crate(s): ${grep_failures[*]}"
59+
[[ "${#lockfile_failures[@]}" != "0" ]] && echo "Failed to generate lockfile for ${#lockfile_failures[@]} crate(s): ${lockfile_failures[*]}"
60+
else
61+
echo "The version number has been changed to $version."
62+
fi
63+
64+
exit $final_exit_code

0 commit comments

Comments
 (0)