ci: add code format check

This commit is contained in:
Toby 2026-04-18 11:48:29 -07:00
parent 1b6636afe6
commit 5647de5b87
2 changed files with 30 additions and 0 deletions

View file

@ -30,6 +30,12 @@ jobs:
- name: Install Python dependencies - name: Install Python dependencies
run: pip install -r requirements.txt 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 - name: Test core
working-directory: core working-directory: core
run: go test -v -count=1 -skip 'Stress' ./... run: go test -v -count=1 -skip 'Stress' ./...

View file

@ -356,6 +356,25 @@ def cmd_format():
print("Failed to format code") 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(): def cmd_mockgen():
if not check_command(["mockery", "--version"]): if not check_command(["mockery", "--version"]):
print("mockery is not installed. Please install mockery and try again.") print("mockery is not installed. Please install mockery and try again.")
@ -500,6 +519,9 @@ def main():
# Format # Format
p_cmd.add_parser("format", help="Format the code") p_cmd.add_parser("format", help="Format the code")
# Format check
p_cmd.add_parser("format-check", help="Check code format")
# Mockgen # Mockgen
p_cmd.add_parser("mockgen", help="Generate mock interfaces") p_cmd.add_parser("mockgen", help="Generate mock interfaces")
@ -533,6 +555,8 @@ def main():
cmd_build(args.pprof, args.release, args.race) cmd_build(args.pprof, args.release, args.race)
elif args.command == "format": elif args.command == "format":
cmd_format() cmd_format()
elif args.command == "format-check":
cmd_format_check()
elif args.command == "mockgen": elif args.command == "mockgen":
cmd_mockgen() cmd_mockgen()
elif args.command == "protogen": elif args.command == "protogen":