Skip to content

Commit

Permalink
GH-679: Create a script for bumping version (#242)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
utkarshg6 authored Mar 20, 2023
1 parent 1abd77f commit 67bbfde
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions ci/bump_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash

if [ $# != 1 ]
then
echo "Please provide version as the first argument"
exit 1
fi

version="$1"
CI_DIR="$( cd "$( dirname "$0" )" && pwd )"
pushd "$CI_DIR/../"

echo "Searching for crates..."

crates=($(find . -type d -exec bash -c '[ -f "$0"/Cargo.toml ]' '{}' \; -print))

if [[ "${#crates[@]}" == "0" ]]; then
echo "No crates found."
exit 1
else
echo "Found ${#crates[@]} crate(s): ${crates[*]}"
fi

file=Cargo.toml
final_exit_code=0
declare -a grep_failures
declare -a lockfile_failures

bump_version() {
# Catches every `version` that begins a line and doesn't end with a comma.
find_pattern='^version\s*=.*[^,]\s*$'
replace_pattern='s/'$find_pattern'/version = "'"$version"'"/'

grep -q "$find_pattern" "$file" && sed -i "$replace_pattern" "$file"
exit_code="$?"
if [[ "$exit_code" != "0" ]]; then
final_exit_code=1
grep_failures+=($1)
return
fi

cargo generate-lockfile
exit_code="$?"
if [[ "$exit_code" != "0" ]]; then
final_exit_code=1
lockfile_failures+=($1)
fi
}

for crate in "${crates[@]}"
do
pushd "$crate"
bump_version "$crate"
popd
done

if [[ $final_exit_code != 0 ]]; then
[[ "${#grep_failures[@]}" != "0" ]] && echo "Failed to find 'version' for ${#grep_failures[@]} crate(s): ${grep_failures[*]}"
[[ "${#lockfile_failures[@]}" != "0" ]] && echo "Failed to generate lockfile for ${#lockfile_failures[@]} crate(s): ${lockfile_failures[*]}"
else
echo "The version number has been changed to $version."
fi

exit $final_exit_code

0 comments on commit 67bbfde

Please sign in to comment.