-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add precommit hooks and add taskfile (#26)
- Loading branch information
1 parent
1dd9273
commit bab51f5
Showing
9 changed files
with
245 additions
and
71 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
|
||
origin_head_sha=$(git rev-parse origin/HEAD) | ||
|
||
git cliff "$origin_head_sha"..HEAD | pbcopy | ||
echo Changelog has been copied to the clipboard. | ||
pbpaste |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
linter() { | ||
echo "Running Go linter..." | ||
if task lint; then | ||
echo "Linter passed!" | ||
else | ||
echo "Linter failed. Please fix the issues before committing." | ||
exit 1 | ||
fi | ||
} | ||
|
||
linter |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
|
||
COMMIT_MSG_FILE=$1 | ||
COMMIT_MSG=$(cat "$COMMIT_MSG_FILE") | ||
REGEX="^((Merge[ a-z-]* branch.*)|(Revert*)|((build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\(.*\))?!?: .*))" | ||
|
||
if [[ ! "$COMMIT_MSG" =~ $REGEX ]]; then | ||
RED='\033[0;31m' | ||
RESET='\033[0m' | ||
|
||
echo -e "${RED}Error: Commit message does not follow the Conventional Commits format.${RESET}" | ||
echo "Example: feat(ui): add new button component" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
#!/usr/bin/env zsh | ||
|
||
# Exit when a command fails. | ||
set -euo pipefail | ||
|
||
BREW_PACKAGES=(go-task jq golangci-lint git-cliff) | ||
NODE_VERSION="20.17.0" | ||
|
||
BLACK="\033[30m" | ||
RED="\033[31m" | ||
GREEN="\033[32m" | ||
YELLOW="\033[33m" | ||
BLUE="\033[34m" | ||
MAGENTA="\033[35m" | ||
CYAN="\033[36m" | ||
WHITE="\033[37m" | ||
DEFAULT="\033[39m" | ||
RESET="\033[0m" | ||
BOLD="\033[1m" | ||
UNDERLINE="\033[4m" | ||
REVERSED="\033[7m" | ||
|
||
pretty_print() { | ||
local message="$1" | ||
local color="${2:-$DEFAULT}" | ||
local style="${3:-}" | ||
|
||
echo -e "${color}${style}$message${RESET}" | ||
} | ||
|
||
header() { | ||
pretty_print "\n========================================================================" | ||
pretty_print "$1" $BLUE $BOLD | ||
pretty_print "========================================================================\n" | ||
} | ||
|
||
success() { | ||
pretty_print "" | ||
pretty_print "✅ $1" $GREEN | ||
} | ||
|
||
install_go () { | ||
header "Setting up Go 🐹" | ||
|
||
if command -v go; then | ||
echo "Go is already installed" | ||
go version | ||
return | ||
else | ||
curl -L https://git.io/vQhTU | bash -s -- --version 1.23.1 | ||
fi | ||
|
||
success "Finished setting up Go!" | ||
} | ||
|
||
# Install Homebrew, a package manager for macOS | ||
install_brew() { | ||
header "Setting up Homebrew 🍺" | ||
|
||
if command -v brew; then | ||
echo "Homebrew is already installed" | ||
eval "$(brew shellenv)" | ||
else | ||
/bin/zsh -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" | ||
INSTALL_DIR="/opt/homebrew/bin" | ||
|
||
if read -q "confirm? -> add $INSTALL_DIR to path in ~/.zprofile? [y/N] "; then | ||
echo 'eval "$('$INSTALL_DIR'/brew shellenv)"' >>~/.zprofile | ||
fi | ||
|
||
echo | ||
eval "$($INSTALL_DIR/brew shellenv)" | ||
|
||
if ! command -v brew >/dev/null; then | ||
echo "Brew installation failed!" | ||
exit 1 | ||
fi | ||
fi | ||
|
||
success "Finished setting up Homebrew!" | ||
} | ||
|
||
# Install Volta, a JavaScript tool manager | ||
install_volta() { | ||
header "Setting up Volta ⚡️" | ||
|
||
if command -v volta; then | ||
echo "Volta is already installed" | ||
else | ||
curl https://get.volta.sh | bash | ||
fi | ||
|
||
success "Finished setting up Volta!" | ||
} | ||
|
||
# Install Node.js using Volta | ||
install_node() { | ||
header "Installing Node.js 🚀" | ||
|
||
if command -v node; then | ||
echo "Node.js is already installed" | ||
node --version | ||
return | ||
else | ||
volta install node@${NODE_VERSION} | ||
# Run node version to verify installation | ||
node --version | ||
fi | ||
|
||
success "Finished installing Node.js!" | ||
} | ||
|
||
# Install or upgrade a package with Homebrew | ||
brew_install() { | ||
if brew ls --versions "$1"; then | ||
brew upgrade "$1" | ||
else | ||
brew install "$1" | ||
fi | ||
} | ||
|
||
# Install packages with Homebrew | ||
install_packages() { | ||
header "Installing packages with Homebrew 🍺" | ||
|
||
for package in "${BREW_PACKAGES[@]}"; do | ||
echo "Installing or upgrading $package..." | ||
brew_install "$package" | ||
echo "Installed or upgraded $package" | ||
done | ||
|
||
success "Finished installing packages with Homebrew!" | ||
} | ||
|
||
# Setup git hooks. | ||
setup_git_hooks() { | ||
header "Setting up git hooks 🎣" | ||
|
||
task setup-git-hooks | ||
success "Finished setting up git hooks!" | ||
} | ||
|
||
echo "Setting up your development environment..." | ||
|
||
install_go | ||
install_brew | ||
install_volta | ||
install_node | ||
install_packages | ||
|
||
setup_git_hooks | ||
|
||
pretty_print "\nFinished setting up your development environment! 🎉" $GREEN $BOLD |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
version: '3' | ||
|
||
vars: | ||
SHELL_TO_USE: | ||
sh: | | ||
echo ${SHELL_TO_USE:-$(basename $SHELL)} | ||
tasks: | ||
build: | ||
desc: "Build the project" | ||
cmds: | ||
- "go build -o {{.CLI_ARGS}}" | ||
|
||
test: | ||
desc: "Run tests" | ||
cmds: | ||
- "go test -race -short -v ./..." | ||
|
||
coverage: | ||
desc: "Run tests with coverage" | ||
cmds: | ||
- "go test -cover -covermode=count -coverprofile=coverage.out ./..." | ||
- "go tool cover -func coverage.out" | ||
|
||
typespec: | ||
desc: "Generate OpenAPI spec" | ||
cmds: | ||
- "{{.SHELL_TO_USE}} scripts/compile-spec.sh" | ||
- "go generate ./..." | ||
|
||
lint-fix: | ||
desc: "Lint Go Code" | ||
cmds: | ||
- "golangci-lint run --fix" | ||
|
||
lint: | ||
desc: "Lint all modules" | ||
cmds: | ||
- "golangci-lint run" | ||
|
||
changelog: | ||
desc: "Generate a changelog for a pull request" | ||
cmds: | ||
- "{{.SHELL_TO_USE}} scripts/generate-pr-changelog.sh" | ||
|
||
setup-git-hooks: | ||
desc: "Set up Git hooks" | ||
cmds: | ||
- "chmod +x ./scripts/hooks/pre-commit" | ||
- "chmod +x ./scripts/hooks/prepare-commit-msg" | ||
- "git config core.hooksPath ./scripts/hooks" |
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