lechnerio-git-hooks 1.1.6 → 1.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +82 -0
- package/hooks/post-commit +104 -2
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# lechnerio-git-hooks
|
|
2
|
+
|
|
3
|
+
Shared git hooks for all lechnerio projects. Install once, get commit linting, lint-staged, version bumping, and changelog generation.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add -D lechnerio-git-hooks
|
|
9
|
+
pnpm approve-builds
|
|
10
|
+
pnpm install
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
For pnpm workspaces, add the `-w` flag:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add -wD lechnerio-git-hooks
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## What it does
|
|
20
|
+
|
|
21
|
+
On install, the package automatically:
|
|
22
|
+
|
|
23
|
+
- Copies `pre-commit`, `commit-msg`, and `post-commit` hooks into `.husky/`
|
|
24
|
+
- Copies `generate-changelog.mjs` into `scripts/`
|
|
25
|
+
- Copies `commitlint.config.js` and `.lintstagedrc.js` into the project root
|
|
26
|
+
- Adds a `lint-staged` script to `package.json`
|
|
27
|
+
- Configures git to use `.husky/` as the hooks path
|
|
28
|
+
|
|
29
|
+
## Hooks
|
|
30
|
+
|
|
31
|
+
| Hook | What it does |
|
|
32
|
+
| ------------- | -------------------------------------------------------------------------------------------- |
|
|
33
|
+
| `pre-commit` | Runs lint-staged (eslint --fix + prettier) |
|
|
34
|
+
| `commit-msg` | Enforces conventional commits via commitlint |
|
|
35
|
+
| `post-commit` | Interactive version bump (subtle/patch/minor/major), changelog generation, push/merge prompt |
|
|
36
|
+
|
|
37
|
+
## Peer dependencies (auto-installed)
|
|
38
|
+
|
|
39
|
+
- `@commitlint/cli`
|
|
40
|
+
- `@commitlint/config-conventional`
|
|
41
|
+
- `lint-staged`
|
|
42
|
+
|
|
43
|
+
## Project requirements
|
|
44
|
+
|
|
45
|
+
These are **not** included and must be installed by the project:
|
|
46
|
+
|
|
47
|
+
- `eslint`
|
|
48
|
+
- `prettier`
|
|
49
|
+
|
|
50
|
+
## Environment variables
|
|
51
|
+
|
|
52
|
+
For non-interactive usage (CI, scripts):
|
|
53
|
+
|
|
54
|
+
| Variable | Values |
|
|
55
|
+
| -------------- | --------------------------------------------------------------- |
|
|
56
|
+
| `VERSION_BUMP` | `1` = subtle, `2` = patch, `3` = minor, `4` = major, `0` = skip |
|
|
57
|
+
| `POST_ACTION` | `1` = push, `2` = merge to main, `0` = skip |
|
|
58
|
+
|
|
59
|
+
## Update
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
pnpm update lechnerio-git-hooks
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Removing old setup
|
|
66
|
+
|
|
67
|
+
If migrating from a manual setup, remove these before installing:
|
|
68
|
+
|
|
69
|
+
```powershell
|
|
70
|
+
Remove-Item .husky\post-commit
|
|
71
|
+
Remove-Item .husky\pre-commit
|
|
72
|
+
Remove-Item .husky\commit-msg
|
|
73
|
+
Remove-Item commitlint.config.js
|
|
74
|
+
Remove-Item .lintstagedrc.js
|
|
75
|
+
Remove-Item scripts\generate-changelog.mjs
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Also remove these from `devDependencies` if present:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
pnpm remove @commitlint/cli @commitlint/config-conventional husky lint-staged
|
|
82
|
+
```
|
package/hooks/post-commit
CHANGED
|
@@ -99,9 +99,10 @@ if [ "$files_changed" -eq 0 ] || [ -z "$lines_changed" ]; then
|
|
|
99
99
|
echo
|
|
100
100
|
echo "1) Push to GitHub"
|
|
101
101
|
echo "2) Merge to Main"
|
|
102
|
+
echo "3) Merge to Main + Push"
|
|
102
103
|
echo -e "${GRAY}0) None${NC}"
|
|
103
104
|
echo
|
|
104
|
-
echo -n "Select option (1-
|
|
105
|
+
echo -n "Select option (1-3, Enter for Default or 0 to skip): "
|
|
105
106
|
read -r choice
|
|
106
107
|
choice=${choice:-1}
|
|
107
108
|
else
|
|
@@ -140,6 +141,56 @@ if [ "$files_changed" -eq 0 ] || [ -z "$lines_changed" ]; then
|
|
|
140
141
|
fi
|
|
141
142
|
fi
|
|
142
143
|
;;
|
|
144
|
+
3)
|
|
145
|
+
echo -e "${YELLOW}🔄 Merging to main + pushing...${NC}"
|
|
146
|
+
if [ "$DRY_RUN" = "true" ]; then
|
|
147
|
+
echo -e "${YELLOW}[DRY RUN] Would execute: git push --follow-tags && git push --tags${NC}"
|
|
148
|
+
echo -e "${YELLOW}[DRY RUN] Would execute: git checkout main && git pull && git merge $(git branch --show-current) && git push${NC}"
|
|
149
|
+
echo -e "${YELLOW}[DRY RUN] Would execute: git checkout $(git branch --show-current)${NC}"
|
|
150
|
+
else
|
|
151
|
+
current_branch=$(git branch --show-current)
|
|
152
|
+
_merge_push_ok=true
|
|
153
|
+
echo -e "${YELLOW}✈️ Pushing ${current_branch}...${NC}"
|
|
154
|
+
if ! git push --follow-tags || ! git push --tags; then
|
|
155
|
+
echo -e "${RED}❌ Failed to push ${current_branch}${NC}"
|
|
156
|
+
_merge_push_ok=false
|
|
157
|
+
fi
|
|
158
|
+
if [ "$_merge_push_ok" = true ]; then
|
|
159
|
+
echo -e "${GREEN}✅ Pushed ${current_branch}${NC}"
|
|
160
|
+
if ! git checkout main; then
|
|
161
|
+
echo -e "${RED}❌ Failed to checkout main${NC}"
|
|
162
|
+
_merge_push_ok=false
|
|
163
|
+
fi
|
|
164
|
+
fi
|
|
165
|
+
if [ "$_merge_push_ok" = true ]; then
|
|
166
|
+
if ! git pull; then
|
|
167
|
+
echo -e "${RED}❌ Failed to pull main${NC}"
|
|
168
|
+
git checkout "$current_branch"
|
|
169
|
+
_merge_push_ok=false
|
|
170
|
+
fi
|
|
171
|
+
fi
|
|
172
|
+
if [ "$_merge_push_ok" = true ]; then
|
|
173
|
+
if ! git merge "$current_branch"; then
|
|
174
|
+
echo -e "${RED}❌ Failed to merge ${current_branch} into main${NC}"
|
|
175
|
+
git checkout "$current_branch"
|
|
176
|
+
_merge_push_ok=false
|
|
177
|
+
fi
|
|
178
|
+
fi
|
|
179
|
+
if [ "$_merge_push_ok" = true ]; then
|
|
180
|
+
echo -e "${GREEN}✅ Merged ${current_branch} into main${NC}"
|
|
181
|
+
if ! git push; then
|
|
182
|
+
echo -e "${RED}❌ Failed to push main${NC}"
|
|
183
|
+
git checkout "$current_branch"
|
|
184
|
+
_merge_push_ok=false
|
|
185
|
+
fi
|
|
186
|
+
fi
|
|
187
|
+
if [ "$_merge_push_ok" = true ]; then
|
|
188
|
+
echo -e "${GREEN}✅ Pushed main${NC}"
|
|
189
|
+
git checkout "$current_branch"
|
|
190
|
+
echo -e "${GREEN}✅ Back on ${current_branch}${NC}"
|
|
191
|
+
fi
|
|
192
|
+
fi
|
|
193
|
+
;;
|
|
143
194
|
0)
|
|
144
195
|
echo -e "${YELLOW}⏭️ Skipping additional actions${NC}"
|
|
145
196
|
;;
|
|
@@ -239,9 +290,10 @@ elif exec < /dev/tty 2>/dev/null; then
|
|
|
239
290
|
echo
|
|
240
291
|
echo -e "1) Push to GitHub ${YELLOW}(default)${NC}"
|
|
241
292
|
echo "2) Merge to Main"
|
|
293
|
+
echo "3) Merge to Main + Push"
|
|
242
294
|
echo -e "${GRAY}0) None${NC}"
|
|
243
295
|
echo
|
|
244
|
-
echo -n "Select option (1-
|
|
296
|
+
echo -n "Select option (1-3, Enter for Default or 0 to skip): "
|
|
245
297
|
read -r choice
|
|
246
298
|
choice=${choice:-1}
|
|
247
299
|
else
|
|
@@ -281,6 +333,56 @@ case $choice in
|
|
|
281
333
|
fi
|
|
282
334
|
fi
|
|
283
335
|
;;
|
|
336
|
+
3)
|
|
337
|
+
echo -e "${YELLOW}🔄 Merging to main + pushing...${NC}"
|
|
338
|
+
if [ "$DRY_RUN" = "true" ]; then
|
|
339
|
+
echo -e "${YELLOW}[DRY RUN] Would execute: git push --follow-tags && git push --tags${NC}"
|
|
340
|
+
echo -e "${YELLOW}[DRY RUN] Would execute: git checkout main && git pull && git merge $(git branch --show-current) && git push${NC}"
|
|
341
|
+
echo -e "${YELLOW}[DRY RUN] Would execute: git checkout $(git branch --show-current)${NC}"
|
|
342
|
+
else
|
|
343
|
+
current_branch=$(git branch --show-current)
|
|
344
|
+
_merge_push_ok=true
|
|
345
|
+
echo -e "${YELLOW}✈️ Pushing ${current_branch}...${NC}"
|
|
346
|
+
if ! git push --follow-tags || ! git push --tags; then
|
|
347
|
+
echo -e "${RED}❌ Failed to push ${current_branch}${NC}"
|
|
348
|
+
_merge_push_ok=false
|
|
349
|
+
fi
|
|
350
|
+
if [ "$_merge_push_ok" = true ]; then
|
|
351
|
+
echo -e "${GREEN}✅ Pushed ${current_branch}${NC}"
|
|
352
|
+
if ! git checkout main; then
|
|
353
|
+
echo -e "${RED}❌ Failed to checkout main${NC}"
|
|
354
|
+
_merge_push_ok=false
|
|
355
|
+
fi
|
|
356
|
+
fi
|
|
357
|
+
if [ "$_merge_push_ok" = true ]; then
|
|
358
|
+
if ! git pull; then
|
|
359
|
+
echo -e "${RED}❌ Failed to pull main${NC}"
|
|
360
|
+
git checkout "$current_branch"
|
|
361
|
+
_merge_push_ok=false
|
|
362
|
+
fi
|
|
363
|
+
fi
|
|
364
|
+
if [ "$_merge_push_ok" = true ]; then
|
|
365
|
+
if ! git merge "$current_branch"; then
|
|
366
|
+
echo -e "${RED}❌ Failed to merge ${current_branch} into main${NC}"
|
|
367
|
+
git checkout "$current_branch"
|
|
368
|
+
_merge_push_ok=false
|
|
369
|
+
fi
|
|
370
|
+
fi
|
|
371
|
+
if [ "$_merge_push_ok" = true ]; then
|
|
372
|
+
echo -e "${GREEN}✅ Merged ${current_branch} into main${NC}"
|
|
373
|
+
if ! git push; then
|
|
374
|
+
echo -e "${RED}❌ Failed to push main${NC}"
|
|
375
|
+
git checkout "$current_branch"
|
|
376
|
+
_merge_push_ok=false
|
|
377
|
+
fi
|
|
378
|
+
fi
|
|
379
|
+
if [ "$_merge_push_ok" = true ]; then
|
|
380
|
+
echo -e "${GREEN}✅ Pushed main${NC}"
|
|
381
|
+
git checkout "$current_branch"
|
|
382
|
+
echo -e "${GREEN}✅ Back on ${current_branch}${NC}"
|
|
383
|
+
fi
|
|
384
|
+
fi
|
|
385
|
+
;;
|
|
284
386
|
0)
|
|
285
387
|
echo -e "${YELLOW}⏭️ Skipping additional actions${NC}"
|
|
286
388
|
;;
|