ci: add code format check
This commit is contained in:
parent
1b6636afe6
commit
5647de5b87
2 changed files with 30 additions and 0 deletions
6
.github/workflows/test.yml
vendored
6
.github/workflows/test.yml
vendored
|
|
@ -30,6 +30,12 @@ jobs:
|
|||
- name: Install Python dependencies
|
||||
run: pip install -r requirements.txt
|
||||
|
||||
- name: Install gofumpt
|
||||
run: go install mvdan.cc/gofumpt@latest
|
||||
|
||||
- name: Check format
|
||||
run: python hyperbole.py format-check
|
||||
|
||||
- name: Test core
|
||||
working-directory: core
|
||||
run: go test -v -count=1 -skip 'Stress' ./...
|
||||
|
|
|
|||
24
hyperbole.py
24
hyperbole.py
|
|
@ -356,6 +356,25 @@ def cmd_format():
|
|||
print("Failed to format code")
|
||||
|
||||
|
||||
def cmd_format_check():
|
||||
if not check_command(["gofumpt", "-version"]):
|
||||
print("gofumpt is not installed. Please install gofumpt and try again.")
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
output = (
|
||||
subprocess.check_output(["gofumpt", "-l", "-extra", "."]).decode().strip()
|
||||
)
|
||||
except Exception:
|
||||
print("Failed to check code format")
|
||||
sys.exit(1)
|
||||
|
||||
if output:
|
||||
print("The following files are not properly formatted:")
|
||||
print(output)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def cmd_mockgen():
|
||||
if not check_command(["mockery", "--version"]):
|
||||
print("mockery is not installed. Please install mockery and try again.")
|
||||
|
|
@ -500,6 +519,9 @@ def main():
|
|||
# Format
|
||||
p_cmd.add_parser("format", help="Format the code")
|
||||
|
||||
# Format check
|
||||
p_cmd.add_parser("format-check", help="Check code format")
|
||||
|
||||
# Mockgen
|
||||
p_cmd.add_parser("mockgen", help="Generate mock interfaces")
|
||||
|
||||
|
|
@ -533,6 +555,8 @@ def main():
|
|||
cmd_build(args.pprof, args.release, args.race)
|
||||
elif args.command == "format":
|
||||
cmd_format()
|
||||
elif args.command == "format-check":
|
||||
cmd_format_check()
|
||||
elif args.command == "mockgen":
|
||||
cmd_mockgen()
|
||||
elif args.command == "protogen":
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue