Skip to content

Commit

Permalink
chore(dev): Script to update cargo deps (#801)
Browse files Browse the repository at this point in the history
Add a script that handles updating cargo dependencies, running tests,
and creating a commit since this is a relatively common operation.

If the script fails at any step the commit will not be created.
  • Loading branch information
afnanenayet authored Jan 14, 2024
1 parent 792655f commit e4f22f9
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions dev_scripts/update_dependencies.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash
# Updates Cargo dependencies and generates a commit if the operation is successful and tests pass.
# This requires the user to have the following binaries available in their PATH:
#
# - cargo
# - cargo-upgrade
# - cargo-update
# - cargo-nextest
#
# If these can't be found the script will exit with an error.

required_binaries=("cargo" "cargo-upgrade" "cargo-update" "cargo-nextest")

for cmd in "${required_binaries[@]}"
do
if ! command -v "$cmd"
then
echo "$cmd was not found"
exit 1
fi
done

# Checks if the current branch is clean, we only want this script to run in a clean context so
# we don't accidentally commit other changes.
has_changes=$(git diff-files --quiet)

if [ "$has_changes" -ne "0" ]; then
echo "ERROR: detected local changes. You must run this script with a clean git context."
exit 1
fi

set -ex

cargo upgrade --incompatible
cargo update
cargo test --doc
cargo nextest run
git add Cargo.lock Cargo.toml
git commit -m "chore(deps): Update cargo dependencies" \
-m "Done with \`dev_scripts/update_dependencies.bash\`"

0 comments on commit e4f22f9

Please # to comment.