Skip to content

Commit 9462478

Browse files
committed
Add husky for branch protection rules, update GitHub Actions
1 parent 19cefa1 commit 9462478

10 files changed

Lines changed: 222 additions & 29 deletions

‎.github/pull_request_template.md‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
## Description
2+
3+
<!-- Provide a brief description of the changes in this PR -->
4+
5+
## Type of Change
6+
7+
<!-- Mark the relevant option with an "x" -->
8+
9+
- [ ] 🐛 Bug fix (bugfix/*)
10+
- [ ] 🔥 Hot fix (hotfix/*)
11+
- [ ] ✨ New feature (feature/*)
12+
- [ ] 🏗️ Infrastructure (infrastructure/*)
13+
- [ ] 📝 Content update (content/*)
14+
- [ ] 📚 Documentation
15+
- [ ] 🎨 Style/UI change
16+
- [ ] ♻️ Code refactoring
17+
18+
## Changes Made
19+
20+
<!-- List the main changes in this PR -->
21+
22+
-
23+
-
24+
-
25+
26+
## Related Issues
27+
28+
<!-- Link to related issues, e.g., Closes #123, Fixes #456 -->
29+
30+
Closes #
31+
32+
## Testing
33+
34+
<!-- Describe the testing you've done -->
35+
36+
- [ ] Unit tests pass locally (`npm run test:unit`)
37+
- [ ] E2E tests pass locally (`npm run test:e2e:ready`)
38+
- [ ] Linting passes (`npm run lint`)
39+
- [ ] Build succeeds (`npm run build`)
40+
- [ ] Manually tested in browser
41+
42+
## Screenshots (if applicable)
43+
44+
<!-- Add screenshots for UI changes -->
45+
46+
## Checklist
47+
48+
- [ ] My branch name follows the conventions (feature/*, bugfix/*, etc.)
49+
- [ ] My code follows the project's coding standards
50+
- [ ] I have performed a self-review of my code
51+
- [ ] I have commented my code, particularly in hard-to-understand areas
52+
- [ ] I have made corresponding changes to the documentation
53+
- [ ] My changes generate no new warnings or errors
54+
- [ ] I have added tests that prove my fix is effective or that my feature works
55+
- [ ] New and existing unit tests pass locally with my changes
56+
- [ ] Any dependent changes have been merged and published
57+
58+
## Additional Notes
59+
60+
<!-- Any additional information that reviewers should know -->
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Branch Protection
2+
3+
on:
4+
pull_request:
5+
types: [opened, edited, synchronize, reopened]
6+
7+
jobs:
8+
check-branch-name:
9+
name: Validate Branch Name
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Check branch naming convention
13+
run: |
14+
BRANCH_NAME="${{ github.head_ref }}"
15+
16+
# Valid patterns: bugfix/, hotfix/, feature/, infrastructure/, content/
17+
if [[ ! $BRANCH_NAME =~ ^(bugfix|hotfix|feature|infrastructure|content)/[a-z0-9-]+$ ]]; then
18+
echo "❌ Invalid branch name: $BRANCH_NAME"
19+
echo ""
20+
echo "Branch names must follow one of these patterns:"
21+
echo " - bugfix/<description> (e.g., bugfix/fix-navigation-menu)"
22+
echo " - hotfix/<description> (e.g., hotfix/critical-security-patch)"
23+
echo " - feature/<description> (e.g., feature/add-contact-form)"
24+
echo " - infrastructure/<desc> (e.g., infrastructure/setup-ci)"
25+
echo " - content/<description> (e.g., content/update-about-page)"
26+
echo ""
27+
echo "Use lowercase letters, numbers, and hyphens only."
28+
exit 1
29+
fi
30+
31+
echo "✅ Branch name is valid: $BRANCH_NAME"
32+
33+
check-pr-target:
34+
name: Verify PR Target
35+
runs-on: ubuntu-latest
36+
steps:
37+
- name: Ensure PR targets main
38+
run: |
39+
TARGET_BRANCH="${{ github.base_ref }}"
40+
41+
if [[ "$TARGET_BRANCH" != "main" ]]; then
42+
echo "⚠️ Warning: PR is targeting '$TARGET_BRANCH' instead of 'main'"
43+
echo "This is allowed, but make sure this is intentional."
44+
else
45+
echo "✅ PR correctly targets 'main' branch"
46+
fi

‎.github/workflows/build-and-test.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Setup Node.js
2020
uses: actions/setup-node@v4
2121
with:
22-
node-version: "20.x"
22+
node-version: "22.x"
2323
cache: 'npm'
2424

2525
- name: Install dependencies

‎.github/workflows/playwright.yml‎

Lines changed: 0 additions & 27 deletions
This file was deleted.

‎.husky/pre-commit‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
# Run unit tests (fast feedback)
4+
nvm use default && npm run test:unit
5+
6+
# Verify branch naming convention
7+
.husky/scripts/check-branch-name.sh
8+
9+
# Prevent commits directly to main
10+
.husky/scripts/prevent-main-commits.sh
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/sh
2+
3+
# Get current branch name
4+
branch=$(git symbolic-ref --short HEAD)
5+
6+
# Define valid branch name patterns
7+
valid_patterns="^(bugfix|hotfix|feature|infrastructure|content)\/[a-z0-9-]+$"
8+
9+
# Allow main and develop branches (for merges)
10+
if [ "$branch" = "main" ] || [ "$branch" = "develop" ]; then
11+
exit 0
12+
fi
13+
14+
# Check if branch name matches valid patterns
15+
if ! echo "$branch" | grep -Eq "$valid_patterns"; then
16+
echo "❌ Invalid branch name: $branch"
17+
echo ""
18+
echo "Branch names must follow one of these patterns:"
19+
echo " - bugfix/<description> (e.g., bugfix/fix-navigation-menu)"
20+
echo " - hotfix/<description> (e.g., hotfix/critical-security-patch)"
21+
echo " - feature/<description> (e.g., feature/add-contact-form)"
22+
echo " - infrastructure/<desc> (e.g., infrastructure/setup-ci)"
23+
echo " - content/<description> (e.g., content/update-about-page)"
24+
echo ""
25+
echo "Use lowercase letters, numbers, and hyphens only."
26+
echo ""
27+
exit 1
28+
fi
29+
30+
exit 0
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
3+
# Get current branch name
4+
branch=$(git symbolic-ref --short HEAD)
5+
6+
# Prevent direct commits to main
7+
if [ "$branch" = "main" ]; then
8+
echo "❌ Direct commits to 'main' branch are not allowed!"
9+
echo ""
10+
echo "Please follow this workflow:"
11+
echo " 1. Create a new branch:"
12+
echo " git checkout -b feature/your-feature-name"
13+
echo ""
14+
echo " 2. Make your changes and commit them"
15+
echo ""
16+
echo " 3. Push your branch and create a Pull Request:"
17+
echo " git push -u origin feature/your-feature-name"
18+
echo ""
19+
echo "Valid branch prefixes: bugfix/, hotfix/, feature/, infrastructure/, content/"
20+
echo ""
21+
exit 1
22+
fi
23+
24+
exit 0

‎README.md‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,37 @@
44

55
@TODO: See here for utility components like shortcodes: <https://docs.astro.build/en/reference/api-reference/#astroslotsrender>
66

7+
## Contributing & Git Workflow
8+
9+
This repository uses branch protection and automated quality checks. See [docs/GIT_WORKFLOW.md](./docs/GIT_WORKFLOW.md) for complete details.
10+
11+
**Quick Start:**
12+
13+
```bash
14+
# Create a feature branch (required - cannot commit to main)
15+
git checkout -b feature/your-feature-name
16+
17+
# Make changes and commit (hooks will run automatically)
18+
git commit -m "Your message"
19+
20+
# Push and create a Pull Request
21+
git push -u origin feature/your-feature-name
22+
```
23+
24+
**Branch Naming:**
25+
26+
- `feature/*` - New features
27+
- `bugfix/*` - Bug fixes
28+
- `hotfix/*` - Critical production fixes
29+
- `infrastructure/*` - DevOps/CI/CD changes
30+
- `content/*` - Content updates
31+
32+
**Pre-commit Checks:**
33+
34+
- Unit tests must pass
35+
- Branch name must follow conventions
36+
- Cannot commit directly to main
37+
738
## Coding Standards
839

940
### Component Architecture

‎package-lock.json‎

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@
5959
"test:e2e:ui": "NODE_ENV=test npx playwright test --ui",
6060
"test:e2e:wip": "NODE_ENV=test npx playwright test --grep @wip",
6161
"test:unit": "NODE_ENV=test npx vitest run",
62-
"upgrade": "npx @astrojs/upgrade"
62+
"upgrade": "npx @astrojs/upgrade",
63+
"prepare": "husky"
6364
},
6465
"dependencies": {
6566
"@astrojs/check": "0.9.4",
@@ -150,6 +151,7 @@
150151
"eslint-plugin-yml": "1.19.0",
151152
"happy-dom": "^20.0.2",
152153
"html-element-attributes": "^3.5.0",
154+
"husky": "^9.1.7",
153155
"is-whitespace-character": "^2.0.1",
154156
"jsdom": "^27.0.0",
155157
"md-attr-parser": "^1.3.0",

0 commit comments

Comments
 (0)