version_control.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. checkout_eval_branch() {
  2. if [ -z "$COMMIT_HASH" ]; then
  3. echo "Commit hash not specified, use current git commit"
  4. return 0
  5. fi
  6. if git diff --quiet $COMMIT_HASH HEAD; then
  7. echo "The given hash is equivalent to the current HEAD"
  8. return 0
  9. fi
  10. echo "Start to checkout openhands version to $COMMIT_HASH, but keep current evaluation harness"
  11. if ! git diff-index --quiet HEAD --; then
  12. echo "There are uncommitted changes, please stash or commit them first"
  13. exit 1
  14. fi
  15. current_branch=$(git rev-parse --abbrev-ref HEAD)
  16. echo "Current version is: $current_branch"
  17. echo "Check out OpenHands to version: $COMMIT_HASH"
  18. if ! git checkout $COMMIT_HASH; then
  19. echo "Failed to check out to $COMMIT_HASH"
  20. exit 1
  21. fi
  22. echo "Revert changes in evaluation folder"
  23. git checkout $current_branch -- evaluation
  24. # Trap the EXIT signal to checkout original branch
  25. trap checkout_original_branch EXIT
  26. }
  27. checkout_original_branch() {
  28. if [ -z "$current_branch" ]; then
  29. return 0
  30. fi
  31. echo "Checkout back to original branch $current_branch"
  32. git checkout $current_branch
  33. }
  34. get_agent_version() {
  35. # IMPORTANT: Because Agent's prompt changes fairly often in the rapidly evolving codebase of OpenHands
  36. # We need to track the version of Agent in the evaluation to make sure results are comparable
  37. AGENT_VERSION=v$(poetry run python -c "import openhands.agenthub; from openhands.controller.agent import Agent; print(Agent.get_cls('$AGENT').VERSION)")
  38. }