pre-push 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. branch="$(git rev-parse --abbrev-ref HEAD)"
  2. if [ "$branch" = "main" ]; then
  3. echo "You can't push directly to main - please check out a branch."
  4. exit 1
  5. fi
  6. # Detect if running on Windows and use pnpm.cmd, otherwise use pnpm.
  7. if [ "$OS" = "Windows_NT" ]; then
  8. pnpm_cmd="pnpm.cmd"
  9. else
  10. if command -v pnpm >/dev/null 2>&1; then
  11. pnpm_cmd="pnpm"
  12. else
  13. pnpm_cmd="npx pnpm"
  14. fi
  15. fi
  16. $pnpm_cmd run check-types
  17. # Use dotenvx to securely load .env.local and run commands that depend on it
  18. if [ -f ".env.local" ]; then
  19. # Check if RUN_TESTS_ON_PUSH is set to true and run tests with dotenvx
  20. if npx dotenvx get RUN_TESTS_ON_PUSH -f .env.local 2>/dev/null | grep -q "^true$"; then
  21. npx dotenvx run -f .env.local -- $pnpm_cmd run test
  22. fi
  23. else
  24. # Fallback: run tests if RUN_TESTS_ON_PUSH is set in regular environment
  25. if [ "$RUN_TESTS_ON_PUSH" = "true" ]; then
  26. $pnpm_cmd run test
  27. fi
  28. fi
  29. # Check for new changesets.
  30. NEW_CHANGESETS=$(find .changeset -name "*.md" ! -name "README.md" | wc -l | tr -d ' ')
  31. echo "Changeset files: $NEW_CHANGESETS"
  32. if [ "$NEW_CHANGESETS" = "0" ]; then
  33. echo "-------------------------------------------------------------------------------------"
  34. echo "Changes detected. Please run 'pnpm changeset' to create a changeset if applicable."
  35. echo "-------------------------------------------------------------------------------------"
  36. fi