Skip to content

Commit d9ba351

Browse files
committed
chore: setup git hooks
1 parent a45834e commit d9ba351

File tree

11 files changed

+248
-10
lines changed

11 files changed

+248
-10
lines changed

.gitattributes

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
# Don't allow people to merge changes to these generated files, because the result
22
# may be invalid. You need to run "rush update" again.
3-
pnpm-lock.yaml merge=text
4-
shrinkwrap.yaml merge=binary
5-
npm-shrinkwrap.json merge=binary
6-
yarn.lock merge=binary
3+
pnpm-lock.yaml merge=ours
4+
shrinkwrap.yaml merge=binary
5+
npm-shrinkwrap.json merge=binary
6+
yarn.lock merge=binary
7+
# 不做自动解决冲突,暴露冲突后由开发者自行 rush pull-idl 做更新
8+
# packages/arch/idl/bam.log.json merge=ours
79

810
# Rush's JSON config files use JavaScript-style code comments. The rule below prevents pedantic
911
# syntax highlighters such as GitHub's from highlighting these comments as errors. Your text editor
1012
# may also require a special configuration to allow comments in JSON.
1113
#
1214
# For more information, see this issue: https://github.com/microsoft/rushstack/issues/1088
1315
#
14-
*.json linguist-language=JSON-with-Comments
16+
*.json linguist-language=JSON-with-Comments

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
registry=https://registry.npmjs.org

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lts/hydrogen

.prettierignore

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Logs
2+
*.log
3+
npm-debug.log*
4+
yarn-debug.log*
5+
yarn-error.log*
6+
7+
# Runtime data
8+
*.pid
9+
*.seed
10+
*.pid.lock
11+
12+
# Directory for instrumented libs generated by jscoverage/JSCover
13+
lib-cov
14+
15+
# Coverage directory used by tools like istanbul
16+
coverage
17+
18+
# nyc test coverage
19+
.nyc_output
20+
21+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
22+
.grunt
23+
24+
# Bower dependency directory (https://bower.io/)
25+
bower_components
26+
27+
# node-waf configuration
28+
.lock-wscript
29+
30+
# Compiled binary addons (https://nodejs.org/api/addons.html)
31+
build/Release
32+
33+
# Dependency directories
34+
node_modules/
35+
jspm_packages/
36+
37+
# Optional npm cache directory
38+
.npm
39+
40+
# Optional eslint cache
41+
.eslintcache
42+
43+
# Optional REPL history
44+
.node_repl_history
45+
46+
# Output of 'npm pack'
47+
*.tgz
48+
49+
# Yarn Integrity file
50+
.yarn-integrity
51+
52+
# dotenv environment variables file
53+
.env
54+
55+
# next.js build output
56+
.next
57+
58+
# OS X temporary files
59+
.DS_Store
60+
61+
# Rush temporary files
62+
common/deploy/
63+
common/temp/
64+
common/autoinstallers/*/.npmrc
65+
common/changes/
66+
common/scripts/
67+
common/config/**/pnpm-lock.yaml
68+
common/_templates/
69+
**/.rush/temp/
70+
71+
# Heft
72+
.heft
73+
74+
# PIA temp files
75+
.pia
76+
77+
# Build assets
78+
dist
79+
packages/speedy-plugin-pia/lib
80+
81+
# Rush files
82+
CHANGELOG.*
83+
84+
# Emo files
85+
.eden-mono
86+
87+
# Package manager files
88+
pnpm-lock.yaml
89+
yarn.lock
90+
package-lock.json
91+
shrinkwrap.json
92+
.pnpm-store/
93+
94+
# Build outputs
95+
lib
96+
apps/bot/routes_metadata/nestedRoutes.json
97+
98+
# Prettier reformats code blocks inside Markdown, which affects rendered output
99+
*.md
100+
101+
vendors/**/index.d.ts
102+
vendors/**/index.js
103+
104+
tests/configs/src/errors/**
105+
106+
apps/bot/src/typing/env/**

.prettierrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Do not modify this file
2+
module.exports = {
3+
...require('./config/eslint-config/.prettierrc.js'),
4+
};

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Will Be Done

common/git-hooks/commit-msg.sample renamed to common/git-hooks/commit-msg

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/bin/bash
22
#
33
# This is an example Git hook for use with Rush. To enable this hook, rename this file
44
# to "commit-msg" and then run "rush install", which will copy it from common/git-hooks
@@ -18,8 +18,20 @@
1818

1919
# This example enforces that commit message should contain a minimum amount of
2020
# description text.
21-
if [ `cat $1 | wc -w` -lt 3 ]; then
22-
echo ""
23-
echo "Invalid commit message: The message must contain at least 3 words."
24-
exit 1
21+
# if [ `cat $1 | wc -w` -lt 3 ]; then
22+
# echo ""
23+
# echo "Invalid commit message: The message must contain at least 3 words."
24+
# exit 1
25+
# fi
26+
27+
# rebase 过程中分支名格式为 (no branch, rebasing chore/replace-rushtool)
28+
# 正常提交时分支名格式为 chore/replace-rushtool
29+
BRANCH_NAME=$(git branch | grep '*' | sed 's/* //')
30+
# 如果匹配到 rebase 格式的输出,认为是在rebase ,则跳过自动推送
31+
if [[ "X${BRANCH_NAME}" == "X(no branch"* ]]; then
32+
exit
33+
else
34+
node common/scripts/install-run-rush.js -q commitlint \
35+
--config common/autoinstallers/rush-commitlint/commitlint.config.js \
36+
--edit "$1" || exit 1
2537
fi

common/git-hooks/post-checkout

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
# avoid conflicts in pnpm lock
3+
# https://7tonshark.com/posts/avoid-conflicts-in-pnpm-lock/
4+
git config merge.ours.driver true

common/git-hooks/pre-commit

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
# Called by "git commit" with no arguments. The hook should
3+
# exit with non-zero status after issuing an appropriate message if
4+
# it wants to stop the commit.
5+
6+
# Invoke the "rush prettier" custom command to reformat files whenever they
7+
# are committed. The command is defined in common/config/rush/command-line.json
8+
# and uses the "rush-lint-staged" autoinstaller.
9+
10+
# Force to update codeowners file if packasge.json changed.
11+
12+
# block unresolved conflict; https://git-scm.com/docs/git-diff
13+
14+
if [ "$PRE_LINT" != "1" ]; then
15+
node common/scripts/install-run-rush.js -q lint-staged || exit $?
16+
fi

common/git-hooks/pre-push

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
RED='\033[0;31m'
4+
NC='\033[0m'
5+
6+
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
7+
8+
if [ "$CURRENT_BRANCH" = "main" ]; then
9+
echo "${RED}Do not push to main branch directly!!!${NC}"
10+
exit 1
11+
fi
12+
13+
if git status --porcelain | grep -q "pnpm-lock.yaml"; then
14+
echo -e "${RED}Error: pnpm-lock.yaml is included in the changes. Please commit it before push!${NC}"
15+
exit 1
16+
fi
17+
18+
node common/scripts/install-run-rush.js install --check-only --ignore-hooks || exit $?

0 commit comments

Comments
 (0)