forked from privacy-scaling-explorations/zk-kit.rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: setup tooling (privacy-scaling-explorations#2)
* chore: setup tooling Formatting, linting, conventional commits lint pre-push hook. GH workflows. Docs deployment * chore: format * ci: refactor main workflow Use different actions * chore: rename workflow * chore: delete crates/src * chore: add lint and fix tasks * chore: update build task * docs: update README * chore: include lint and build checks in main workflow * chore: reorg make tasks * chore: setup git core.editor to convco in setup * chore: remove comment * fix: update make help regex * fix: fix grammar * ci(docs): add redirect index.html page * refactor: include creation of pre-commit hook in setup * feat: use `--no-print-directory` flag in `Makefile` * style: indent log * fix: make setup.sh POSIX compliant remove `-o pipefail` option * feat: check if `make` is available * fix: use commit-msg hook to only lint current commit msg * feat: set convco commit as git core.editor * feat: integrate convco with git during setup * fix: call integrate_convco_with_git in main * fix: find default system editor * docs: update README
- Loading branch information
Showing
16 changed files
with
410 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: docs | ||
on: | ||
push: | ||
branches: [main] | ||
paths: ['src/**/*.rs', 'Cargo.toml', '.github/workflows/docs.yml'] | ||
workflow_dispatch: | ||
|
||
permissions: | ||
contents: read | ||
pages: write | ||
id-token: write | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: dtolnay/rust-toolchain@stable | ||
- uses: Swatinem/[email protected] | ||
- uses: actions/configure-pages@v5 | ||
- name: Build docs | ||
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 '<meta http-equiv="refresh" content="0;url=example/index.html">' > target/doc/index.html | ||
- uses: actions/upload-pages-artifact@v3 | ||
with: | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,48 @@ | ||
name: main | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
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 | ||
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install Rust | ||
uses: dtolnay/rust-toolchain@stable | ||
with: | ||
toolchain: stable | ||
components: rustfmt, clippy | ||
|
||
- name: Cache | ||
uses: Swatinem/rust-cache@v2 | ||
|
||
- 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 | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: dtolnay/rust-toolchain@stable | ||
- uses: Swatinem/[email protected] | ||
- run: make build | ||
|
||
format: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: taiki-e/[email protected] | ||
with: | ||
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/[email protected] | ||
- run: make lint | ||
|
||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: taiki-e/[email protected] | ||
with: | ||
tool: cargo-nextest | ||
- run: cargo nextest run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
/target | ||
.cargo/* | ||
!.cargo/config.toml | ||
Cargo.lock | ||
target | ||
|
||
.envrc | ||
.tool-versions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
#!/bin/sh | ||
set -eu | ||
|
||
ORANGE="\033[33m" | ||
RED="\033[31m" | ||
RESET="\033[0m" | ||
|
||
log() { | ||
printf "%b\n" "$1" | ||
} | ||
|
||
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" ] | ||
} | ||
|
||
install_local() { | ||
crate="$1" | ||
log "Installing $ORANGE$crate$RESET locally..." | ||
cargo install --root .cargo "$crate" | ||
} | ||
|
||
maybe_install_local() { | ||
crate="$1" | ||
if ! is_crate_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_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 | ||
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 | ||
} | ||
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_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) | ||
# 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" | ||
} | ||
|
||
end_log() { | ||
log "===================\nTo get started, you can run the make tasks defined in the Makefile.\n" | ||
make help | ||
} | ||
|
||
main() { | ||
is_make_available | ||
install_dev_deps | ||
write_hooks | ||
integrate_convco_with_git | ||
end_log | ||
} | ||
|
||
main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.