chore: setup some common config (#66)

* chore: setup some common config

* chore: setup some common config

* chore: setup commit lint
This commit is contained in:
tecvan 2025-03-20 14:32:11 +08:00 committed by GitHub
parent b726f3cfea
commit be5d086811
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 2626 additions and 12 deletions

39
.github/workflows/common-pr-checks.yml vendored Normal file
View File

@ -0,0 +1,39 @@
name: PR Common Checks
on:
pull_request:
types: [opened, edited, synchronize, reopened]
jobs:
common-checks:
name: PR Common Checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Config Git User
run: |
git config --local user.name "tecvan"
git config --local user.email "fanwenjie.fe@bytedance.com"
- uses: actions/setup-node@v3
with:
node-version: 18
- name: Install Dependencies
run: node common/scripts/install-run-rush.js install
# PR Title Format Check
- name: Check PR Title Format
if: ${{ !contains(github.event.pull_request.title, 'WIP') && !contains(github.event.pull_request.title, 'wip') }}
env:
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
node common/scripts/install-run-rush.js update-autoinstaller --name rush-commitlint && \
pushd common/autoinstallers/rush-commitlint && \
echo "$PR_TITLE" | npx commitlint --config commitlint.config.js && \
popd
# Add more common checks here
# For example: file size checks, specific file format validations, etc.

2
.gitignore vendored
View File

@ -94,7 +94,7 @@ jspm_packages/
*.iml
# Visual Studio Code
.vscode/
.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json

13
.vscode/extentions.json vendored Normal file
View File

@ -0,0 +1,13 @@
{
"recommendations": [
"editorconfig.editorconfig",
"esbenp.prettier-vscode",
"streetsidesoftware.code-spell-checker",
"codezombiech.gitignore",
"aaron-bond.better-comments"
],
"unwantedRecommendations": [
"nucllear.vscode-extension-auto-import",
"steoates.autoimport"
]
}

View File

@ -0,0 +1,87 @@
const chalk = require('chalk');
const spawn = require('cross-spawn');
const defaultConfig = require('cz-customizable');
const { getChangedPackages } = require('./utils');
const typesConfig = [
{ value: 'feat', name: 'A new feature' },
{ value: 'fix', name: 'A bug fix' },
{ value: 'docs', name: 'Documentation only changes' },
{
value: 'style',
name: 'Changes that do not affect the meaning of the code\n (white-space, formatting, missing semi-colons, etc)',
},
{
value: 'refactor',
name: 'A code change that neither fixes a bug nor adds a feature',
},
{
value: 'perf',
name: 'A code change that improves performance',
},
{ value: 'test', name: 'Adding missing tests' },
{
value: 'chore',
name: 'Changes to the build process or auxiliary tools',
},
{
value: 'build',
name: 'Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)',
},
{
value: 'ci',
name: 'Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)',
},
{
value: 'revert',
name: 'Reverts a previous commit',
},
];
const { stdout = '' } = spawn.sync(`git diff --staged --name-only`, {
shell: true,
encoding: 'utf8',
stdio: 'pipe',
});
const changedFiles = stdout.split('\n').filter(Boolean);
const changeSet = getChangedPackages(changedFiles);
if (changeSet.size > 1) {
process.stderr.write(
`${[
chalk.yellow(
`Multiple packages detected in current commit, please consider splitting into smaller commits`,
),
].join('\n')}\n`,
);
changeSet.clear();
changeSet.add('multiple');
}
const changedScopes = [...changeSet];
module.exports = {
...defaultConfig,
types: typesConfig.map(({ value, name }) => {
return {
name: `${value}:${new Array(10 - value.length)
.fill(' ')
.join('')}${name}`,
value,
};
}),
messages: {
...defaultConfig.messages,
type: "Select the type of change that you're committing",
scope: 'Ensure the scope of this change',
subject: 'Write a short, imperative tense description of the change',
body: 'Provide a longer description of the change. Use "|" to break new line:\n',
breaking: 'List any BREAKING CHANGES (optional):\n',
confirmCommit: 'Are you sure you want to proceed with the commit above?',
},
scopes: changedScopes.join(','),
allowCustomScopes: false,
skipQuestions: ['customScope', 'footer', 'body'],
allowBreakingChanges: ['feat', 'fix'],
};

View File

@ -0,0 +1,14 @@
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'header-max-length': [2, 'always', 150],
'subject-full-stop': [0, 'never'],
'subject-case': [
2,
'never',
[
'upper-case', // UPPERCASE
],
],
},
};

