Created
August 14, 2023 17:22
-
-
Save alamenai/08c96b685117e177264264d27ea43a22 to your computer and use it in GitHub Desktop.
Husky scripts example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# This hook enforces that commit messages start with a capitalized verb. | |
# ANSI color codes for formatting | |
RED='\033[0;31m' | |
NC='\033[0m' # No Color | |
commit_msg="$1" | |
error_msg="${RED}error: Commit message must start with a capitalized verb${NC}" | |
# Use regex to check if the message starts with a capitalized verb | |
if ! grep -qE "^[A-Z][a-z]+ " "$commit_msg"; then | |
echo "$error_msg" >&2 | |
exit 1 | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
. "$(dirname -- "$0")/_/husky.sh" | |
# Run linting and lint-staged checks | |
npm run lint && npx lint-staged | |
# Run Cypress tests without opening the launchpad | |
npm run cypress-run-component |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# This hook prevents pushing if the build fails. | |
# ANSI color codes for formatting | |
RED='\033[0;31m' | |
GREEN='\033[0;32m' | |
NC='\033[0m' # No Color | |
# Run your build command (replace with your actual build command) | |
build_command= npm run build | |
if ! $build_command; then | |
echo "${RED}error: Build failed. Fix the build issues before pushing.${NC}" >&2 | |
exit 1 | |
else | |
echo -e "${GREEN}Build succeeded. Processing and Pushing...${NC}" >&2 | |
echo # This line adds an empty line | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment