Skip to content

Commit

Permalink
chore: setup tooling (privacy-scaling-explorations#2)
Browse files Browse the repository at this point in the history
* 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
sripwoud authored Jul 9, 2024
1 parent af0fd16 commit 770adbf
Show file tree
Hide file tree
Showing 16 changed files with 410 additions and 144 deletions.
20 changes: 20 additions & 0 deletions .dprint.jsonc
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",
],
}
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/---bug.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
14 changes: 7 additions & 7 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@

<!-- Please check if the PR fulfills these requirements. -->

- [ ] 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
38 changes: 38 additions & 0 deletions .github/workflows/docs.yml
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
76 changes: 42 additions & 34 deletions .github/workflows/main.yml
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
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
/target
.cargo/*
!.cargo/config.toml
Cargo.lock
target

.envrc
.tool-versions
139 changes: 139 additions & 0 deletions .setup.sh
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
30 changes: 15 additions & 15 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading

0 comments on commit 770adbf

Please sign in to comment.