Git setup and code quality
note
Replace gitlab.reids.net.au with your server name.
Initial repository setup
# Initialise new Git repo with main branch
git init
git checkout -b main
git add .
git commit -m "Initial commit"
GitLab CLI setup
Install glab via brew on mac
brew install glab
Configure glab
# Disable telemetry
glab config set -g disable_telemetry true
# Check status
glab auth status --hostname gitlab.reids.net.au
# Edit config and remove github section
glab config edit
# Check status with hostname
glab auth status
# Set default host
glab config set -g host gitlab.reids.net.au
# Create repository
glab repo create muppit-apps/fitness-app --private
Configure git remote
# Git from project folder
git remote set-url origin https://gitlab.reids.net.au/muppit-apps/fitness-app.git
git push -u origin main
# Confirm the remote
git remote -v
glab repo view
Code quality tools
Foundation phase 1.
Overview
Implemented comprehensive code quality system as part of foundation phase 1:
- Prettier for consistent code formatting.
- ESLint for code linting and error detection.
- Husky for Git hooks enforcement.
- lint-staged for efficient pre-commit checks.
Dependencies installed
npm install --save-dev prettier husky lint-staged @typescript-eslint/eslint-plugin @typescript-eslint/parser @eslint/eslintrc
Configuration Files Created
.prettierrc- Prettier formatting rules..prettierignore- Files excluded from formatting.eslint.config.js- Modern ESLint configuration (v9 format)..husky/pre-commit- Pre-commit hook (type checking + linting)..husky/commit-msg- Commit message validation hook.
Available scripts
# Code formatting
npm run format # Format all files with Prettier
npm run format:check # Check formatting without changes
# Linting
npm run lint # Run ESLint
npm run lint:fix # Fix ESLint issues automatically
# Type checking
npm run typecheck # Run TypeScript compiler checks
Git hooks behavior
Pre-commit Hook:
- Runs TypeScript type checking.
- Formats staged files with Prettier.
- Runs ESLint on staged files.
- Only allows commit if all checks pass.
Commit Message Hook:
- Enforces conventional commit message format.
- Required format:
type(scope?): description. - Valid types:
build,chore,ci,docs,feat,fix,perf,refactor,revert,style,test.
Example valid commit messages
feat(auth): add user authentication system
fix(api): resolve login endpoint timeout
docs(readme): update installation instructions
style(components): format user profile component
chore(deps): update dependencies
Bypass hooks
Emergency only.
git commit -m "feat: urgent fix" --no-verify
Note: The --no-verify flag should only be used in emergency situations as it bypasses all quality checks.
GitLab CI/CD pipeline implementation
Pipeline architecture
5-Stage Automated Pipeline:
- .pre - Dependency installation with native module build tools.
- validate - Type checking, formatting, linting, documentation sync.
- test - Jest unit tests with PostgreSQL database and coverage reporting.
- quality - Export validation, dependency audit, React hooks, bundle analysis.
- security - npm security audit for vulnerabilities.
Environment configuration
Base Image: node:20 (Debian-based)
- Switched from Alpine Linux for native binary compatibility.
- Includes Python, make, g++ for native module compilation.
- Better support for packages like lightningcss (TailwindCSS v4).
Smart Execution Rules:
- Skips on documentation-only changes (
docs:commit prefix). - Skips on markdown-only changes (
*.md,memory_bank/**/*). - Caches node_modules for faster builds.
- Runs automatically on push, merge requests, and web triggers.
CI/CD troubleshooting history
Major Issues Resolved:
-
Node.js Version Compatibility
- Issue: Package engine warnings for lint-staged, commander.
- Solution: Upgraded from Node.js 18 → 20.
-
Native Module Compilation
- Issue: Missing Python/build tools for node-gyp.
- Solution: Added apt-get install python3 make g++.
-
TailwindCSS v4 Binary Issues
- Issue: lightningcss native binary resolution failures.
- Solution: Downgraded to TailwindCSS v3 for CI stability.
- Future: Document v4 migration path with proper binary handling.
-
Documentation Sync Failures
- Issue: grep commands failing in CI environment.
- Solution: Replaced shell commands with Node.js file operations.
-
Jest Coverage Configuration
- Issue: Unrealistic 70% coverage thresholds causing failures.
- Solution: Focused coverage on tested areas, disabled global thresholds.
-
Prettier Automation Gaps
- Issue: .mjs files not included in lint-staged configuration.
- Solution: Extended patterns to include .mjs, .cjs files.
Pipeline artifacts
Generated Reports:
- JUnit XML test results for GitLab test reporting.
- Cobertura coverage reports for merge request integration.
- LCOV coverage data for local development.
- Bundle analysis results (when enabled).
Coverage Configuration:
- Focuses on
src/components/**andsrc/lib/**directories. - Excludes API routes and server workers from coverage calculation.
- Generates multiple report formats for different tools.
Performance optimisations
Caching Strategy:
- Node.js dependency caching with package-lock.json fingerprinting.
- Artifact caching for test results and coverage reports.
- Smart cache invalidation on dependency changes.
Parallel Execution:
- Validation stage jobs run in parallel for faster feedback.
- Quality stage jobs run concurrently for efficiency.
- Total pipeline completion time: ~5-10 minutes.