Skip to content

Commit a42c8b0

Browse files
authored
Merge pull request #1 from mubbi/feature/commit-semantic-release
Feature/commit semantic release
2 parents 6a62830 + c6c4287 commit a42c8b0

File tree

23 files changed

+4689
-10
lines changed

23 files changed

+4689
-10
lines changed

.githooks/commit-msg

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/bin/sh
2+
3+
# Colors for output
4+
RED='\033[0;31m'
5+
GREEN='\033[0;32m'
6+
YELLOW='\033[1;33m'
7+
NC='\033[0m' # No Color
8+
9+
echo "${YELLOW}🔍 Validating commit message format...${NC}"
10+
11+
# Check if commitlint is available
12+
if ! command -v npx > /dev/null 2>&1; then
13+
echo "${RED}❌ Node.js/npm not available. Please install Node.js to validate commit messages.${NC}"
14+
exit 1
15+
fi
16+
17+
# Check if this is a merge commit
18+
if [ -f .git/MERGE_HEAD ]; then
19+
echo "${GREEN}✅ Merge commit detected, skipping validation${NC}"
20+
exit 0
21+
fi
22+
23+
# Read the commit message
24+
COMMIT_MSG_FILE="$1"
25+
COMMIT_MSG=$(cat "$COMMIT_MSG_FILE")
26+
27+
# Skip empty commits
28+
if [ -z "$COMMIT_MSG" ] || [ "$COMMIT_MSG" = "" ]; then
29+
echo "${RED}❌ Empty commit message${NC}"
30+
exit 1
31+
fi
32+
33+
# Run commitlint
34+
echo "$COMMIT_MSG" | npx commitlint
35+
COMMITLINT_EXIT_CODE=$?
36+
37+
if [ $COMMITLINT_EXIT_CODE -ne 0 ]; then
38+
echo ""
39+
echo "${RED}❌ Commit message does not follow conventional commit format!${NC}"
40+
echo ""
41+
echo "${YELLOW}Expected format:${NC}"
42+
echo " ${GREEN}type(scope): description${NC}"
43+
echo ""
44+
echo "${YELLOW}Valid types:${NC}"
45+
echo " feat: A new feature"
46+
echo " fix: A bug fix"
47+
echo " docs: Documentation only changes"
48+
echo " style: Changes that do not affect the meaning of the code"
49+
echo " refactor: A code change that neither fixes a bug nor adds a feature"
50+
echo " test: Adding missing tests or correcting existing tests"
51+
echo " chore: Changes to the build process or auxiliary tools"
52+
echo " perf: A code change that improves performance"
53+
echo " ci: Changes to CI configuration files and scripts"
54+
echo " build: Changes that affect the build system"
55+
echo " revert: Reverts a previous commit"
56+
echo ""
57+
echo "${YELLOW}Examples:${NC}"
58+
echo " ${GREEN}feat(auth): add user authentication${NC}"
59+
echo " ${GREEN}fix(api): resolve validation error in user endpoint${NC}"
60+
echo " ${GREEN}docs: update API documentation${NC}"
61+
echo ""
62+
echo "${YELLOW}💡 Use '${GREEN}npm run commit${NC}${YELLOW}' or '${GREEN}make commit${NC}${YELLOW}' for interactive commit creation!${NC}"
63+
exit 1
64+
fi
65+
66+
echo "${GREEN}✅ Commit message format is valid${NC}"
67+
exit 0

.githooks/prepare-commit-msg

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
11
#!/bin/sh
22

3-
BRANCH_NAME=$(git branch --show-current)
3+
# Check if this is a merge commit or revert
4+
if [ "$2" = "merge" ] || [ "$2" = "squash" ] || [ "$2" = "commit" ]; then
5+
exit 0
6+
fi
7+
8+
# Check if commitizen is available
9+
if ! command -v npx > /dev/null 2>&1; then
10+
echo "Warning: Node.js/npm not available for commit message validation"
11+
exit 0
12+
fi
13+
14+
# Skip if already has conventional commit format
15+
COMMIT_MSG=$(cat "$1")
16+
if echo "$COMMIT_MSG" | grep -qE '^(feat|fix|docs|style|refactor|test|chore|perf|ci|build|revert)(\(.+\))?: .+'; then
17+
exit 0
18+
fi
419

5-
if [ -n "$BRANCH_NAME" ]; then
6-
echo "[$BRANCH_NAME] $(cat "$1")" > "$1"
20+
# Interactive commit with commitizen if not automated
21+
if [ -t 1 ]; then
22+
echo "🚨 Interactive commit detected. Please use 'npm run commit' or 'make commit' for proper semantic commits!"
23+
echo "Your commit message will be validated against conventional commit standards."
24+
exit 1
725
fi

