diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bfc4805..bd11ceb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,17 +25,14 @@ jobs: - name: install libdbus on linux if: matrix.os == 'ubuntu-latest' run: sudo apt-get update && sudo apt-get install -y --no-install-recommends libdbus-1-dev pkg-config - - uses: jdx/mise-action@5083fe46898c414b2475087cc79da59e7da859e8 # v2.1.11 + # No mise here: the test matrix only needs rust + cargo-nextest. Letting + # rustup own the toolchain avoids the mise/host-rustup divergence we hit + # on macOS (mise's cargo and rustup component add ended up on different + # toolchains and clippy wouldn't resolve). + - uses: dtolnay/rust-toolchain@b3b07ba8b418998c39fb20f53e8b695cdcc8de1b # stable with: - install: true - cache: true - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: ensure rustfmt + clippy components - # `mise.toml` requests rust profile=default, but mise's rust backend - # may install a cached minimal toolchain. Add the components - # explicitly so `cargo fmt` and `cargo clippy` always resolve. - run: rustup component add rustfmt clippy + toolchain: "1.89" + components: rustfmt, clippy - uses: Swatinem/rust-cache@98c8021b550208e191a6a3145459bfc9fb29c4c0 # v2.7.4 - uses: taiki-e/install-action@v2 with: @@ -79,6 +76,26 @@ jobs: - uses: Swatinem/rust-cache@98c8021b550208e191a6a3145459bfc9fb29c4c0 # v2.7.4 - run: cargo check --all-features + pre-commit: + name: pre-commit + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - name: install libdbus + run: sudo apt-get update && sudo apt-get install -y --no-install-recommends libdbus-1-dev pkg-config + - uses: jdx/mise-action@5083fe46898c414b2475087cc79da59e7da859e8 # v2.1.11 + with: + install: true + cache: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: ensure rustfmt + clippy components + # Route through mise so components land in the same toolchain the + # pre-commit cargo hooks (`mise exec -- cargo ...`) will use. + run: mise exec -- rustup component add rustfmt clippy + - uses: Swatinem/rust-cache@98c8021b550208e191a6a3145459bfc9fb29c4c0 # v2.7.4 + - uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1 + linux-headless: name: linux headless (no D-Bus) runs-on: ubuntu-latest diff --git a/.markdownlint-cli2.yaml b/.markdownlint-cli2.yaml new file mode 100644 index 0000000..e1a2a75 --- /dev/null +++ b/.markdownlint-cli2.yaml @@ -0,0 +1,21 @@ +# markdownlint-cli2 config for slack-cli. +# Mainly relaxes rules that fight against Japanese line widths and +# legitimate inline HTML / bare URLs in README content. + +config: + line-length: false + no-inline-html: false + no-bare-urls: false + first-line-h1: false + no-duplicate-heading: false + no-emphasis-as-heading: false + # Tables with mixed-width (CJK + ASCII) characters cannot be aligned by + # column at the byte/code-point level. Keep tables readable by content, + # not by pipe alignment. + table-column-style: false + +ignores: + - 'CHANGELOG.md' + - 'target/**' + # Internal brainstorming spec + implementation plan, kept as-is. + - 'docs/superpowers/**' diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..f35ff96 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,65 @@ +# pre-commit hooks for slack-cli. +# +# Install (one-time, per clone): +# pip install --user pre-commit # or: brew install pre-commit, pipx install pre-commit +# pre-commit install +# pre-commit install --hook-type commit-msg +# +# Run manually on every tracked file: +# pre-commit run --all-files + +repos: + # ----- File hygiene ----- + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v6.0.0 + hooks: + - id: trailing-whitespace + exclude: '\.snap$' + - id: end-of-file-fixer + exclude: '\.snap$' + - id: check-yaml + - id: check-toml + - id: check-json + - id: check-merge-conflict + - id: check-added-large-files + args: [--maxkb=1024] + - id: mixed-line-ending + args: [--fix=lf] + - id: detect-private-key + + # ----- Secret detection ----- + - repo: https://github.com/gitleaks/gitleaks + rev: v8.30.0 + hooks: + - id: gitleaks + + # ----- Markdown lint ----- + - repo: https://github.com/DavidAnson/markdownlint-cli2 + rev: v0.22.1 + hooks: + - id: markdownlint-cli2 + args: ['--config', '.markdownlint-cli2.yaml'] + + # ----- Conventional Commits (commit-msg only) ----- + - repo: https://github.com/compilerla/conventional-pre-commit + rev: v4.4.0 + hooks: + - id: conventional-pre-commit + stages: [commit-msg] + args: [feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert] + + # ----- Rust (local hooks via mise so the toolchain is always pinned) ----- + - repo: local + hooks: + - id: cargo-fmt + name: cargo fmt --check + entry: mise exec -- cargo fmt --all -- --check + language: system + types: [rust] + pass_filenames: false + - id: cargo-clippy + name: cargo clippy --all-targets -- -D warnings + entry: mise exec -- cargo clippy --all-targets -- -D warnings + language: system + types: [rust] + pass_filenames: false diff --git a/README.ja.md b/README.ja.md index ecffaed..3bb43c4 100644 --- a/README.ja.md +++ b/README.ja.md @@ -149,6 +149,27 @@ mise run snap # 未確定の insta スナップショットをレビュ mise run run -- channel list ``` +### pre-commit hooks + +クローン直後に一度だけ設定(`pre-commit` を PATH に入れて `.git/hooks` に登録します): + +```sh +pip install --user pre-commit # または brew install pre-commit / pipx install pre-commit +pre-commit install +pre-commit install --hook-type commit-msg +``` + +全 tracked file に対して手動実行: + +```sh +pre-commit run --all-files +``` + +`.pre-commit-config.yaml` で次を設定: ファイル衛生チェック、gitleaks +(secret scan)、markdownlint、Conventional Commits validator(commit-msg)、 +ローカル hook として `cargo fmt --check` と `cargo clippy --all-targets -- -D warnings`。 +CI でも同じ hook 群を各 PR で実行します。 + ## ライセンス MIT OR Apache-2.0 のデュアルライセンス。 diff --git a/README.md b/README.md index 5617c1e..8774d8b 100644 --- a/README.md +++ b/README.md @@ -153,6 +153,28 @@ mise run snap # Review pending insta snapshots mise run run -- channel list ``` +### pre-commit hooks + +One-time setup per clone (installs `pre-commit` to your PATH and wires up +`.git/hooks`): + +```sh +pip install --user pre-commit # or: brew install pre-commit / pipx install pre-commit +pre-commit install +pre-commit install --hook-type commit-msg +``` + +Run all hooks against every tracked file: + +```sh +pre-commit run --all-files +``` + +Configured in `.pre-commit-config.yaml`: file hygiene, gitleaks (secret +scan), markdownlint, Conventional Commits validator (commit-msg), plus +`cargo fmt --check` and `cargo clippy --all-targets -- -D warnings` as +local hooks. The CI workflow runs the same set on every PR. + ## License Dual-licensed under MIT OR Apache-2.0.