Skip to content

Commit

Permalink
Merge pull request #1916 from input-output-hk/sfa/script_to_upgrade_d…
Browse files Browse the repository at this point in the history
…ependencies

Add a script to update all dependencies
  • Loading branch information
sfauvel authored Sep 6, 2024
2 parents 6f9da0c + 52c9a94 commit 8690abe
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 0 deletions.
20 changes: 20 additions & 0 deletions docs/runbook/upgrade-repository-dependencies/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@

This runbook provides step-by-step instructions to upgrade the dependencies in the repository, including Rust crates, documentation, and JavaScript packages.

## Update dependencies tool

The `update_dependencies.sh` script allows you to to update dependencies performing all the steps described in the next chapter.

It requires having `cargo-edit` installed, which can be done with the following command:

```
cargo install cargo-edit
```

To start the update, execute the command:

```
. ../docs/runbook/upgrade-repository-dependencies/upgrade-dependencies.sh
```

By default, Rust dependencies are updated to the latest version. If you want to only update to the latest compatible versions, add the `--incompatible` option to the command.

**Warning**: Before re-running the script, you need to revert the modified code to its original state to avoid incrementing the versions of crates and JSON packages twice.

## Steps

### Upgrade Rust outdated dependencies
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/bin/bash

# get command line arguments to pass them to `cargo upgrade` command
# By default, we allow upgrading all dependencies to the latest one.
# If you want to upgrade only to the compatible version, launch script with option `--compatbile`
CARGO_UPGRADE_OPTIONS=${*:-"--incompatible"}

# Need to install `cargo-edit` to execute `cargo upgrade` and `cargo set-version` commands

# Upgrade Rust outdated dependencies
cargo upgrade "${CARGO_UPGRADE_OPTIONS}" --verbose
# cargo upgrade -i allow --verbose
# Let the CI run the tests at the end of the script
# cargo test --all-features
git commit -am "chore: update Rust dependencies"

# Bump Rust crates versions
cargo set-version --bump patch
git commit -am "chore: bump crates versions"

# Upgrade the documentation website dependencies
pushd docs/website || exit
make upgrade
popd || exit
git commit -am "chore: upgrade doc dependencies
By running 'make upgrade' command."

# Upgrade the explorer dependencies
pushd mithril-explorer || exit
make upgrade
popd || exit
git commit -am "chore: upgrade explorer dependencies
By running 'make upgrade' command."

# Upgrade www/ and www-test/ dependencies
pushd mithril-client-wasm || exit
make upgrade-www-deps
popd || exit

git commit -am "chore: upgrade mithril client wasm 'www' and 'www-test' dependencies
By running 'make upgrade-www-deps' command."

# Bump Javascript packages versions

# Search all package.json files and bump the version
# and exclude `package.json` in `node_modules` folder
for package_json_file in $(find . -name package.json | grep -v "/node_modules/"); do
folder="$(dirname $package_json_file)"
pushd "$folder" || exit
npm version patch
popd || exit
done

pushd mithril-client-wasm || exit
make www-install www-test-install
popd || exit

pushd mithril-explorer || exit
make install
popd || exit

pushd docs/website || exit
make install
popd || exit

git commit -am "chore: bump mithril client wasm 'www' and 'www-test' dependencies
By running:
- 'make www-install' command in 'mithril-client-wasm'.
- 'make www-test-install' command in 'mithril-client-wasm'.
- 'make install' command in 'mithril-explorer'.
- 'make install' command in 'docs/website'."

# create a temporary script file that print "hello"
TMP_SCRIPT_DIR=/tmp/mithril
FLAKE_UPDATE_SCRIPT=nix_flake_update.sh

mkdir -p "$TMP_SCRIPT_DIR"
echo "git config --global --add safe.directory '*'
nix --extra-experimental-features 'nix-command flakes' flake update" > "$TMP_SCRIPT_DIR/$FLAKE_UPDATE_SCRIPT"

# The nix update is deactivated while waiting to be compatible with the latest version
# # Upgrade Nix Flake dependencies
# docker run -v "$(pwd)":/mithril -v "$TMP_SCRIPT_DIR":/scripts/mithril -w /mithril nixos/nix /bin/sh -c ". /scripts/mithril/$FLAKE_UPDATE_SCRIPT"
# rm "$TMP_SCRIPT_DIR/$FLAKE_UPDATE_SCRIPT"
#
# git commit -am "chore: update nix flake dependencies
# 
# By running 'nix flake update' command."

0 comments on commit 8690abe

Please sign in to comment.