Skip to content

Commit

Permalink
[CELEBORN-1240] Introduce Husky Configuration to Celeborn Web
Browse files Browse the repository at this point in the history
![image](https://github.com/apache/incubator-celeborn/assets/49502875/4404770c-c46e-470b-8f5e-c244c6656339)

### What changes were proposed in this pull request?

- Added Husky to enforce code quality with automated tasks during Git events.
- Added lint-staged for optimized linting on staged files before each commit.

### Why are the changes needed?

Enhances code quality.

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

Local test.

Closes apache#2250 from tiny-dust/CELEBORN-1240.

Lead-authored-by: tiny-dust <[email protected]>
Co-authored-by: 周顺顺 <[email protected]>
Signed-off-by: SteNicholas <[email protected]>
  • Loading branch information
tiny-dust authored and SteNicholas committed Jan 26, 2024
1 parent 5c54388 commit d315ff5
Show file tree
Hide file tree
Showing 9 changed files with 475 additions and 8 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/web_lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

name: Lint Check for Web

on:
push:
branches:
- main
- branch-*
pull_request:
branches:
- main
- branch-*

concurrency:
group: style-${{ github.ref }}
cancel-in-progress: true

jobs:
lint:
runs-on: ubuntu-latest

steps:
- uses: pnpm/action-setup@v2
with:
version: 8

- name: Checkout code
uses: actions/checkout@v4

# When updating node and pnpm version, also need to update the version in `web/pom.xml`
- name: Use Node.js v20.11.0
uses: actions/setup-node@v4
with:
node-version: 20.11.0

- name: Use pnpm v8.14.3
uses: pnpm/action-setup@v2
with:
version: 8.14.3

- name: Install dependencies
run: pnpm install
working-directory: ./web

- name: Lint and format
run: pnpm run lint
working-directory: ./web
6 changes: 6 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ This project uses check-style plugins. Run some checks before you create a new p
dev/reformat
```

Meanwhile, run some checks of web with changes of web module before you create a new pull request.

```shell
dev/reformat --web
```

If you have changed configuration, run following command to refresh docs.
```shell
UPDATE=1 build/mvn clean test -pl common -am -Dtest=none -DwildcardSuites=org.apache.celeborn.ConfigurationSuite
Expand Down
19 changes: 12 additions & 7 deletions dev/reformat
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@
set -x

PROJECT_DIR="$(cd "`dirname "$0"`/.."; pwd)"
${PROJECT_DIR}/build/mvn spotless:apply -Pflink-1.14
${PROJECT_DIR}/build/mvn spotless:apply -Pflink-1.15
${PROJECT_DIR}/build/mvn spotless:apply -Pflink-1.17
${PROJECT_DIR}/build/mvn spotless:apply -Pflink-1.18
${PROJECT_DIR}/build/mvn spotless:apply -Pspark-2.4
${PROJECT_DIR}/build/mvn spotless:apply -Pspark-3.3
${PROJECT_DIR}/build/mvn spotless:apply -Pmr

if [ "$1" == "--web" ]; then
${PROJECT_DIR}/build/mvn clean install -pl web
else
${PROJECT_DIR}/build/mvn spotless:apply -Pflink-1.14
${PROJECT_DIR}/build/mvn spotless:apply -Pflink-1.15
${PROJECT_DIR}/build/mvn spotless:apply -Pflink-1.17
${PROJECT_DIR}/build/mvn spotless:apply -Pflink-1.18
${PROJECT_DIR}/build/mvn spotless:apply -Pspark-2.4
${PROJECT_DIR}/build/mvn spotless:apply -Pspark-3.3
${PROJECT_DIR}/build/mvn spotless:apply -Pmr
fi
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<module>service</module>
<module>master</module>
<module>worker</module>
<module>web</module>
</modules>

<distributionManagement>
Expand Down
22 changes: 22 additions & 0 deletions web/.husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

#!/usr/bin/env sh

. "$(dirname -- "$0")/_/husky.sh"

cd web && pnpm run lint:lint-staged
4 changes: 4 additions & 0 deletions web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,9 @@ pnpm build
### Lint with [ESLint](https://eslint.org/)

```sh
# Whole project
pnpm lint

# Staged files for commit
pnpm lint:lint-staged
```
9 changes: 8 additions & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"build-only": "vite build",
"type-check": "vue-tsc --build --force",
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
"format": "prettier --write src/"
"lint:lint-staged": "lint-staged",
"format": "prettier --write src/",
"prepare": "cd ../ && husky install web/.husky"
},
"dependencies": {
"pinia": "^2.1.7",
Expand All @@ -28,6 +30,8 @@
"@vue/tsconfig": "^0.5.0",
"eslint": "^8.49.0",
"eslint-plugin-vue": "^9.17.0",
"husky": "^8.0.0",
"lint-staged": "^15.2.0",
"naive-ui": "^2.37.3",
"npm-run-all2": "^6.1.1",
"prettier": "^3.0.3",
Expand All @@ -37,5 +41,8 @@
"unplugin-vue-components": "^0.26.0",
"vite": "^5.0.10",
"vue-tsc": "^1.8.25"
},
"lint-staged": {
"*.{vue,js,jsx,cjs,mjs,ts,tsx,cts,mts}": "eslint --fix --ignore-path .gitignore --config .eslintrc.cjs"
}
}
Loading

0 comments on commit d315ff5

Please sign in to comment.