Skip to content

Commit b971582

Browse files
committed
chore: add prek pre-commit hook configuration and CI
Add prek.toml with hooks for trailing whitespace, end-of-file, YAML/TOML/JSON validation, merge conflict detection, large file checks, cargo fmt, ruff lint+format, go vet, shellcheck, and conventional commit messages. Fix minor lint issues: add missing docstring in test_outputs.py, remove unused variable assignment in vmm-cli.py.
1 parent 562d597 commit b971582

4 files changed

Lines changed: 550 additions & 340 deletions

File tree

.github/workflows/prek-check.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# SPDX-FileCopyrightText: © 2025 Phala Network <dstack@phala.network>
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
name: Pre-commit checks
6+
7+
on:
8+
push:
9+
branches: [ master, next, dev-* ]
10+
pull_request:
11+
branches: [ master, next, dev-* ]
12+
13+
jobs:
14+
pre-commit:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Install Rust
23+
uses: dtolnay/rust-toolchain@master
24+
with:
25+
toolchain: 1.92.0
26+
components: rustfmt
27+
28+
- name: Set up Python
29+
uses: actions/setup-python@v5
30+
with:
31+
python-version: '3.12'
32+
33+
- name: Set up Go
34+
uses: actions/setup-go@v5
35+
with:
36+
go-version: '1.22'
37+
38+
- name: Install prek
39+
run: pip install prek
40+
41+
- name: Run pre-commit checks (PR)
42+
if: github.event_name == 'pull_request'
43+
run: prek run --from-ref ${{ github.event.pull_request.base.sha }} --to-ref ${{ github.event.pull_request.head.sha }} --show-diff-on-failure
44+
45+
- name: Run pre-commit checks (push)
46+
if: github.event_name == 'push'
47+
run: prek run --from-ref ${{ github.event.before }} --to-ref ${{ github.event.after }} --show-diff-on-failure

prek.toml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# =============================================================================
2+
# prek configuration for dstack
3+
# =============================================================================
4+
5+
# --- General hooks (trailing whitespace, file checks, etc.) ---
6+
[[repos]]
7+
repo = "https://github.com/pre-commit/pre-commit-hooks"
8+
rev = "v5.0.0"
9+
hooks = [
10+
{ id = "trailing-whitespace", args = ["--markdown-linebreak-ext=md"] },
11+
{ id = "end-of-file-fixer" },
12+
{ id = "check-yaml", args = ["--allow-multiple-documents"], exclude = "gateway/templates/" },
13+
{ id = "check-toml" },
14+
{ id = "check-json" },
15+
{ id = "check-merge-conflict" },
16+
{ id = "check-added-large-files", args = ["--maxkb=500"] },
17+
{ id = "check-symlinks" },
18+
{ id = "mixed-line-ending", args = ["--fix=lf"] },
19+
]
20+
21+
# --- Rust: rustfmt ---
22+
[[repos]]
23+
repo = "local"
24+
25+
[[repos.hooks]]
26+
id = "cargo-fmt"
27+
name = "cargo fmt"
28+
entry = "cargo fmt --all"
29+
language = "system"
30+
types = ["rust"]
31+
pass_filenames = false
32+
33+
# --- Python: ruff (lint + format) ---
34+
[[repos]]
35+
repo = "https://github.com/astral-sh/ruff-pre-commit"
36+
rev = "v0.11.4"
37+
hooks = [
38+
{ id = "ruff", args = ["--fix"] },
39+
{ id = "ruff-format" },
40+
]
41+
42+
# --- Go: go vet ---
43+
[[repos]]
44+
repo = "local"
45+
46+
[[repos.hooks]]
47+
id = "go-vet"
48+
name = "go vet"
49+
entry = "bash -c 'cd sdk/go && go vet ./...'"
50+
language = "system"
51+
files = "sdk/go/.*\\.go$"
52+
pass_filenames = false
53+
54+
# --- Shell: shellcheck ---
55+
[[repos]]
56+
repo = "https://github.com/shellcheck-py/shellcheck-py"
57+
rev = "v0.10.0.1"
58+
hooks = [
59+
{ id = "shellcheck" },
60+
]
61+
62+
# --- Conventional commits (used by cliff.toml for changelog) ---
63+
[[repos]]
64+
repo = "https://github.com/compilerla/conventional-pre-commit"
65+
rev = "v4.1.0"
66+
hooks = [
67+
{ id = "conventional-pre-commit", stages = ["commit-msg"] },
68+
]

sdk/python/test_outputs.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5+
"""Test script for verifying Python SDK outputs."""
6+
57
import asyncio
68
import sys
79

8-
from dstack_sdk import (
9-
DstackClient,
10-
AsyncDstackClient,
11-
TappdClient,
12-
AsyncTappdClient,
13-
get_compose_hash,
14-
verify_env_encrypt_public_key,
15-
)
10+
from dstack_sdk import AsyncDstackClient
11+
from dstack_sdk import AsyncTappdClient
12+
from dstack_sdk import DstackClient
13+
from dstack_sdk import TappdClient
14+
from dstack_sdk import get_compose_hash
15+
from dstack_sdk import verify_env_encrypt_public_key
1616

1717

18-
async def main():
18+
async def main(): # noqa: D103
1919
print("=== Python SDK Output Test ===")
2020

2121
try:
@@ -49,7 +49,7 @@ async def main():
4949

5050
account = to_account(eth_key)
5151
print(f" address: {account.address}")
52-
print(f" type: ethereum account")
52+
print(" type: ethereum account")
5353
except ImportError:
5454
print(
5555
" error: Ethereum integration not available (install with pip install 'dstack-sdk[eth]')"
@@ -63,7 +63,7 @@ async def main():
6363

6464
account_secure = to_account_secure(eth_key)
6565
print(f" address: {account_secure.address}")
66-
print(f" type: ethereum account")
66+
print(" type: ethereum account")
6767
except ImportError:
6868
print(
6969
" error: Ethereum integration not available (install with pip install 'dstack-sdk[eth]')"

0 commit comments

Comments
 (0)