Skip to content

Commit be5d086

Browse files
authored
chore: setup some common config (bytedance#66)
* chore: setup some common config * chore: setup some common config * chore: setup commit lint
1 parent b726f3c commit be5d086

File tree

11 files changed

+2626
-12
lines changed

11 files changed

+2626
-12
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: PR Common Checks
2+
on:
3+
pull_request:
4+
types: [opened, edited, synchronize, reopened]
5+
6+
jobs:
7+
common-checks:
8+
name: PR Common Checks
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
with:
13+
fetch-depth: 1
14+
15+
- name: Config Git User
16+
run: |
17+
git config --local user.name "tecvan"
18+
git config --local user.email "fanwenjie.fe@bytedance.com"
19+
20+
- uses: actions/setup-node@v3
21+
with:
22+
node-version: 18
23+
24+
- name: Install Dependencies
25+
run: node common/scripts/install-run-rush.js install
26+
27+
# PR Title Format Check
28+
- name: Check PR Title Format
29+
if: ${{ !contains(github.event.pull_request.title, 'WIP') && !contains(github.event.pull_request.title, 'wip') }}
30+
env:
31+
PR_TITLE: ${{ github.event.pull_request.title }}
32+
run: |
33+
node common/scripts/install-run-rush.js update-autoinstaller --name rush-commitlint && \
34+
pushd common/autoinstallers/rush-commitlint && \
35+
echo "$PR_TITLE" | npx commitlint --config commitlint.config.js && \
36+
popd
37+
38+
# Add more common checks here
39+
# For example: file size checks, specific file format validations, etc.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ jspm_packages/
9494
*.iml
9595

9696
# Visual Studio Code
97-
.vscode/
97+
.vscode/settings.json
9898
!.vscode/tasks.json
9999
!.vscode/launch.json
100100

.vscode/extentions.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"recommendations": [
3+
"editorconfig.editorconfig",
4+
"esbenp.prettier-vscode",
5+
"streetsidesoftware.code-spell-checker",
6+
"codezombiech.gitignore",
7+
"aaron-bond.better-comments"
8+
],
9+
"unwantedRecommendations": [
10+
"nucllear.vscode-extension-auto-import",
11+
"steoates.autoimport"
12+
]
13+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
const chalk = require('chalk');
2+
const spawn = require('cross-spawn');
3+
const defaultConfig = require('cz-customizable');
4+
const { getChangedPackages } = require('./utils');
5+
6+
const typesConfig = [
7+
{ value: 'feat', name: 'A new feature' },
8+
{ value: 'fix', name: 'A bug fix' },
9+
{ value: 'docs', name: 'Documentation only changes' },
10+
{
11+
value: 'style',
12+
name: 'Changes that do not affect the meaning of the code\n (white-space, formatting, missing semi-colons, etc)',
13+
},
14+
{
15+
value: 'refactor',
16+
name: 'A code change that neither fixes a bug nor adds a feature',
17+
},
18+
{
19+
value: 'perf',
20+
name: 'A code change that improves performance',
21+
},
22+
{ value: 'test', name: 'Adding missing tests' },
23+
{
24+
value: 'chore',
25+
name: 'Changes to the build process or auxiliary tools',
26+
},
27+
{
28+
value: 'build',
29+
name: 'Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)',
30+
},
31+
{
32+
value: 'ci',
33+
name: 'Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)',
34+
},
35+
{
36+
value: 'revert',
37+
name: 'Reverts a previous commit',
38+
},
39+
];
40+
41+
const { stdout = '' } = spawn.sync(`git diff --staged --name-only`, {
42+
shell: true,
43+
encoding: 'utf8',
44+
stdio: 'pipe',
45+
});
46+
const changedFiles = stdout.split('\n').filter(Boolean);
47+
const changeSet = getChangedPackages(changedFiles);
48+
49+
if (changeSet.size > 1) {
50+
process.stderr.write(
51+
`${[
52+
chalk.yellow(
53+
`Multiple packages detected in current commit, please consider splitting into smaller commits`,
54+
),
55+
].join('\n')}\n`,
56+
);
57+
58+
changeSet.clear();
59+
changeSet.add('multiple');
60+
}
61+
62+
const changedScopes = [...changeSet];
63+
64+
module.exports = {
65+
...defaultConfig,
66+
types: typesConfig.map(({ value, name }) => {
67+
return {
68+
name: `${value}:${new Array(10 - value.length)
69+
.fill(' ')
70+
.join('')}${name}`,
71+
value,
72+
};
73+
}),
74+
messages: {
75+
...defaultConfig.messages,
76+
type: "Select the type of change that you're committing",
77+
scope: 'Ensure the scope of this change',
78+
subject: 'Write a short, imperative tense description of the change',
79+
body: 'Provide a longer description of the change. Use "|" to break new line:\n',
80+
breaking: 'List any BREAKING CHANGES (optional):\n',
81+
confirmCommit: 'Are you sure you want to proceed with the commit above?',
82+
},
83+
scopes: changedScopes.join(','),
84+
allowCustomScopes: false,
85+
skipQuestions: ['customScope', 'footer', 'body'],
86+
allowBreakingChanges: ['feat', 'fix'],
87+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
extends: ['@commitlint/config-conventional'],
3+
rules: {
4+
'header-max-length': [2, 'always', 150],
5+
'subject-full-stop': [0, 'never'],
6+
'subject-case': [
7+
2,
8+
'never',
9+
[
10+
'upper-case', // UPPERCASE
11+
],
12+
],
13+
},
14+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "rush-commitlint",
3+
"version": "1.0.0",
4+
"private": true,
5+
"author": "fanwenjie.fe@bytedance.com",
6+
"config": {
7+
"commitizen": {
8+
"path": "common/autoinstallers/rush-commitlint/node_modules/cz-customizable"
9+
}
10+
},
11+
"dependencies": {
12+
"@commitlint/cli": "^17.2.0",
13+
"@commitlint/config-conventional": "^17.2.0",
14+
"@rushstack/rush-sdk": "5.100.2",
15+
"commitizen": "^4.2.6",
16+
"cz-customizable": "^7.2.1"
17+
},
18+
"devDependencies": {
19+
"@types/node": "^20"
20+
}
21+
}

0 commit comments

Comments
 (0)