update-dependencies.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env bash
  2. # SPDX-FileCopyrightText: 2025 Christina Sørensen
  3. #
  4. # SPDX-License-Identifier: EUPL-1.2
  5. set -euo pipefail
  6. commit_changes() {
  7. local file_to_check="$1"
  8. local commit_subject="$2"
  9. local commit_body="$3"
  10. # Check if the file has changes staged or unstaged
  11. if ! git diff --quiet --exit-code "$file_to_check"; then
  12. echo "$file_to_check has been updated. Committing changes."
  13. git add "$file_to_check"
  14. printf "%s\n\n%s" "$commit_subject" "$commit_body" | git commit -F -
  15. else
  16. echo "No changes to $file_to_check. Skipping commit."
  17. fi
  18. }
  19. BRANCH_NAME="deps_update_$(date --iso-8601)"
  20. if git rev-parse --verify "$BRANCH_NAME" >/dev/null 2>&1; then
  21. echo "Branch '$BRANCH_NAME' already exists. Checking out."
  22. git switch "$BRANCH_NAME"
  23. else
  24. git switch -c "$BRANCH_NAME"
  25. fi
  26. # 1. Update Cargo dependencies
  27. echo "Checking for Cargo dependency updates..."
  28. # Redirect stderr to stdout to capture cargo's output.
  29. CARGO_OUTPUT=$(cargo update --recursive 2>&1)
  30. UPDATED_CRATES=$(echo "$CARGO_OUTPUT" | grep 'Updating' || true)
  31. commit_changes "Cargo.lock" "build(deps): cargo bump $(date --iso-8601)" "$UPDATED_CRATES"
  32. # 2. Update Nix Flake dependencies
  33. echo "Checking for Nix Flake dependency updates..."
  34. # Use grep -A 2 to capture the 2 lines *after* the match.
  35. FLAKE_OUTPUT=$(nix flake update 2>&1)
  36. UPDATED_FLAKES=$(echo "$FLAKE_OUTPUT" | grep -A 2 'Updated input' || true)
  37. commit_changes "flake.lock" "build(deps): flake bump $(date --iso-8601)" "$UPDATED_FLAKES"
  38. echo "Dependency update process complete."
  39. git status