From 24276f82447c40ef95b9c7e6e5df1816de91239c Mon Sep 17 00:00:00 2001 From: xdustinface Date: Thu, 12 Feb 2026 02:31:17 +0100 Subject: [PATCH] feat: add CI with `pre-commit` (`ruff` linting and `pytest`) GitHub Actions CI runs `pre-commit` hooks (`ruff format`, `ruff lint`, `pytest`) on `ubuntu-latest` and `macos-latest` with Python `3.14`. --- .github/workflows/ci.yml | 37 +++++++++++++++++++++++++++++ .pre-commit-config.yaml | 50 ++++++++++++++++++++++++++++++++++++++++ contrib/setup-dashd.py | 0 export_wallets.py | 0 pyproject.toml | 28 ++++++++++++++++++++++ 5 files changed, 115 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 .pre-commit-config.yaml mode change 100644 => 100755 contrib/setup-dashd.py mode change 100644 => 100755 export_wallets.py create mode 100644 pyproject.toml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..cfec637 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,37 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + +env: + DASHVERSION: "23.0.2" + +jobs: + pre-commit: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: "3.14" + allow-prereleases: true + + - name: Cache dashd + uses: actions/cache@v4 + with: + path: .dashd-cache + key: dashd-${{ runner.os }}-${{ env.DASHVERSION }} + + - name: Setup dashd + env: + CACHE_DIR: ${{ github.workspace }}/.dashd-cache + run: python contrib/setup-dashd.py >> "$GITHUB_ENV" + + - uses: pre-commit/action@v3.0.1 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..6a34a8a --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,50 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: trailing-whitespace + exclude: '\.md$' + - id: end-of-file-fixer + exclude: '^data/' + - id: check-yaml + args: ['--allow-multiple-documents'] + - id: check-json + exclude: '^data/' + - id: check-toml + - id: check-merge-conflict + - id: mixed-line-ending + args: ['--fix=lf'] + - id: check-added-large-files + args: ['--maxkb=1000'] + - id: check-case-conflict + - id: check-executables-have-shebangs + - id: check-shebang-scripts-are-executable + + - repo: https://github.com/rhysd/actionlint + rev: v1.7.9 + hooks: + - id: actionlint + + - repo: https://github.com/crate-ci/typos + rev: v1.31.1 + hooks: + - id: typos + args: ['--write-changes'] + exclude: '^data/' + + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.15.0 + hooks: + - id: ruff-format + - id: ruff-check + args: [--fix] + + - repo: local + hooks: + - id: pytest + name: pytest + entry: python3 -m pytest + language: python + additional_dependencies: [pytest] + pass_filenames: false + always_run: true diff --git a/contrib/setup-dashd.py b/contrib/setup-dashd.py old mode 100644 new mode 100755 diff --git a/export_wallets.py b/export_wallets.py old mode 100644 new mode 100755 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..a0a0fa5 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,28 @@ +[tool.ruff] +target-version = "py312" +line-length = 120 + +[tool.ruff.lint] +select = [ + "E", # pycodestyle errors + "F", # pyflakes + "W", # pycodestyle warnings + "I", # isort + "UP", # pyupgrade + "B", # flake8-bugbear + "SIM", # flake8-simplify +] +ignore = [ + "E501", # line too long (handled by formatter) + "SIM105", # contextlib.suppress - less readable than try/except/pass + "SIM108", # ternary operator - less readable for multi-line assignments +] + +[tool.ruff.format] +quote-style = "double" + +[tool.pytest.ini_options] +testpaths = ["tests"] +markers = [ + "integration: end-to-end tests requiring a real dashd binary (set DASHD_PATH)", +]