.github/workflows/ci.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main, develop ]
8+
9+
jobs:
10+
validate-commits:
11+
runs-on: ubuntu-latest
12+
if: github.event_name == 'pull_request'
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Setup Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: '20'
23+
cache: 'npm'
24+
25+
- name: Install dependencies
26+
run: npm ci
27+
28+
- name: Validate commit messages
29+
run: |
30+
# Validate all commits in the PR
31+
npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Release Please
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
jobs:
13+
release-please:
14+
runs-on: ubuntu-latest
15+
outputs:
16+
release_created: ${{ steps.release.outputs.release_created }}
17+
tag_name: ${{ steps.release.outputs.tag_name }}
18+
steps:
19+
- name: Release Please
20+
id: release
21+
uses: google-github-actions/release-please-action@v4
22+
with:
23+
release-type: simple
24+
config-file: release-please-config.json
25+
manifest-file: .release-please-manifest.json
26+
27+
publish-artifacts:
28+
runs-on: ubuntu-latest
29+
needs: release-please
30+
if: ${{ needs.release-please.outputs.release_created }}
31+
steps:
32+
- name: Checkout
33+
uses: actions/checkout@v4
34+
35+
- name: Set up Docker Buildx
36+
uses: docker/setup-buildx-action@v3

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@
2424
/storage/*.key
2525
/storage/pail
2626
/vendor
27+
28+
# Commit tools
29+
node_modules/
30+
npm-debug.log*
31+
.npm
32+
.husky/_/
33+
34+
# Release artifacts
35+
CHANGELOG.md
36+
2737
Homestead.json
2838
Homestead.yaml
2939
Thumbs.db

.release-please-manifest.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
".": "1.0.0"
3+
}

Makefile

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,40 @@
22
setup-git-hooks:
33
@echo "SETUP: Installing Git hooks..."
44
cp -r .githooks/ .git/hooks/
5-
chmod +x .git/hooks/pre-commit && chmod +x .git/hooks/pre-push && chmod +x .git/hooks/prepare-commit-msg
5+
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
66
@echo "SUCCESS: Git hooks installed!"
77

8+
# Install Node.js dependencies for commit tools
9+
install-commit-tools:
10+
@echo "SETUP: Installing commit tools..."
11+
npm install
12+
@echo "SUCCESS: Commit tools installed!"
13+
14+
# Interactive semantic commit
15+
commit:
16+
@echo "🚀 Starting interactive semantic commit..."
17+
npm run commit
18+
19+
# Validate commit message format
20+
validate-commit:
21+
@echo "VALIDATE: Checking commit message format..."
22+
npm run lint:commit
23+
24+
# Setup complete development environment
25+
setup-dev: install-commit-tools setup-git-hooks
26+
@echo "SUCCESS: Development environment setup complete!"
27+
@echo ""
28+
@echo "🎉 You're all set! Use the following commands:"
29+
@echo " make commit - Create a semantic commit interactively"
30+
@echo " make validate-commit - Validate the last commit message"
31+
@echo " make release - Create a release (maintainers only)"
32+
@echo ""
33+
34+
# Create a release (for maintainers)
35+
release:
36+
@echo "RELEASE: Creating release with release-please..."
37+
npm run release
38+
839
# Run Code Linting in Docker
940
docker-lint:
1041
@echo "LINT: Running Pint linter in Docker..."
@@ -400,6 +431,30 @@ docker-sonarqube-clean:
400431
cd containers && docker-compose -f docker-compose.sonarqube.yml down -v
401432
@echo "SUCCESS: SonarQube data cleaned!"
402433

434+
# Docker-based commit workflow
435+
docker-commit:
436+
@echo "🚀 Starting Docker-based semantic commit..."
437+
docker-compose -f containers/docker-compose.dev.yml exec dev-tools npm run commit
438+
439+
# Setup development environment with Docker
440+
docker-setup-dev:
441+
@echo "SETUP: Setting up development environment with Docker..."
442+
docker-compose -f containers/docker-compose.dev.yml up -d
443+
docker-compose -f containers/docker-compose.dev.yml exec dev-tools npm install
444+
@$(MAKE) setup-git-hooks
445+
@echo "SUCCESS: Docker development environment setup complete!"
446+
447+
# Validate commit in Docker
448+
docker-validate-commit:
449+
@echo "VALIDATE: Checking commit message format in Docker..."
450+
docker-compose -f containers/docker-compose.dev.yml exec dev-tools npm run lint:commit
451+
452+
# Clean up development environment
453+
docker-cleanup-dev:
454+
@echo "CLEANUP: Removing development containers..."
455+
docker-compose -f containers/docker-compose.dev.yml down
456+
@echo "SUCCESS: Development environment cleaned up!"
457+
403458
# Show available commands and usage
404459
help:
405460
@echo "Laravel Blog API - Docker-based Development Environment"

0 commit comments

Comments
 (0)