2018-11-11 08:19:04 -08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -e
|
2018-10-25 09:13:25 -07:00
|
|
|
|
|
|
|
usage() {
|
|
|
|
cat <<EOF
|
2018-10-25 11:45:15 -07:00
|
|
|
usage: $0 [major|minor|patch|-preXYZ]
|
2018-10-25 09:13:25 -07:00
|
|
|
|
|
|
|
Increments the Cargo.toml version.
|
2019-07-25 13:57:18 -07:00
|
|
|
|
|
|
|
Default:
|
|
|
|
* Removes the prerelease tag if present, otherwise the minor version is incremented.
|
2018-10-25 09:13:25 -07:00
|
|
|
EOF
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
here="$(dirname "$0")"
|
|
|
|
cd "$here"/..
|
|
|
|
source ci/semver_bash/semver.sh
|
2020-10-23 10:45:19 -07:00
|
|
|
source scripts/read-cargo-variable.sh
|
2018-10-25 09:13:25 -07:00
|
|
|
|
2020-10-19 14:08:27 -07:00
|
|
|
ignores=(
|
|
|
|
.cache
|
|
|
|
.cargo
|
|
|
|
target
|
|
|
|
web3.js/examples
|
|
|
|
)
|
|
|
|
|
|
|
|
not_paths=()
|
|
|
|
for ignore in "${ignores[@]}"; do
|
|
|
|
not_paths+=(-not -path "*/$ignore/*")
|
|
|
|
done
|
|
|
|
|
|
|
|
# shellcheck disable=2207,SC2068 # Don't want a positional arg if `not-paths` is empty
|
|
|
|
Cargo_tomls=($(find . -mindepth 2 -name Cargo.toml ${not_paths[@]}))
|
2019-10-18 20:53:45 -07:00
|
|
|
# shellcheck disable=2207
|
|
|
|
markdownFiles=($(find . -name "*.md"))
|
2018-10-25 12:26:57 -07:00
|
|
|
|
|
|
|
# Collect the name of all the internal crates
|
|
|
|
crates=()
|
2019-04-15 13:25:44 -07:00
|
|
|
for Cargo_toml in "${Cargo_tomls[@]}"; do
|
2018-10-25 12:26:57 -07:00
|
|
|
crates+=("$(readCargoVariable name "$Cargo_toml")")
|
|
|
|
done
|
|
|
|
|
|
|
|
# Read the current version
|
2018-10-25 09:13:25 -07:00
|
|
|
MAJOR=0
|
|
|
|
MINOR=0
|
|
|
|
PATCH=0
|
|
|
|
SPECIAL=""
|
2019-04-15 13:25:44 -07:00
|
|
|
|
2019-03-20 21:01:23 -07:00
|
|
|
semverParseInto "$(readCargoVariable version "${Cargo_tomls[0]}")" MAJOR MINOR PATCH SPECIAL
|
2018-10-25 09:13:25 -07:00
|
|
|
[[ -n $MAJOR ]] || usage
|
|
|
|
|
2020-03-06 13:36:01 -08:00
|
|
|
currentVersion="$MAJOR\.$MINOR\.$PATCH$SPECIAL"
|
2019-07-25 13:57:18 -07:00
|
|
|
|
|
|
|
bump=$1
|
|
|
|
if [[ -z $bump ]]; then
|
|
|
|
if [[ -n $SPECIAL ]]; then
|
|
|
|
bump=dropspecial # Remove prerelease tag
|
|
|
|
else
|
|
|
|
bump=minor
|
|
|
|
fi
|
|
|
|
fi
|
2018-10-25 11:45:15 -07:00
|
|
|
SPECIAL=""
|
2018-10-25 09:13:25 -07:00
|
|
|
|
2018-10-25 12:26:57 -07:00
|
|
|
# Figure out what to increment
|
2019-07-25 13:57:18 -07:00
|
|
|
case $bump in
|
2018-10-25 09:13:25 -07:00
|
|
|
patch)
|
|
|
|
PATCH=$((PATCH + 1))
|
|
|
|
;;
|
|
|
|
major)
|
|
|
|
MAJOR=$((MAJOR+ 1))
|
2020-02-20 21:56:13 -08:00
|
|
|
MINOR=0
|
|
|
|
PATCH=0
|
2018-10-25 09:13:25 -07:00
|
|
|
;;
|
|
|
|
minor)
|
|
|
|
MINOR=$((MINOR+ 1))
|
2020-02-20 21:56:13 -08:00
|
|
|
PATCH=0
|
2018-10-25 09:13:25 -07:00
|
|
|
;;
|
2019-07-25 13:57:18 -07:00
|
|
|
dropspecial)
|
|
|
|
;;
|
2020-11-05 16:04:05 -08:00
|
|
|
check)
|
|
|
|
badTomls=()
|
|
|
|
for Cargo_toml in "${Cargo_tomls[@]}"; do
|
|
|
|
if ! grep "^version *= *\"$currentVersion\"$" "$Cargo_toml" &>/dev/null; then
|
|
|
|
badTomls+=("$Cargo_toml")
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [[ ${#badTomls[@]} -ne 0 ]]; then
|
|
|
|
echo "Error: Incorrect crate version specified in: ${badTomls[*]}"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
exit 0
|
|
|
|
;;
|
2018-10-25 16:18:08 -07:00
|
|
|
-*)
|
|
|
|
if [[ $1 =~ ^-[A-Za-z0-9]*$ ]]; then
|
|
|
|
SPECIAL="$1"
|
|
|
|
else
|
|
|
|
echo "Error: Unsupported characters found in $1"
|
|
|
|
exit 1
|
|
|
|
fi
|
2018-10-25 11:45:15 -07:00
|
|
|
;;
|
2018-10-25 09:13:25 -07:00
|
|
|
*)
|
|
|
|
echo "Error: unknown argument: $1"
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2018-10-25 11:45:15 -07:00
|
|
|
newVersion="$MAJOR.$MINOR.$PATCH$SPECIAL"
|
2018-10-25 09:13:25 -07:00
|
|
|
|
2018-10-25 12:26:57 -07:00
|
|
|
# Update all the Cargo.toml files
|
2019-04-15 13:25:44 -07:00
|
|
|
for Cargo_toml in "${Cargo_tomls[@]}"; do
|
2018-10-25 12:26:57 -07:00
|
|
|
# Set new crate version
|
2018-10-25 09:13:25 -07:00
|
|
|
(
|
|
|
|
set -x
|
2019-08-20 17:05:28 -07:00
|
|
|
sed -i "$Cargo_toml" -e "0,/^version =/{s/^version = \"[^\"]*\"$/version = \"$newVersion\"/}"
|
2018-10-25 10:38:34 -07:00
|
|
|
)
|
|
|
|
|
2018-10-25 12:26:57 -07:00
|
|
|
# Fix up the version references to other internal crates
|
|
|
|
for crate in "${crates[@]}"; do
|
|
|
|
(
|
|
|
|
set -x
|
|
|
|
sed -i "$Cargo_toml" -e "
|
2019-05-29 18:30:49 -07:00
|
|
|
s/^$crate = { *path *= *\"\([^\"]*\)\" *, *version *= *\"[^\"]*\"\(.*\)} *\$/$crate = \{ path = \"\1\", version = \"$newVersion\"\2\}/
|
2018-10-25 12:26:57 -07:00
|
|
|
"
|
|
|
|
)
|
|
|
|
done
|
2018-10-25 09:13:25 -07:00
|
|
|
done
|
2018-10-25 10:38:34 -07:00
|
|
|
|
2019-10-18 20:53:45 -07:00
|
|
|
# Update all the documentation references
|
|
|
|
for file in "${markdownFiles[@]}"; do
|
|
|
|
# Set new crate version
|
|
|
|
(
|
|
|
|
set -x
|
|
|
|
sed -i "$file" -e "s/$currentVersion/$newVersion/g"
|
|
|
|
)
|
|
|
|
done
|
|
|
|
|
2018-10-25 09:13:25 -07:00
|
|
|
echo "$currentVersion -> $newVersion"
|
|
|
|
|
|
|
|
exit 0
|