Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: setup tooling #2

Merged
merged 26 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1d10b2b
chore: setup tooling
sripwoud Jul 1, 2024
a47faf3
chore: format
sripwoud Jul 1, 2024
5408189
ci: refactor main workflow
sripwoud Jul 1, 2024
b558b7c
chore: rename workflow
sripwoud Jul 1, 2024
839951e
chore: delete crates/src
sripwoud Jul 1, 2024
5b2919b
chore: add lint and fix tasks
sripwoud Jul 1, 2024
069ecbb
chore: update build task
sripwoud Jul 1, 2024
3827baa
docs: update README
sripwoud Jul 1, 2024
4ddf291
chore: include lint and build checks in main workflow
sripwoud Jul 1, 2024
72ed07d
chore: reorg make tasks
sripwoud Jul 1, 2024
e24ecd3
chore: setup git core.editor to convco in setup
sripwoud Jul 1, 2024
c3455b5
chore: remove comment
sripwoud Jul 1, 2024
b2e81b6
fix: update make help regex
sripwoud Jul 1, 2024
1660521
fix: fix grammar
sripwoud Jul 1, 2024
5d546fe
ci(docs): add redirect index.html page
sripwoud Jul 2, 2024
0cdd2a6
refactor: include creation of pre-commit hook in setup
sripwoud Jul 2, 2024
16c2ce5
feat: use `--no-print-directory` flag in `Makefile`
sripwoud Jul 2, 2024
263294b
style: indent log
sripwoud Jul 2, 2024
ec9ce9f
fix: make setup.sh POSIX compliant
sripwoud Jul 2, 2024
8ae4261
feat: check if `make` is available
sripwoud Jul 2, 2024
b2e79f3
fix: use commit-msg hook to only lint current commit msg
sripwoud Jul 9, 2024
c2fbaaf
feat: set convco commit as git core.editor
sripwoud Jul 9, 2024
17b7a65
feat: integrate convco with git during setup
sripwoud Jul 9, 2024
1b82e9d
fix: call integrate_convco_with_git in main
sripwoud Jul 9, 2024
9946420
fix: find default system editor
sripwoud Jul 9, 2024
1aed3de
docs: update README
sripwoud Jul 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
sripwoud marked this conversation as resolved.
Show resolved Hide resolved
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']
cedoor marked this conversation as resolved.
Show resolved Hide resolved
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]
sripwoud marked this conversation as resolved.
Show resolved Hide resolved
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