From 1d10b2b88d18e81efe91b0b196d7531624800164 Mon Sep 17 00:00:00 2001 From: sripwoud Date: Mon, 1 Jul 2024 16:27:27 +0200 Subject: [PATCH 01/26] chore: setup tooling Formatting, linting, conventional commits lint pre-push hook. GH workflows. Docs deployment --- .dprint.jsonc | 20 +++++++++ .github/workflows/docs.yml | 21 +++++++++ .github/workflows/pr.yml | 31 ++++++++++++++ .gitignore | 8 +++- .setup.sh | 88 ++++++++++++++++++++++++++++++++++++++ Makefile | 33 ++++++++++++++ crates/example/src/lib.rs | 15 +++++++ crates/example/src/main.rs | 3 -- crates/src/lib.rs | 15 +++++++ 9 files changed, 230 insertions(+), 4 deletions(-) create mode 100644 .dprint.jsonc create mode 100644 .github/workflows/docs.yml create mode 100644 .github/workflows/pr.yml create mode 100755 .setup.sh create mode 100644 Makefile create mode 100644 crates/example/src/lib.rs delete mode 100644 crates/example/src/main.rs create mode 100644 crates/src/lib.rs diff --git a/.dprint.jsonc b/.dprint.jsonc new file mode 100644 index 0000000..3d9a07c --- /dev/null +++ b/.dprint.jsonc @@ -0,0 +1,20 @@ +{ + "exec": { + "commands": [ + { + "command": "rustfmt", + "exts": ["rs"], + }, + ], + }, + "prettier": { + "singleQuote": true, + }, + "plugins": [ + "https://plugins.dprint.dev/exec-0.4.4.json@c207bf9b9a4ee1f0ecb75c594f774924baf62e8e53a2ce9d873816a408cecbf7", + "https://plugins.dprint.dev/json-0.19.3.wasm", + "https://plugins.dprint.dev/markdown-0.17.1.wasm", + "https://plugins.dprint.dev/toml-0.6.2.wasm", + "https://plugins.dprint.dev/prettier-0.40.0.json@68c668863ec834d4be0f6f5ccaab415df75336a992aceb7eeeb14fdf096a9e9c", + ], +} diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 0000000..540579f --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,21 @@ +name: Deploy docs +on: + push: + branches: [main] + paths: ['src/**/*.rs', 'Cargo.toml', '.github/workflows/docs.yml'] + workflow_dispatch: + +jobs: + deploy-docs: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + - uses: moonrepo/setup-rust@v1.2.0 + - name: Build docs + run: cargo doc --no-deps --all-features + - uses: peaceiris/actions-gh-pages@v4.0.0 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./target/doc diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 0000000..60283d0 --- /dev/null +++ b/.github/workflows/pr.yml @@ -0,0 +1,31 @@ +name: Pull Requests +# test +on: + pull_request: + types: [opened, reopened, synchronize] + branches: [main] + push: + branches: [main] + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + format-lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: taiki-e/cache-cargo-install-action@v2.0.1 + with: + tool: dprint + - run: make check + + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: taiki-e/cache-cargo-install-action@v2.0.1 + with: + tool: cargo-nextest + - run: cargo nextest run diff --git a/.gitignore b/.gitignore index ea8c4bf..d8bbebb 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,7 @@ -/target +.cargo/* +!.cargo/config.toml +Cargo.lock +target + +.envrc +.tool-versions diff --git a/.setup.sh b/.setup.sh new file mode 100755 index 0000000..85c96e0 --- /dev/null +++ b/.setup.sh @@ -0,0 +1,88 @@ +#!/bin/sh +set -eou pipefail + +CYAN="\033[36m" +ORANGE="\033[33m" +RESET="\033[0m" + +log() { + printf "%b\n" "$1" +} + +is_bin_locally_available() { + crate="$1" + [ -x ".cargo/bin/$crate" ] +} + +install_local() { + crate="$1" + log "Installing $ORANGE$crate$RESET locally..." + cargo install --root .cargo "$crate" +} + +maybe_install_local() { + crate="$1" + if ! is_bin_locally_available "$crate"; then + install_local "$crate" + else + log "$ORANGE$crate$RESET already installed locally. Skipping." + fi +} + +install_dev_deps() { + log "Installing development dependencies..." + crates="convco dprint cargo-nextest" + + for crate in $crates; do + maybe_install_local "$crate" + done +} + +write_pre_push_hook() { + cat >.git/hooks/pre-push <<'EOF' +#!/bin/sh +alias convco=.cargo/bin/convco + +# https://convco.github.io/check/ +z40=0000000000000000000000000000000000000000 + +while read -r _ local_sha _ remote_sha; do + if [ "$local_sha" != $z40 ]; then + if [ "$remote_sha" = $z40 ]; then + # New branch, examine all commits + range="$local_sha" + else + # Update to existing branch, examine new commits + range="$remote_sha..$local_sha" + fi + + # Check only the commits that are not in main + merge_base=$(git merge-base "$local_sha" main) + if [ -n $merge_base ];then + range="$merge_base..$local_sha" + fi + + # Check for WIP commit + if ! convco check "$range"; then + exit 1 + fi + fi +done +EOF + + chmod +x .git/hooks/pre-push + log "\nConventional commits lint hook written to .git/hooks/pre-push" +} + +end_log() { + log "\nTo get started, you can run the make tasks defined in the Makefile.\n" + make help | tail -n +2 | head -n -1 +} + +main() { + install_dev_deps + write_pre_push_hook + end_log +} + +main diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..caca81c --- /dev/null +++ b/Makefile @@ -0,0 +1,33 @@ +DEV_BIN_DIR := .cargo/bin +CYAN := \033[36m +RESET := \033[0m +export PATH := $(DEV_BIN_DIR):$(PATH) + +.PHONY: fmt build test setup + +help: ## display this help message (default task) + @printf "%b\n" "Usage: make [$(CYAN)task$(RESET)]" + @printf "%s\n" "Available tasks:" + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \ + awk 'BEGIN {FS = ":.*?## "}; {printf "$(CYAN)%-20s$(RESET) %s\n", $$1, $$2}' + +build: + @cargo build + +build.docs: ## build the documentation + @cargo doc --no-deps --all-features + +check: ## check that all files match formatting rules + @dprint check + +docs: ## build & open the documentation in the browser + @cargo doc --no-deps --open --all-features + +fmt: ## format all files + @dprint fmt + +setup: ## run the setup script to install dependencies + @./.setup.sh + +test: ## run all tests + @cargo-nextest ntr diff --git a/crates/example/src/lib.rs b/crates/example/src/lib.rs new file mode 100644 index 0000000..adbc56f --- /dev/null +++ b/crates/example/src/lib.rs @@ -0,0 +1,15 @@ +/// Adds two numbers together +pub fn add(left: usize, right: usize) -> usize { + left + right +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_works() { + let result = add(2, 2); + assert_eq!(result, 4); + } +} diff --git a/crates/example/src/main.rs b/crates/example/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/crates/example/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} diff --git a/crates/src/lib.rs b/crates/src/lib.rs new file mode 100644 index 0000000..adbc56f --- /dev/null +++ b/crates/src/lib.rs @@ -0,0 +1,15 @@ +/// Adds two numbers together +pub fn add(left: usize, right: usize) -> usize { + left + right +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_works() { + let result = add(2, 2); + assert_eq!(result, 4); + } +} From a47faf3af1d5d1b8792b786440d9397eb13d35f9 Mon Sep 17 00:00:00 2001 From: sripwoud Date: Mon, 1 Jul 2024 16:32:14 +0200 Subject: [PATCH 02/26] chore: format --- .github/ISSUE_TEMPLATE/---bug.md | 6 ++-- .github/pull_request_template.md | 14 ++++----- .github/workflows/main.yml | 52 ++++++++++++++++---------------- CODE_OF_CONDUCT.md | 30 +++++++++--------- CONTRIBUTING.md | 44 +++++++++++++-------------- Cargo.toml | 4 +-- README.md | 18 +++++------ crates/example/Cargo.toml | 14 ++++----- 8 files changed, 91 insertions(+), 91 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/---bug.md b/.github/ISSUE_TEMPLATE/---bug.md index 486c640..593029c 100644 --- a/.github/ISSUE_TEMPLATE/---bug.md +++ b/.github/ISSUE_TEMPLATE/---bug.md @@ -26,9 +26,9 @@ If applicable, add screenshots to help explain your problem. **Technologies (please complete the following information):** -- Node.js version -- NPM version -- Solidity version +- Node.js version +- NPM version +- Solidity version **Additional context** Add any other context about the problem here. diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 2aac60a..bfa786e 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -29,10 +29,10 @@ -- [ ] My code follows the style guidelines of this project -- [ ] I have performed a self-review of my code -- [ ] I have commented my code, particularly in hard-to-understand areas -- [ ] My changes generate no new warnings -- [ ] I have run `yarn format` and `yarn compile` without getting any errors -- [ ] I have added tests that prove my fix is effective or that my feature works -- [ ] New and existing unit tests pass locally with my changes +- [ ] My code follows the style guidelines of this project +- [ ] I have performed a self-review of my code +- [ ] I have commented my code, particularly in hard-to-understand areas +- [ ] My changes generate no new warnings +- [ ] I have run `yarn format` and `yarn compile` without getting any errors +- [ ] I have added tests that prove my fix is effective or that my feature works +- [ ] New and existing unit tests pass locally with my changes diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e90a675..1784df5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,40 +1,40 @@ name: main on: - push: - branches: - - main - pull_request: + push: + branches: + - main + pull_request: concurrency: - group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} - cancel-in-progress: true + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true jobs: - build: - runs-on: ubuntu-latest + build: + runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 + steps: + - name: Checkout + uses: actions/checkout@v4 - - name: Install Rust - uses: dtolnay/rust-toolchain@stable - with: - toolchain: stable - components: rustfmt, clippy + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + with: + toolchain: stable + components: rustfmt, clippy - - name: Cache - uses: Swatinem/rust-cache@v2 + - name: Cache + uses: Swatinem/rust-cache@v2 - - name: Build - run: cargo build --workspace --all-targets + - name: Build + run: cargo build --workspace --all-targets - - name: Run tests - run: cargo test --workspace --all-targets + - name: Run tests + run: cargo test --workspace --all-targets - - name: Run clippy - run: cargo clippy --workspace --all-targets -- -D warnings + - name: Run clippy + run: cargo clippy --workspace --all-targets -- -D warnings - - name: Run fmt check - run: cargo fmt -- --check + - name: Run fmt check + run: cargo fmt -- --check diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 0cb59ea..8014579 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -17,24 +17,24 @@ diverse, inclusive, and healthy community. Examples of behavior that contributes to a positive environment for our community include: -- Demonstrating empathy and kindness toward other people -- Being respectful of differing opinions, viewpoints, and experiences -- Giving and gracefully accepting constructive feedback -- Accepting responsibility and apologizing to those affected by our mistakes, - and learning from the experience -- Focusing on what is best not just for us as individuals, but for the - overall community +- Demonstrating empathy and kindness toward other people +- Being respectful of differing opinions, viewpoints, and experiences +- Giving and gracefully accepting constructive feedback +- Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +- Focusing on what is best not just for us as individuals, but for the + overall community Examples of unacceptable behavior include: -- The use of sexualized language or imagery, and sexual attention or - advances of any kind -- Trolling, insulting or derogatory comments, and personal or political attacks -- Public or private harassment -- Publishing others' private information, such as a physical or email - address, without their explicit permission -- Other conduct which could reasonably be considered inappropriate in a - professional setting +- The use of sexualized language or imagery, and sexual attention or + advances of any kind +- Trolling, insulting or derogatory comments, and personal or political attacks +- Public or private harassment +- Publishing others' private information, such as a physical or email + address, without their explicit permission +- Other conduct which could reasonably be considered inappropriate in a + professional setting ## Enforcement Responsibilities diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7bec00a..54e7384 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -30,7 +30,7 @@ Pull requests are great if you want to add a feature or fix a bug. Here's a quic 7. Push to your fork and submit a pull request on our `main` branch. Please provide us with some explanation of why you made the changes you made. For new features make sure to explain a standard use case to us. -> [!NOTE] +> [!NOTE]\ > When a new package is created or a new feature is added to the repository, the contributor will be added to the `.github/CODEOWNERS` file to review and approve any future changes to their code. ## CI (Github Actions) Tests @@ -63,17 +63,17 @@ The **header** is mandatory and the **scope** of the header is optional. The type must be one of the following: -- feat: A new feature -- fix: A bug fix -- docs: Documentation only changes -- style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc) -- refactor: A code change that neither fixes a bug nor adds a feature (improvements of the code structure) -- perf: A code change that improves the performance -- test: Adding missing or correcting existing tests -- build: Changes that affect the build system or external dependencies (example scopes: gulp, npm) -- ci: Changes to CI configuration files and scripts (example scopes: travis, circle) -- chore: Other changes that don't modify src or test files -- revert: Reverts a previous commit +- feat: A new feature +- fix: A bug fix +- docs: Documentation only changes +- style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc) +- refactor: A code change that neither fixes a bug nor adds a feature (improvements of the code structure) +- perf: A code change that improves the performance +- test: Adding missing or correcting existing tests +- build: Changes that affect the build system or external dependencies (example scopes: gulp, npm) +- ci: Changes to CI configuration files and scripts (example scopes: travis, circle) +- chore: Other changes that don't modify src or test files +- revert: Reverts a previous commit #### Scope @@ -83,9 +83,9 @@ The scope should be the name of the npm package affected (as perceived by the pe The subject contains a succinct description of the change: -- Use the imperative, present tense: "change" not "changed" nor "changes" -- Don't capitalize the first letter -- No dot (.) at the end +- Use the imperative, present tense: "change" not "changed" nor "changes" +- Don't capitalize the first letter +- No dot (.) at the end #### Body @@ -93,13 +93,13 @@ Just as in the subject, use the imperative, present tense: "change" not "changed ### Branch rules -- There must be a `main` branch, used only for the releases. -- Avoid long descriptive names for long-lived branches. -- Use kebab-case (no CamelCase). -- Use grouping tokens (words) at the beginning of your branch names (in a similar way to the `type` of commit). -- Define and use short lead tokens to differentiate branches in a way that is meaningful to your workflow. -- Use slashes to separate parts of your branch names. -- Remove branch after merge if it is not important. +- There must be a `main` branch, used only for the releases. +- Avoid long descriptive names for long-lived branches. +- Use kebab-case (no CamelCase). +- Use grouping tokens (words) at the beginning of your branch names (in a similar way to the `type` of commit). +- Define and use short lead tokens to differentiate branches in a way that is meaningful to your workflow. +- Use slashes to separate parts of your branch names. +- Remove branch after merge if it is not important. Examples: diff --git a/Cargo.toml b/Cargo.toml index e998a11..4e8a665 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,11 +3,11 @@ [workspace] resolver = "2" members = [ - "crates/*" + "crates/*", ] [workspace.package] version = "0.0.1" -license = "MIT" edition = "2021" +license = "MIT" publish = false diff --git a/README.md b/README.md index a33a737..912c086 100644 --- a/README.md +++ b/README.md @@ -46,11 +46,11 @@ ## 🗂️ Repositories -- Javascript: https://github.com/privacy-scaling-explorations/zk-kit -- Rust: https://github.com/privacy-scaling-explorations/zk-kit.rust -- Solidity: https://github.com/privacy-scaling-explorations/zk-kit.solidity -- Circom: https://github.com/privacy-scaling-explorations/zk-kit.circom -- Noir: https://github.com/privacy-scaling-explorations/zk-kit.noir +- Javascript: https://github.com/privacy-scaling-explorations/zk-kit +- Rust: https://github.com/privacy-scaling-explorations/zk-kit.rust +- Solidity: https://github.com/privacy-scaling-explorations/zk-kit.solidity +- Circom: https://github.com/privacy-scaling-explorations/zk-kit.circom +- Noir: https://github.com/privacy-scaling-explorations/zk-kit.noir ## 📦 Crates @@ -87,10 +87,10 @@ ## 👥 Ways to contribute -- 🔧 Work on [open issues](https://github.com/privacy-scaling-explorations/zk-kit.rust/contribute) -- 📦 Suggest new [crates](https://github.com/privacy-scaling-explorations/zk-kit.rust/issues/new?assignees=&labels=feature+%3Arocket%3A&template=---crate.md&title=) -- 🚀 Share ideas for new [features](https://github.com/privacy-scaling-explorations/zk-kit.rust/issues/new?assignees=&labels=feature+%3Arocket%3A&template=---feature.md&title=) -- 🐛 Create a report if you find any [bugs](https://github.com/privacy-scaling-explorations/zk-kit.rust/issues/new?assignees=&labels=bug+%F0%9F%90%9B&template=---bug.md&title=) in the code +- 🔧 Work on [open issues](https://github.com/privacy-scaling-explorations/zk-kit.rust/contribute) +- 📦 Suggest new [crates](https://github.com/privacy-scaling-explorations/zk-kit.rust/issues/new?assignees=&labels=feature+%3Arocket%3A&template=---crate.md&title=) +- 🚀 Share ideas for new [features](https://github.com/privacy-scaling-explorations/zk-kit.rust/issues/new?assignees=&labels=feature+%3Arocket%3A&template=---feature.md&title=) +- 🐛 Create a report if you find any [bugs](https://github.com/privacy-scaling-explorations/zk-kit.rust/issues/new?assignees=&labels=bug+%F0%9F%90%9B&template=---bug.md&title=) in the code ## 🛠 Install diff --git a/crates/example/Cargo.toml b/crates/example/Cargo.toml index ecf2992..4674cf7 100644 --- a/crates/example/Cargo.toml +++ b/crates/example/Cargo.toml @@ -3,15 +3,15 @@ [package] name = "example" version = "0.1.0" -authors = [ "Pinco" ] -description = "Just an example." -homepage = "https://arkworks.rs" -repository = "privacy-scaling-explorations/zk-kit.rust" -documentation = "https://docs.rs/example" -keywords = ["cryptography", "finite-fields", "elliptic-curves" ] +authors = ["Pinco"] categories = ["cryptography"] +documentation = "https://docs.rs/example" +edition = "2021" +homepage = "https://arkworks.rs" include = ["Cargo.toml", "src", "README.md", "LICENSE"] +keywords = ["cryptography", "finite-fields", "elliptic-curves"] license = "MIT" -edition = "2021" +repository = "privacy-scaling-explorations/zk-kit.rust" +description = "Just an example." [dependencies] From 540818970d49f8c0b68f572c7873503761be7073 Mon Sep 17 00:00:00 2001 From: sripwoud Date: Mon, 1 Jul 2024 16:38:56 +0200 Subject: [PATCH 03/26] ci: refactor main workflow Use different actions --- .github/workflows/docs.yml | 5 ++-- .github/workflows/main.yml | 47 +++++++++++++++----------------------- .github/workflows/pr.yml | 31 ------------------------- 3 files changed, 22 insertions(+), 61 deletions(-) delete mode 100644 .github/workflows/pr.yml diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 540579f..40b6946 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -1,4 +1,4 @@ -name: Deploy docs +name: docs on: push: branches: [main] @@ -12,7 +12,8 @@ jobs: contents: write steps: - uses: actions/checkout@v4 - - uses: moonrepo/setup-rust@v1.2.0 + - uses: dtolnay/rust-toolchain@stable + - uses: Swatinem/rust-cache@v2.7.3 - name: Build docs run: cargo doc --no-deps --all-features - uses: peaceiris/actions-gh-pages@v4.0.0 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1784df5..60283d0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,40 +1,31 @@ -name: main - +name: Pull Requests +# test on: - push: - branches: - - main pull_request: + types: [opened, reopened, synchronize] + branches: [main] + push: + branches: [main] concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} cancel-in-progress: true jobs: - build: + format-lint: runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Install Rust - uses: dtolnay/rust-toolchain@stable + - uses: actions/checkout@v4 + - uses: taiki-e/cache-cargo-install-action@v2.0.1 with: - toolchain: stable - components: rustfmt, clippy - - - name: Cache - uses: Swatinem/rust-cache@v2 + tool: dprint + - run: make check - - name: Build - run: cargo build --workspace --all-targets - - - name: Run tests - run: cargo test --workspace --all-targets - - - name: Run clippy - run: cargo clippy --workspace --all-targets -- -D warnings - - - name: Run fmt check - run: cargo fmt -- --check + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: taiki-e/cache-cargo-install-action@v2.0.1 + with: + tool: cargo-nextest + - run: cargo nextest run diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml deleted file mode 100644 index 60283d0..0000000 --- a/.github/workflows/pr.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: Pull Requests -# test -on: - pull_request: - types: [opened, reopened, synchronize] - branches: [main] - push: - branches: [main] - -concurrency: - group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} - cancel-in-progress: true - -jobs: - format-lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: taiki-e/cache-cargo-install-action@v2.0.1 - with: - tool: dprint - - run: make check - - test: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: taiki-e/cache-cargo-install-action@v2.0.1 - with: - tool: cargo-nextest - - run: cargo nextest run From b558b7c4b5e95b28bee744bb657cdcd967463522 Mon Sep 17 00:00:00 2001 From: sripwoud Date: Mon, 1 Jul 2024 16:39:58 +0200 Subject: [PATCH 04/26] chore: rename workflow --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 60283d0..e6d5f89 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,4 +1,4 @@ -name: Pull Requests +name: main # test on: pull_request: From 839951e948ebcdd58c7d3b6fad100444bde334e2 Mon Sep 17 00:00:00 2001 From: sripwoud Date: Mon, 1 Jul 2024 16:40:28 +0200 Subject: [PATCH 05/26] chore: delete crates/src --- crates/src/lib.rs | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 crates/src/lib.rs diff --git a/crates/src/lib.rs b/crates/src/lib.rs deleted file mode 100644 index adbc56f..0000000 --- a/crates/src/lib.rs +++ /dev/null @@ -1,15 +0,0 @@ -/// Adds two numbers together -pub fn add(left: usize, right: usize) -> usize { - left + right -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); - } -} From 5b2919bc809ae64a77a6531fed8496118cc5a03b Mon Sep 17 00:00:00 2001 From: sripwoud Date: Mon, 1 Jul 2024 16:51:40 +0200 Subject: [PATCH 06/26] chore: add lint and fix tasks --- Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Makefile b/Makefile index caca81c..84cdde5 100644 --- a/Makefile +++ b/Makefile @@ -26,6 +26,12 @@ docs: ## build & open the documentation in the browser fmt: ## format all files @dprint fmt +lint: ## lint code + @cargo clippy --all-targets --all-features --workspace + +fix: ## apply lint suggestion + @cargo clippy --all-targets --all-features --workspace --fix + setup: ## run the setup script to install dependencies @./.setup.sh From 069ecbbe7702044f869d6a796e3802480030dba8 Mon Sep 17 00:00:00 2001 From: sripwoud Date: Mon, 1 Jul 2024 16:56:01 +0200 Subject: [PATCH 07/26] chore: update build task --- Cargo.lock | 4 ---- Makefile | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1f20ad5..21d186b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5,7 +5,3 @@ version = 3 [[package]] name = "example" version = "0.1.0" - -[[package]] -name = "example-2" -version = "0.1.0" diff --git a/Makefile b/Makefile index 84cdde5..261d23a 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ help: ## display this help message (default task) awk 'BEGIN {FS = ":.*?## "}; {printf "$(CYAN)%-20s$(RESET) %s\n", $$1, $$2}' build: - @cargo build + @cargo build --workspace --all-features --all-targets --release build.docs: ## build the documentation @cargo doc --no-deps --all-features From 3827baac5dbc253e38e6d4f7c1596e87a24d8635 Mon Sep 17 00:00:00 2001 From: sripwoud Date: Mon, 1 Jul 2024 17:02:58 +0200 Subject: [PATCH 08/26] docs: update README --- README.md | 85 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 44 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 912c086..1a3423a 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@   |   - 🤝 Code of conduct + 🤝 Code of Conduct   |   @@ -46,19 +46,23 @@ ## 🗂️ Repositories -- Javascript: https://github.com/privacy-scaling-explorations/zk-kit -- Rust: https://github.com/privacy-scaling-explorations/zk-kit.rust -- Solidity: https://github.com/privacy-scaling-explorations/zk-kit.solidity -- Circom: https://github.com/privacy-scaling-explorations/zk-kit.circom -- Noir: https://github.com/privacy-scaling-explorations/zk-kit.noir +- **JavaScript:** [zk-kit](https://github.com/privacy-scaling-explorations/zk-kit) +- **Rust:** [zk-kit.rust](https://github.com/privacy-scaling-explorations/zk-kit.rust) +- **Solidity:** [zk-kit.solidity](https://github.com/privacy-scaling-explorations/zk-kit.solidity) +- **Circom:** [zk-kit.circom](https://github.com/privacy-scaling-explorations/zk-kit.circom) +- **Noir:** [zk-kit.noir](https://github.com/privacy-scaling-explorations/zk-kit.noir) ## 📦 Crates - - - - + + + + + + + +
PackageVersionDownloadsAudited
PackageVersionDownloadsAudited
@@ -67,13 +71,11 @@ - Crate version - Crate downloads @@ -85,71 +87,72 @@
-## 👥 Ways to contribute +## 👥 Ways to Contribute - 🔧 Work on [open issues](https://github.com/privacy-scaling-explorations/zk-kit.rust/contribute) - 📦 Suggest new [crates](https://github.com/privacy-scaling-explorations/zk-kit.rust/issues/new?assignees=&labels=feature+%3Arocket%3A&template=---crate.md&title=) - 🚀 Share ideas for new [features](https://github.com/privacy-scaling-explorations/zk-kit.rust/issues/new?assignees=&labels=feature+%3Arocket%3A&template=---feature.md&title=) - 🐛 Create a report if you find any [bugs](https://github.com/privacy-scaling-explorations/zk-kit.rust/issues/new?assignees=&labels=bug+%F0%9F%90%9B&template=---bug.md&title=) in the code -## 🛠 Install - -Clone this repository: +## 🛠 Setup ```bash -git clone https://github.com/privacy-scaling-explorations/zk-kit.rust.git +git clone https://github.com/privacy-scaling-explorations/zk-kit.rust.git && make setup ``` -and install the dependencies: - -```bash -cd zk-kit.rust && cargo build -``` +This will clone this repository and install the required development dependencies locally. ## 📜 Usage -### Code quality and formatting +You can view the available tasks with: -Run [rustfmt](https://github.com/rust-lang/rustfmt) to check formatting rules: +```commandline +make +``` -```bash -cargo fmt -- --check +### Code Quality and Formatting + +You can proof your code for consistency with our formatting rules: + +```commandline +make check ``` or automatically format the code: -```bash -cargo fmt +```commandline +make fmt ``` -Run [Clippy](https://github.com/rust-lang/rust-clippy) to analyze the code and catch bugs: +To lint and analyze the code for potential bugs: -```bash -cargo clippy --workspace --all-targets +```commandline +make lint ``` -or automatically apply suggestions: +or automatically apply lint fix suggestions: -```bash -cargo clippy --workspace --fix +```commandline +make fix ``` ### Conventional commits -ZK-Kit uses [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/). We therefore suggest using tools such as [cocogitto](https://docs.cocogitto.io). +ZK-Kit uses [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/).\ +Compliance with these rules is enforced with a pre-push git hook, which was set up when you ran `make setup`. ### Testing -Test the code: +To test the code: -```bash -cargo test --workspace --all-targets +```commandline +make test ``` ### Build -Build crates: +To build crates: -```bash -cargo build --workspace --all-targets +```commandline +make build ``` From 4ddf2918ff119815d58fc2213818d9878b9ebee3 Mon Sep 17 00:00:00 2001 From: sripwoud Date: Mon, 1 Jul 2024 17:08:31 +0200 Subject: [PATCH 09/26] chore: include lint and build checks in main workflow --- .github/workflows/main.yml | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e6d5f89..25cea0b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,7 +12,15 @@ concurrency: cancel-in-progress: true jobs: - format-lint: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - uses: Swatinem/rust-cache@v2.7.3 + - run: make build + + format: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -21,6 +29,16 @@ jobs: tool: dprint - run: make check + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + with: + components: clippy + - uses: Swatinem/rust-cache@v2.7.3 + - run: make lint + test: runs-on: ubuntu-latest steps: From 72ed07dbe91ebdd96163c73cd5e035ad891a9fbf Mon Sep 17 00:00:00 2001 From: sripwoud Date: Mon, 1 Jul 2024 17:24:11 +0200 Subject: [PATCH 10/26] chore: reorg make tasks --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 261d23a..650dd77 100644 --- a/Makefile +++ b/Makefile @@ -23,15 +23,15 @@ check: ## check that all files match formatting rules docs: ## build & open the documentation in the browser @cargo doc --no-deps --open --all-features +fix: ## apply lint suggestion + @cargo clippy --all-targets --all-features --workspace --fix + fmt: ## format all files @dprint fmt lint: ## lint code @cargo clippy --all-targets --all-features --workspace -fix: ## apply lint suggestion - @cargo clippy --all-targets --all-features --workspace --fix - setup: ## run the setup script to install dependencies @./.setup.sh From e24ecd397700dd64c41878a081531b64b9c02296 Mon Sep 17 00:00:00 2001 From: sripwoud Date: Mon, 1 Jul 2024 17:35:56 +0200 Subject: [PATCH 11/26] chore: setup git core.editor to convco in setup --- .setup.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.setup.sh b/.setup.sh index 85c96e0..4d76390 100755 --- a/.setup.sh +++ b/.setup.sh @@ -74,6 +74,10 @@ EOF log "\nConventional commits lint hook written to .git/hooks/pre-push" } +setup_convco() { + git config --local core.editor ".cargo/bin/convco commit" +} + end_log() { log "\nTo get started, you can run the make tasks defined in the Makefile.\n" make help | tail -n +2 | head -n -1 @@ -82,6 +86,7 @@ end_log() { main() { install_dev_deps write_pre_push_hook + setup_convco end_log } From c3455b5f03b133061a72d458a7eaa38899b022c1 Mon Sep 17 00:00:00 2001 From: sripwoud Date: Mon, 1 Jul 2024 21:22:10 +0200 Subject: [PATCH 12/26] chore: remove comment --- .github/workflows/main.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 25cea0b..7069881 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,5 +1,4 @@ name: main -# test on: pull_request: types: [opened, reopened, synchronize] From b2e81b6561e6b3e1edc0e170d4faa9cb36b14c3d Mon Sep 17 00:00:00 2001 From: sripwoud Date: Mon, 1 Jul 2024 21:38:17 +0200 Subject: [PATCH 13/26] fix: update make help regex --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 650dd77..4755118 100644 --- a/Makefile +++ b/Makefile @@ -3,15 +3,15 @@ CYAN := \033[36m RESET := \033[0m export PATH := $(DEV_BIN_DIR):$(PATH) -.PHONY: fmt build test setup +.PHONY: help build build.docs fix fmt lint setup test help: ## display this help message (default task) @printf "%b\n" "Usage: make [$(CYAN)task$(RESET)]" @printf "%s\n" "Available tasks:" - @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \ + @grep -E '^[a-zA-Z_]+(\.[a-zA-Z_]+)*:.*?## .*$$' $(MAKEFILE_LIST) | \ awk 'BEGIN {FS = ":.*?## "}; {printf "$(CYAN)%-20s$(RESET) %s\n", $$1, $$2}' -build: +build: ## build the project @cargo build --workspace --all-features --all-targets --release build.docs: ## build the documentation From 16605212593d2cad13b669d8ddffe7f251159a9b Mon Sep 17 00:00:00 2001 From: sripwoud Date: Mon, 1 Jul 2024 21:43:53 +0200 Subject: [PATCH 14/26] fix: fix grammar --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 4755118..fc3fa00 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ check: ## check that all files match formatting rules docs: ## build & open the documentation in the browser @cargo doc --no-deps --open --all-features -fix: ## apply lint suggestion +fix: ## apply lint suggestions @cargo clippy --all-targets --all-features --workspace --fix fmt: ## format all files From 5d546fe3ccacf12509e96b2862eed32dadfe2e9e Mon Sep 17 00:00:00 2001 From: sripwoud Date: Tue, 2 Jul 2024 07:58:35 +0200 Subject: [PATCH 15/26] ci(docs): add redirect index.html page --- .github/workflows/docs.yml | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 40b6946..d0badd1 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -5,18 +5,34 @@ on: paths: ['src/**/*.rs', 'Cargo.toml', '.github/workflows/docs.yml'] workflow_dispatch: +permissions: + contents: read + pages: write + id-token: write + jobs: - deploy-docs: + build: runs-on: ubuntu-latest - permissions: - contents: write steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v2.7.3 + - uses: actions/configure-pages@v5 - name: Build docs - run: cargo doc --no-deps --all-features - - uses: peaceiris/actions-gh-pages@v4.0.0 + run: | + make build.docs + # we need an index.html page (cargo doc doesn't create it) + # this will just redirect to target/doc/example/index.html + echo '' > target/doc/index.html + - uses: actions/upload-pages-artifact@v3 with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./target/doc + path: target/doc + deploy: + needs: build + runs-on: ubuntu-latest + environment: + name: github-pages + url: ${{ steps.deploy.outputs.page_url }} + steps: + - uses: actions/deploy-pages@v4 + id: deploy From 0cdd2a6cc7cd2bf55319dbe04df0d5ab8a136149 Mon Sep 17 00:00:00 2001 From: sripwoud Date: Tue, 2 Jul 2024 08:20:49 +0200 Subject: [PATCH 16/26] refactor: include creation of pre-commit hook in setup --- .setup.sh | 20 +++++++++++++------- Makefile | 3 +++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/.setup.sh b/.setup.sh index 4d76390..245089b 100755 --- a/.setup.sh +++ b/.setup.sh @@ -1,7 +1,6 @@ #!/bin/sh set -eou pipefail -CYAN="\033[36m" ORANGE="\033[33m" RESET="\033[0m" @@ -71,22 +70,29 @@ done EOF chmod +x .git/hooks/pre-push - log "\nConventional commits lint hook written to .git/hooks/pre-push" + log " .git/hooks/pre-push (conventional commits linting)" } -setup_convco() { - git config --local core.editor ".cargo/bin/convco commit" +write_pre_commit_hook() { + echo "make fmt" >.git/hooks/pre-commit + chmod +x .git/hooks/pre-commit + log " .git/hooks/pre-commit (formatting)" +} + +write_hooks() { + log "Writing hooks..." + write_pre_commit_hook + write_pre_push_hook } end_log() { - log "\nTo get started, you can run the make tasks defined in the Makefile.\n" + log "===================\nTo get started, you can run the make tasks defined in the Makefile.\n" make help | tail -n +2 | head -n -1 } main() { install_dev_deps - write_pre_push_hook - setup_convco + write_hooks end_log } diff --git a/Makefile b/Makefile index fc3fa00..22f39f9 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,9 @@ build.docs: ## build the documentation check: ## check that all files match formatting rules @dprint check +commit: ## make conventional commit + @.cargo/bin/convco commit + docs: ## build & open the documentation in the browser @cargo doc --no-deps --open --all-features From 16c2ce5c8d275952fa3881df1a92d79e4a10c651 Mon Sep 17 00:00:00 2001 From: sripwoud Date: Tue, 2 Jul 2024 08:31:02 +0200 Subject: [PATCH 17/26] feat: use `--no-print-directory` flag in `Makefile` --- .setup.sh | 2 +- Makefile | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.setup.sh b/.setup.sh index 245089b..fb9a233 100755 --- a/.setup.sh +++ b/.setup.sh @@ -87,7 +87,7 @@ write_hooks() { end_log() { log "===================\nTo get started, you can run the make tasks defined in the Makefile.\n" - make help | tail -n +2 | head -n -1 + make help } main() { diff --git a/Makefile b/Makefile index 22f39f9..847073a 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +MAKEFLAGS += --no-print-directory + DEV_BIN_DIR := .cargo/bin CYAN := \033[36m RESET := \033[0m From 263294bd9b5045495be56dfade009184be095ed8 Mon Sep 17 00:00:00 2001 From: sripwoud Date: Tue, 2 Jul 2024 08:41:44 +0200 Subject: [PATCH 18/26] style: indent log --- .setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.setup.sh b/.setup.sh index fb9a233..b295181 100755 --- a/.setup.sh +++ b/.setup.sh @@ -24,7 +24,7 @@ maybe_install_local() { if ! is_bin_locally_available "$crate"; then install_local "$crate" else - log "$ORANGE$crate$RESET already installed locally. Skipping." + log " $ORANGE$crate$RESET already installed locally. Skipping." fi } From ec9ce9ff4b122bce2cbf585325b664260ed614ca Mon Sep 17 00:00:00 2001 From: sripwoud Date: Tue, 2 Jul 2024 13:22:35 +0200 Subject: [PATCH 19/26] fix: make setup.sh POSIX compliant remove `-o pipefail` option --- .setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.setup.sh b/.setup.sh index b295181..9af16d1 100755 --- a/.setup.sh +++ b/.setup.sh @@ -1,5 +1,5 @@ #!/bin/sh -set -eou pipefail +set -eu ORANGE="\033[33m" RESET="\033[0m" From 8ae4261b07d8c8ec45664877a6dc43e1f67f86a4 Mon Sep 17 00:00:00 2001 From: sripwoud Date: Tue, 2 Jul 2024 14:04:22 +0200 Subject: [PATCH 20/26] feat: check if `make` is available --- .setup.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/.setup.sh b/.setup.sh index 9af16d1..9e5f8ff 100755 --- a/.setup.sh +++ b/.setup.sh @@ -2,13 +2,21 @@ set -eu ORANGE="\033[33m" +RED="\033[31m" RESET="\033[0m" log() { printf "%b\n" "$1" } -is_bin_locally_available() { +is_make_available() { + if ! command -v make >/dev/null; then + log "${RED}error: make is not available.$RESET\nPlease install ${ORANGE}make$RESET for your OS and run this script again." + return 1 + fi +} + +is_crate_bin_locally_available() { crate="$1" [ -x ".cargo/bin/$crate" ] } @@ -21,7 +29,7 @@ install_local() { maybe_install_local() { crate="$1" - if ! is_bin_locally_available "$crate"; then + if ! is_crate_bin_locally_available "$crate"; then install_local "$crate" else log " $ORANGE$crate$RESET already installed locally. Skipping." @@ -91,6 +99,7 @@ end_log() { } main() { + is_make_available install_dev_deps write_hooks end_log From b2e79f373c36fc682dc3a291e6b7c848ea391cf2 Mon Sep 17 00:00:00 2001 From: sripwoud Date: Tue, 9 Jul 2024 09:19:15 +0200 Subject: [PATCH 21/26] fix: use commit-msg hook to only lint current commit msg --- .setup.sh | 50 ++++++++++++++++++-------------------------------- 1 file changed, 18 insertions(+), 32 deletions(-) diff --git a/.setup.sh b/.setup.sh index 9e5f8ff..f173ec5 100755 --- a/.setup.sh +++ b/.setup.sh @@ -45,52 +45,38 @@ install_dev_deps() { done } -write_pre_push_hook() { - cat >.git/hooks/pre-push <<'EOF' +write_pre_commit_hook() { + echo "make fmt" >.git/hooks/pre-commit + chmod +x .git/hooks/pre-commit + log " .git/hooks/pre-commit (formatting)" +} + +write_commit_msg_hook() { + cat >.git/hooks/commit-msg <<'EOF' #!/bin/sh alias convco=.cargo/bin/convco # https://convco.github.io/check/ z40=0000000000000000000000000000000000000000 -while read -r _ local_sha _ remote_sha; do - if [ "$local_sha" != $z40 ]; then - if [ "$remote_sha" = $z40 ]; then - # New branch, examine all commits - range="$local_sha" - else - # Update to existing branch, examine new commits - range="$remote_sha..$local_sha" - fi - - # Check only the commits that are not in main - merge_base=$(git merge-base "$local_sha" main) - if [ -n $merge_base ];then - range="$merge_base..$local_sha" - fi - - # Check for WIP commit - if ! convco check "$range"; then - exit 1 - fi +main() { + if ! cat .git/COMMIT_EDITMSG | convco check --from-stdin --ignore-reverts;then + printf "%s\n" "Please refer to https://www.conventionalcommits.org/en/v1.0.0" + exit 1 fi -done -EOF - - chmod +x .git/hooks/pre-push - log " .git/hooks/pre-push (conventional commits linting)" } -write_pre_commit_hook() { - echo "make fmt" >.git/hooks/pre-commit - chmod +x .git/hooks/pre-commit - log " .git/hooks/pre-commit (formatting)" +main +EOF + + chmod +x .git/hooks/commit-msg + log " .git/hooks/commit-msg (conventional commits linting)" } write_hooks() { log "Writing hooks..." write_pre_commit_hook - write_pre_push_hook + write_commit_msg_hook } end_log() { From c2fbaaf0016fe7ea7a74e264d5197268239e6039 Mon Sep 17 00:00:00 2001 From: sripwoud Date: Tue, 9 Jul 2024 09:25:33 +0200 Subject: [PATCH 22/26] feat: set convco commit as git core.editor --- .setup.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.setup.sh b/.setup.sh index f173ec5..aeb5faa 100755 --- a/.setup.sh +++ b/.setup.sh @@ -79,6 +79,11 @@ write_hooks() { write_commit_msg_hook } +integrate_convco_with_git() { + git config --local core.editor ".cargo/bin/convco commit" + log "Integrating convco with git..." +} + end_log() { log "===================\nTo get started, you can run the make tasks defined in the Makefile.\n" make help From 17b7a65006b8441f5eba991f417557ccde8080fb Mon Sep 17 00:00:00 2001 From: sripwoud Date: Tue, 9 Jul 2024 09:36:38 +0200 Subject: [PATCH 23/26] feat: integrate convco with git during setup --- .setup.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.setup.sh b/.setup.sh index aeb5faa..21687b0 100755 --- a/.setup.sh +++ b/.setup.sh @@ -81,7 +81,9 @@ write_hooks() { integrate_convco_with_git() { git config --local core.editor ".cargo/bin/convco commit" - log "Integrating convco with git..." + # do not use convco for interactive rebase (git rebase -i) + git config --local sequence.editor "$EDITOR" + log "Integrated convco with git" } end_log() { From 1b82e9dc08e815293dc929c1196fc6a1db95ae72 Mon Sep 17 00:00:00 2001 From: sripwoud Date: Tue, 9 Jul 2024 09:44:22 +0200 Subject: [PATCH 24/26] fix: call integrate_convco_with_git in main --- .setup.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/.setup.sh b/.setup.sh index 21687b0..5d12ae5 100755 --- a/.setup.sh +++ b/.setup.sh @@ -95,6 +95,7 @@ main() { is_make_available install_dev_deps write_hooks + integrate_convco_with_git end_log } From 99464200c051313575f92a4879690e11e8fc385b Mon Sep 17 00:00:00 2001 From: sripwoud Date: Tue, 9 Jul 2024 12:39:27 +0200 Subject: [PATCH 25/26] fix: find default system editor --- .setup.sh | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/.setup.sh b/.setup.sh index 5d12ae5..772cf9b 100755 --- a/.setup.sh +++ b/.setup.sh @@ -79,10 +79,47 @@ write_hooks() { write_commit_msg_hook } +find_editor() { + editor="" + global_git_editor=$(git config --global --get core.editor || true) + + if [ -n "$global_git_editor" ]; then + editor="$global_git_editor" + elif [ -n "$EDITOR" ]; then + editor="$EDITOR" + elif command -v nvim >/dev/null; then + editor="nvim" + elif command -v vim >/dev/null; then + editor="vim" + elif command -v vi >/dev/null; then + editor="vi" + elif command -v code >/dev/null; then + editor="code" + elif command -v emacs >/dev/null; then + editor="emacs" + elif command -v nano >/dev/null; then + editor="nano" + elif command -v notepad >/dev/null; then + editor="notepad" + fi + + echo "$editor" +} + integrate_convco_with_git() { git config --local core.editor ".cargo/bin/convco commit" + # do not use convco for interactive rebase (git rebase -i) - git config --local sequence.editor "$EDITOR" + # use system's default editor instead + editor=$(find_editor) + + if [ -n "$editor" ]; then + git config --local sequence.editor "$editor" + else + log "${RED}error: No editor found.$RESET" + log "Please set the ${ORANGE}EDITOR$RESET environment variable to your preferred editor and run ${ORANGE}make setup$RESET again." + fi + log "Integrated convco with git" } From 1aed3ded0d0c72cdee56f4d448aa728e01d2f324 Mon Sep 17 00:00:00 2001 From: sripwoud Date: Tue, 9 Jul 2024 13:11:31 +0200 Subject: [PATCH 26/26] docs: update README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1a3423a..f7b4a93 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,7 @@ You can proof your code for consistency with our formatting rules: make check ``` -or automatically format the code: +or automatically format the code (performed automatically in a `pre-commit` hook): ```commandline make fmt @@ -139,7 +139,7 @@ make fix ### Conventional commits ZK-Kit uses [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/).\ -Compliance with these rules is enforced with a pre-push git hook, which was set up when you ran `make setup`. +Compliance with these rules is enforced with a `commit-msg` git hook, which was set up when you ran `make setup`. ### Testing