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

feat(cargo-husky): Adds pre-commit and pre-push hooks #241

Merged
merged 5 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 31 additions & 0 deletions .cargo-husky/hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh
#
# This hook was set by cargo-husky v1.5.0: https://github.com/rhysd/cargo-husky#readme
# Generated by script /Users/shufflebottomhogwood/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-husky-1.5.0/build.rs
# Output at /Users/shufflebottomhogwood/Code/excalibur/target/debug/build/cargo-husky-f07c66896bec186c/out
#

set -e
# fmt
echo '+cargo +nightly fmt --all'
cargo +nightly fmt --all

# Enforcing Angular commit style
# I was having trouble gitting the regex to work, so I just commented it out for now
# commit_message=$(git log -1 --pretty=%B)
# if ! echo "$commit_message" | grep -qE '^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\([a-zA-Z0-9_]*\))?: .*'
# then
# echo 'error: invalid commit message format.'
# echo 'Please follow the Angular commit message style.'
# echo 'Format: type(scope?): subject'
# echo 'Example: fix(server): fix login issue'
# exit 1
# else
# echo 'Commit message format is valid.'
# fi

# No commiting to main
if [ "$(git symbolic-ref --short HEAD)" = "main" ]; then
echo 'error: you are trying to commit to main, which is not allowed.'
exit 1
fi
22 changes: 22 additions & 0 deletions .cargo-husky/hooks/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh
#
# This hook was set by cargo-husky v1.5.0: https://github.com/rhysd/cargo-husky#readme
# Generated by script /Users/shufflebottomhogwood/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-husky-1.5.0/build.rs
# Output at /Users/shufflebottomhogwood/Code/excalibur/target/debug/build/cargo-husky-e97043955f0b7beb/out
#

set -e

echo '+cargo build --all'
cargo build --all

protected_branch='main'
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
remote_name=$(git for-each-ref --format='%(upstream:short)' $(git symbolic-ref -q HEAD))
remote_name=${remote_name%/$protected_branch}
remote_name=${remote_name#refs/remotes/}

if [[ $current_branch = $protected_branch && $remote_name = 'origin' ]]; then
echo 'error: you are trying to push to main, which is not allowed.'
exit 1
fi
23 changes: 1 addition & 22 deletions .github/workflows/book.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,4 @@ jobs:
- name: Run tests
run: |
cd journal
mdbook test

lint:
runs-on: ubuntu-latest
name: Lints
needs: install
steps:
- uses: actions/checkout@v3

- name: Install mdbook-linkcheck
run: |
cd journal
mkdir mdbook-linkcheck
curl -sSL -o mdbook-linkcheck.zip https://github.com/Michael-F-Bryan/mdbook-linkcheck/releases/latest/download/mdbook-linkcheck.x86_64-unknown-linux-gnu.zip
unzip mdbook-linkcheck.zip -d ./mdbook-linkcheck
chmod +x `pwd`/mdbook-linkcheck/mdbook-linkcheck
echo `pwd`/mdbook-linkcheck >> $GITHUB_PATH

- name: Run linkcheck
run: |
cd journal
mdbook-linkcheck --standalone
mdbook test
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,17 @@ dotenv.workspace = true
RustQuant.workspace = true
statrs.workspace = true


[dev-dependencies]
# For book
mdbook = "0.4.35"
cargo-make = "0.37.2"
mdbook-katex = "0.5.8"

[dev-dependencies.cargo-husky]
version = "1"
default-features = false
features = ["user-hooks"]

[[bench]]
name = "ui_benchmark"
harness = false
Expand Down
6 changes: 5 additions & 1 deletion book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ trust = false
no-css = false
include-src = false
block-delimiter = { left = "$$", right = "$$" }
inline-delimiter = { left = "$", right = "$" }
inline-delimiter = { left = "$", right = "$" }

[linkcheck]
follow-web-links = false
warning-policy = 'ignore'
2 changes: 1 addition & 1 deletion journal/src/analysis/dollar_cost_averaging.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

To analyze the DCA strategy we should consider the following approach.

1. Define a weight changer agent that changes the weight of the DFMM curve over time as prescribed in [Dollar Cost Averaging](../strategies/dollar_cost_averaging.md).
1. Define a weight changer agent that changes the weight of the DFMM curve over time as prescribed in [Dollar Cost Averaging](dollar_cost_averaging.md).
2. Define a swapper agent to swap between $X$ and $Y$ at prescribed timeframes.

We can compare the values of the portfolio held by an LP into the DCA strategy versus the swapper agent.
Expand Down
17 changes: 9 additions & 8 deletions journal/src/dev_notes/ui/dec-17.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
# tonight

What do I prioritize for tonight?

- [x] Remove cargo nightly features
- [x] Pin dependencies
- [x] Font and asset loading on mac os?
- [x] macos cant right click haha!! fixed with left click
- [ ] Make traces cleaner, and potentially save to file?
- [ ] Get some tests passing
- [ ] Clippy
```ignore
[x] Remove cargo nightly features
[x] Pin dependencies
[x] Font and asset loading on mac os?
[x] macos cant right click haha!! fixed with left click
[ ] Make traces cleaner, and potentially save to file?
[ ] Get some tests passing
[ ] Clippy
```

# tagline

Expand Down
2 changes: 1 addition & 1 deletion journal/src/dev_notes/ui/nov-16.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
## Ethersdb
- Problem: Ethersdb instantiation uses `block_on`. Breaks if within tokio runtime. Tests are inside tokio runtime!
- Solution: Do `EthersDb::<basic>` inside a separate __non-tokio__ thread.
- #[tokio::test(flavor = "multi_thread", worker_threads = 1)] is clutch.
- `#[tokio::test(flavor = "multi_thread", worker_threads = 1)]` is clutch.
2 changes: 1 addition & 1 deletion journal/src/dev_notes/ui/nov-25.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ We start with the base "package" of components that make up every section of the
- update() - A function to mutate the state of the component.


This begins at the root [`iced: :Application`] all the way down to the last child. This happens recursively, so app -> update -> child -> update -> ...nth child.
This begins at the root `iced: :Application` all the way down to the last child. This happens recursively, so app -> update -> child -> update -> ...nth child.

In each child component, a Parent Message is defined for developers to easily understand its relationship in the context of its package. Then, the child's Message can implement `From<ChildMessage> for ParentMessage`. Implementing this allows the parent to "wrap" the message with its own message type, thereby completing the recursion.

Expand Down
2 changes: 1 addition & 1 deletion journal/src/trading_functions/log_normal.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ $$
L \equiv \mathtt{liquidity}
$$
Note that $L$ has units of Token (this is what we want).
Given the domain of $\Phi^{-1}$ we can see that $x\in[0,L]$ and $y\in[0,KL]$.
Given the domain of $\Phi^{-1}$ we can see that $x\in\[0,L\]$ and $y\in\[0,KL\]$.
As the pool's liquidity increases, the maximal amount of each reserve increases and both are scaled by the same factor (this is what we want).

## Useful Notation
Expand Down
Loading