mirror of
https://github.com/frappe/frappe_docker.git
synced 2024-12-22 18:18:57 +00:00
chore: Use pre-commit framework (#604)
* Add pre-commit, prettier configs and editorconfig * Remove `check-toml` hook * Add isort config * Add codespell config * Update hooks * Remove prettierignore * Add shellcheck config * Add lint workflow * Add pre-commit autoupdate workflow * Remove path constraints from lint workflow * Fix CI * Add guide to CONTRIBUTING.md * Fix (probably) shfmt * Fix (probably) shfmt * Fix (probably) shfmt
This commit is contained in:
parent
65f6228be8
commit
2ac2b7ce43
19
.editorconfig
Normal file
19
.editorconfig
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# http://editorconfig.org
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
|
|
||||||
|
[*.{py, pyi}]
|
||||||
|
indent_size = 4
|
||||||
|
|
||||||
|
[*Dockerfile*]
|
||||||
|
indent_size = 4
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
trim_trailing_whitespace = false
|
33
.github/workflows/lint.yml
vendored
33
.github/workflows/lint.yml
vendored
@ -4,19 +4,38 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
paths:
|
|
||||||
- "*.sh"
|
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
paths:
|
|
||||||
- "*.sh"
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
lint:
|
lint:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- name: Checkout
|
||||||
- uses: ludeeus/action-shellcheck@1.1.0
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Setup Python
|
||||||
|
uses: actions/setup-python@v2
|
||||||
|
|
||||||
|
# For shfmt pre-commit hook
|
||||||
|
- name: Setup Go
|
||||||
|
uses: actions/setup-go@v2
|
||||||
|
with:
|
||||||
|
go-version: "^1.14"
|
||||||
|
|
||||||
|
- name: Cache
|
||||||
|
uses: actions/cache@v2
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/.cache/pre-commit
|
||||||
|
~/.cache/pip
|
||||||
|
key: lint-${{ hashFiles('.pre-commit-config.yaml') }}
|
||||||
|
|
||||||
|
- name: Install pre-commit
|
||||||
|
run: pip install -U pre-commit
|
||||||
|
|
||||||
|
- name: Lint
|
||||||
|
run: pre-commit run --color=always --all-files
|
||||||
env:
|
env:
|
||||||
SHELLCHECK_OPTS: -x
|
GO111MODULE: on
|
||||||
|
26
.github/workflows/pre-commit-autoupdate.yml
vendored
Normal file
26
.github/workflows/pre-commit-autoupdate.yml
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
name: Autoupdate pre-commit hooks
|
||||||
|
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
# Every day at 7 am
|
||||||
|
- cron: 0 7 * * *
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
pre-commit-autoupdate:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Update pre-commit hooks
|
||||||
|
uses: vrslev/pre-commit-autoupdate@v1.0.0
|
||||||
|
|
||||||
|
- name: Create Pull Request
|
||||||
|
uses: peter-evans/create-pull-request@v3
|
||||||
|
with:
|
||||||
|
branch: pre-commit-autoupdate
|
||||||
|
title: "chore(deps): Update pre-commit hooks"
|
||||||
|
commit-message: "chore(deps): Update pre-commit hooks"
|
||||||
|
body: Update pre-commit hooks
|
||||||
|
labels: dependencies,development
|
||||||
|
delete-branch: True
|
56
.pre-commit-config.yaml
Normal file
56
.pre-commit-config.yaml
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
repos:
|
||||||
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
|
rev: v4.0.1
|
||||||
|
hooks:
|
||||||
|
- id: trailing-whitespace
|
||||||
|
- id: end-of-file-fixer
|
||||||
|
|
||||||
|
- repo: https://github.com/asottile/pyupgrade
|
||||||
|
rev: v2.29.1
|
||||||
|
hooks:
|
||||||
|
- id: pyupgrade
|
||||||
|
args: [--py37-plus]
|
||||||
|
|
||||||
|
- repo: https://github.com/psf/black
|
||||||
|
rev: 21.11b1
|
||||||
|
hooks:
|
||||||
|
- id: black
|
||||||
|
|
||||||
|
- repo: https://github.com/pycqa/isort
|
||||||
|
rev: 5.10.1
|
||||||
|
hooks:
|
||||||
|
- id: isort
|
||||||
|
args: [
|
||||||
|
-o, # KNOWN_THIRD_PARTY
|
||||||
|
frappe,
|
||||||
|
--profile,
|
||||||
|
black,
|
||||||
|
]
|
||||||
|
|
||||||
|
- repo: https://github.com/pre-commit/mirrors-prettier
|
||||||
|
rev: v2.5.1
|
||||||
|
hooks:
|
||||||
|
- id: prettier
|
||||||
|
exclude: installation/docker-compose-custom.yml
|
||||||
|
|
||||||
|
- repo: https://github.com/codespell-project/codespell
|
||||||
|
rev: v2.1.0
|
||||||
|
hooks:
|
||||||
|
- id: codespell
|
||||||
|
exclude: ".*Dockerfile.*"
|
||||||
|
|
||||||
|
- repo: local
|
||||||
|
hooks:
|
||||||
|
- id: shfmt
|
||||||
|
name: shfmt
|
||||||
|
language: golang
|
||||||
|
additional_dependencies: [mvdan.cc/sh/v3/cmd/shfmt]
|
||||||
|
entry: shfmt
|
||||||
|
args: [-w]
|
||||||
|
types: [shell]
|
||||||
|
|
||||||
|
- repo: https://github.com/shellcheck-py/shellcheck-py
|
||||||
|
rev: v0.8.0.1
|
||||||
|
hooks:
|
||||||
|
- id: shellcheck
|
||||||
|
args: [-x]
|
@ -10,12 +10,35 @@ On each PR that contains changes relevant to Docker builds, images are being bui
|
|||||||
> :evergreen_tree: Please be considerate when pushing commits and opening PR for multiple branches, as the process of building images uses energy and contributes to global warming.
|
> :evergreen_tree: Please be considerate when pushing commits and opening PR for multiple branches, as the process of building images uses energy and contributes to global warming.
|
||||||
>
|
>
|
||||||
|
|
||||||
|
|
||||||
## Lint
|
## Lint
|
||||||
|
|
||||||
|
We use `pre-commit` framework to lint the codebase before committing.
|
||||||
|
First, you need to install pre-commit with pip:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
shellcheck example.sh
|
pip install pre-commit
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Also you can use brew if you're on Mac:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
brew install pre-commit
|
||||||
|
```
|
||||||
|
|
||||||
|
To setup _pre-commit_ hook, run:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
pre-commit install
|
||||||
|
```
|
||||||
|
|
||||||
|
To run all the files in repository, run:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
pre-commit run --all-files
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Build
|
## Build
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
|
Loading…
Reference in New Issue
Block a user