ぼざクリ タグ広場 https://hub.nizika.monster
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

52 lines
1.1 KiB

  1. #!/bin/sh
  2. # A sample pre-build hook
  3. #
  4. # Checks:
  5. # 1. We have a clean checkout
  6. # 2. A remote is configured
  7. # 3. The branch has been pushed to the remote
  8. # 4. The version we are deploying matches the remote
  9. #
  10. # These environment variables are available:
  11. # KAMAL_RECORDED_AT
  12. # KAMAL_PERFORMER
  13. # KAMAL_VERSION
  14. # KAMAL_HOSTS
  15. # KAMAL_ROLE (if set)
  16. # KAMAL_DESTINATION (if set)
  17. if [ -n "$(git status --porcelain)" ]; then
  18. echo "Git checkout is not clean, aborting..." >&2
  19. git status --porcelain >&2
  20. exit 1
  21. fi
  22. first_remote=$(git remote)
  23. if [ -z "$first_remote" ]; then
  24. echo "No git remote set, aborting..." >&2
  25. exit 1
  26. fi
  27. current_branch=$(git branch --show-current)
  28. if [ -z "$current_branch" ]; then
  29. echo "Not on a git branch, aborting..." >&2
  30. exit 1
  31. fi
  32. remote_head=$(git ls-remote $first_remote --tags $current_branch | cut -f1)
  33. if [ -z "$remote_head" ]; then
  34. echo "Branch not pushed to remote, aborting..." >&2
  35. exit 1
  36. fi
  37. if [ "$KAMAL_VERSION" != "$remote_head" ]; then
  38. echo "Version ($KAMAL_VERSION) does not match remote HEAD ($remote_head), aborting..." >&2
  39. exit 1
  40. fi
  41. exit 0