Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions .githooks/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/sh

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

echo "${YELLOW}🔍 Validating commit message format...${NC}"

# Check if commitlint is available
if ! command -v npx > /dev/null 2>&1; then
echo "${RED}❌ Node.js/npm not available. Please install Node.js to validate commit messages.${NC}"
exit 1
fi

# Check if this is a merge commit
if [ -f .git/MERGE_HEAD ]; then
echo "${GREEN}✅ Merge commit detected, skipping validation${NC}"
exit 0
fi

# Read the commit message
COMMIT_MSG_FILE="$1"
COMMIT_MSG=$(cat "$COMMIT_MSG_FILE")

# Skip empty commits
if [ -z "$COMMIT_MSG" ] || [ "$COMMIT_MSG" = "" ]; then
echo "${RED}❌ Empty commit message${NC}"
exit 1
fi

# Run commitlint
echo "$COMMIT_MSG" | npx commitlint
COMMITLINT_EXIT_CODE=$?

if [ $COMMITLINT_EXIT_CODE -ne 0 ]; then
echo ""
echo "${RED}❌ Commit message does not follow conventional commit format!${NC}"
echo ""
echo "${YELLOW}Expected format:${NC}"
echo " ${GREEN}type(scope): description${NC}"
echo ""
echo "${YELLOW}Valid types:${NC}"
echo " feat: A new feature"
echo " fix: A bug fix"
echo " docs: Documentation only changes"
echo " style: Changes that do not affect the meaning of the code"
echo " refactor: A code change that neither fixes a bug nor adds a feature"
echo " test: Adding missing tests or correcting existing tests"
echo " chore: Changes to the build process or auxiliary tools"
echo " perf: A code change that improves performance"
echo " ci: Changes to CI configuration files and scripts"
echo " build: Changes that affect the build system"
echo " revert: Reverts a previous commit"
echo ""
echo "${YELLOW}Examples:${NC}"
echo " ${GREEN}feat(auth): add user authentication${NC}"
echo " ${GREEN}fix(api): resolve validation error in user endpoint${NC}"
echo " ${GREEN}docs: update API documentation${NC}"
echo ""
echo "${YELLOW}💡 Use '${GREEN}npm run commit${NC}${YELLOW}' or '${GREEN}make commit${NC}${YELLOW}' for interactive commit creation!${NC}"
exit 1
fi

echo "${GREEN}✅ Commit message format is valid${NC}"
exit 0
24 changes: 21 additions & 3 deletions .githooks/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
#!/bin/sh

BRANCH_NAME=$(git branch --show-current)
# Check if this is a merge commit or revert
if [ "$2" = "merge" ] || [ "$2" = "squash" ] || [ "$2" = "commit" ]; then
exit 0
fi

# Check if commitizen is available
if ! command -v npx > /dev/null 2>&1; then
echo "Warning: Node.js/npm not available for commit message validation"
exit 0
fi

# Skip if already has conventional commit format
COMMIT_MSG=$(cat "$1")
if echo "$COMMIT_MSG" | grep -qE '^(feat|fix|docs|style|refactor|test|chore|perf|ci|build|revert)(\(.+\))?: .+'; then
exit 0
fi

if [ -n "$BRANCH_NAME" ]; then
echo "[$BRANCH_NAME] $(cat "$1")" > "$1"
# Interactive commit with commitizen if not automated
if [ -t 1 ]; then
echo "🚨 Interactive commit detected. Please use 'npm run commit' or 'make commit' for proper semantic commits!"
echo "Your commit message will be validated against conventional commit standards."
exit 1
fi
31 changes: 31 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: CI

on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]

jobs:
validate-commits:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Validate commit messages
run: |
# Validate all commits in the PR
npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose
36 changes: 36 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Release Please

on:
push:
branches:
- main

permissions:
contents: write
pull-requests: write

jobs:
release-please:
runs-on: ubuntu-latest
outputs:
release_created: ${{ steps.release.outputs.release_created }}
tag_name: ${{ steps.release.outputs.tag_name }}
steps:
- name: Release Please
id: release
uses: google-github-actions/release-please-action@v4
with:
release-type: simple
config-file: release-please-config.json
manifest-file: .release-please-manifest.json

publish-artifacts:
runs-on: ubuntu-latest
needs: release-please
if: ${{ needs.release-please.outputs.release_created }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@
/storage/*.key
/storage/pail
/vendor

# Commit tools
node_modules/
npm-debug.log*
.npm
.husky/_/

# Release artifacts
CHANGELOG.md

Homestead.json
Homestead.yaml
Thumbs.db
Expand Down
3 changes: 3 additions & 0 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
".": "1.0.0"
}
57 changes: 56 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,40 @@
setup-git-hooks:
@echo "SETUP: Installing Git hooks..."
cp -r .githooks/ .git/hooks/
chmod +x .git/hooks/pre-commit && chmod +x .git/hooks/pre-push && chmod +x .git/hooks/prepare-commit-msg
chmod +x .git/hooks/pre-commit && chmod +x .git/hooks/pre-push && chmod +x .git/hooks/prepare-commit-msg && chmod +x .git/hooks/commit-msg
@echo "SUCCESS: Git hooks installed!"

# Install Node.js dependencies for commit tools
install-commit-tools:
@echo "SETUP: Installing commit tools..."
npm install
@echo "SUCCESS: Commit tools installed!"

# Interactive semantic commit
commit:
@echo "🚀 Starting interactive semantic commit..."
npm run commit

# Validate commit message format
validate-commit:
@echo "VALIDATE: Checking commit message format..."
npm run lint:commit

# Setup complete development environment
setup-dev: install-commit-tools setup-git-hooks
@echo "SUCCESS: Development environment setup complete!"
@echo ""
@echo "🎉 You're all set! Use the following commands:"
@echo " make commit - Create a semantic commit interactively"
@echo " make validate-commit - Validate the last commit message"
@echo " make release - Create a release (maintainers only)"
@echo ""

# Create a release (for maintainers)
release:
@echo "RELEASE: Creating release with release-please..."
npm run release

# Run Code Linting in Docker
docker-lint:
@echo "LINT: Running Pint linter in Docker..."
Expand Down Expand Up @@ -400,6 +431,30 @@ docker-sonarqube-clean:
cd containers && docker-compose -f docker-compose.sonarqube.yml down -v
@echo "SUCCESS: SonarQube data cleaned!"

# Docker-based commit workflow
docker-commit:
@echo "🚀 Starting Docker-based semantic commit..."
docker-compose -f containers/docker-compose.dev.yml exec dev-tools npm run commit

# Setup development environment with Docker
docker-setup-dev:
@echo "SETUP: Setting up development environment with Docker..."
docker-compose -f containers/docker-compose.dev.yml up -d
docker-compose -f containers/docker-compose.dev.yml exec dev-tools npm install
@$(MAKE) setup-git-hooks
@echo "SUCCESS: Docker development environment setup complete!"

# Validate commit in Docker
docker-validate-commit:
@echo "VALIDATE: Checking commit message format in Docker..."
docker-compose -f containers/docker-compose.dev.yml exec dev-tools npm run lint:commit

# Clean up development environment
docker-cleanup-dev:
@echo "CLEANUP: Removing development containers..."
docker-compose -f containers/docker-compose.dev.yml down
@echo "SUCCESS: Development environment cleaned up!"

# Show available commands and usage
help:
@echo "Laravel Blog API - Docker-based Development Environment"
Expand Down
Loading
Loading