View File

@ -0,0 +1,21 @@
{
"name": "rush-commitlint",
"version": "1.0.0",
"private": true,
"author": "fanwenjie.fe@bytedance.com",
"config": {
"commitizen": {
"path": "common/autoinstallers/rush-commitlint/node_modules/cz-customizable"
}
},
"dependencies": {
"@commitlint/cli": "^17.2.0",
"@commitlint/config-conventional": "^17.2.0",
"@rushstack/rush-sdk": "5.100.2",
"commitizen": "^4.2.6",
"cz-customizable": "^7.2.1"
},
"devDependencies": {
"@types/node": "^20"
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,37 @@
const { RushConfiguration } = require('@rushstack/rush-sdk')
const getRushConfiguration = (function () {
let rushConfiguration = null
return function () {
// eslint-disable-next-line
return (rushConfiguration ||= RushConfiguration.loadFromDefaultLocation({
startingFolder: process.cwd(),
}))
}
})()
function getChangedPackages(changedFiles) {
const changedPackages = new Set()
try {
const rushConfiguration = getRushConfiguration()
const { rushJsonFolder } = rushConfiguration
const lookup = rushConfiguration.getProjectLookupForRoot(rushJsonFolder)
for (const file of changedFiles) {
const project = lookup.findChildPath(file)
// 如果没找到注册的包信息,则认为是通用文件更改
const packageName = project?.packageName || 'misc'
if (!changedPackages.has(packageName)) {
changedPackages.add(packageName)
}
}
} catch (e) {
console.error(e)
throw e
}
return changedPackages
}
exports.getChangedPackages = getChangedPackages
exports.getRushConfiguration = getRushConfiguration

View File

@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
#
# This is an example Git hook for use with Rush. To enable this hook, rename this file
# to "commit-msg" and then run "rush install", which will copy it from common/git-hooks
@ -18,8 +18,22 @@
# This example enforces that commit message should contain a minimum amount of
# description text.
if [ `cat $1 | wc -w` -lt 3 ]; then
echo ""
echo "Invalid commit message: The message must contain at least 3 words."
exit 1
# if [ `cat $1 | wc -w` -lt 3 ]; then
# echo ""
# echo "Invalid commit message: The message must contain at least 3 words."
# exit 1
# fi
# rebase 过程中分支名格式为 (no branch, rebasing chore/replace-rushtool)
# 正常提交时分支名格式为 chore/replace-rushtool
BRANCH_NAME=$(git branch | grep '*' | sed 's/* //')
# 如果匹配到 rebase 格式的输出认为是在rebase ,则跳过自动推送
if [[ "X${BRANCH_NAME}" == "X(no branch"* ]]; then
exit
else
node common/scripts/install-run-rush.js -q commitlint \
--config common/autoinstallers/rush-commitlint/commitlint.config.js \
--edit "$1" || exit 1
# 如果当前分支是 main 分支,则不进行推送
node infra/rush-x/bin/run change || exit 1
fi

4
common/git-hooks/post-checkout Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
# avoid conflicts in pnpm lock
# https://7tonshark.com/posts/avoid-conflicts-in-pnpm-lock/
git config merge.ours.driver true

6
package-lock.json generated
View File

@ -1,6 +0,0 @@
{
"name": "flow-editor-public",
"lockfileVersion": 3,
"requires": true,
"packages": {}
}