Skip to content

Commit

Permalink
Merge pull request #1037 from rainlanguage/2024-12-02-prep-script
Browse files Browse the repository at this point in the history
new prep script and readme
  • Loading branch information
thedavidmeister authored Dec 3, 2024
2 parents 556b016 + ad6a4fa commit 25d28a6
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 158 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
COMMIT_SHA=test
21 changes: 1 addition & 20 deletions .github/workflows/tauri-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,26 +65,7 @@ jobs:
uses: DeterminateSystems/nix-installer-action@v4
- uses: DeterminateSystems/magic-nix-cache-action@v2

- run: nix develop -c rainix-sol-prelude
working-directory: lib/rain.interpreter
- run: nix develop -c rainix-rs-prelude
working-directory: lib/rain.interpreter
- run: nix develop -c rainix-sol-prelude
working-directory: lib/rain.interpreter/lib/rain.metadata
- run: nix develop -c rainix-rs-prelude
working-directory: lib/rain.interpreter/lib/rain.metadata
- run: nix develop -c rainix-sol-prelude
- run: nix develop -c rainix-rs-prelude
- run: nix develop -c raindex-prelude
- run: nix develop -c ob-ui-components-prelude


- run: nix develop .#tauri-shell -c ob-tauri-prelude

- run: nix develop -c npm run build
working-directory: packages/orderbook
- run: nix develop -c npm run build
working-directory: packages/ui-components
- run: ./prep-all.sh

- run: nix develop .#tauri-shell -c ob-tauri-unit-test

Expand Down
20 changes: 1 addition & 19 deletions .github/workflows/tauri.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,7 @@ jobs:
uses: DeterminateSystems/nix-installer-action@v4
- uses: DeterminateSystems/magic-nix-cache-action@v2

- run: nix develop -c rainix-sol-prelude
working-directory: lib/rain.interpreter
- run: nix develop -c rainix-rs-prelude
working-directory: lib/rain.interpreter
- run: nix develop -c rainix-sol-prelude
working-directory: lib/rain.interpreter/lib/rain.metadata
- run: nix develop -c rainix-rs-prelude
working-directory: lib/rain.interpreter/lib/rain.metadata
- run: nix develop -c rainix-sol-prelude
- run: nix develop -c rainix-rs-prelude
- run: nix develop -c raindex-prelude
- run: nix develop -c ob-ui-components-prelude

- run: nix develop .#tauri-shell -c ob-tauri-prelude

- run: nix develop -c npm run build
working-directory: packages/orderbook
- run: nix develop -c npm run build
working-directory: packages/ui-components
- run: ./prep-all.sh

- run: nix develop .#tauri-shell -c ob-tauri-unit-test

Expand Down
16 changes: 2 additions & 14 deletions .github/workflows/test-ui-components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,8 @@ jobs:
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main

- run: nix develop -c rainix-sol-prelude
working-directory: lib/rain.interpreter
- run: nix develop -c rainix-rs-prelude
working-directory: lib/rain.interpreter
- run: nix develop -c rainix-sol-prelude
working-directory: lib/rain.interpreter/lib/rain.metadata
- run: nix develop -c rainix-rs-prelude
working-directory: lib/rain.interpreter/lib/rain.metadata
- run: nix develop -c rainix-sol-prelude
- run: nix develop -c rainix-rs-prelude
- run: nix develop -c raindex-prelude
- run: nix develop -c ob-ui-components-prelude
- run: nix develop -c npm run build
working-directory: packages/orderbook
- run: ./prep-all.sh

- run: nix develop -c npm run svelte-lint-format-check
working-directory: packages/ui-components
- run: nix develop -c npm run test
Expand Down
17 changes: 1 addition & 16 deletions .github/workflows/test-webapp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,8 @@ jobs:
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main

- run: nix develop -c rainix-sol-prelude
working-directory: lib/rain.interpreter
- run: nix develop -c rainix-rs-prelude
working-directory: lib/rain.interpreter
- run: nix develop -c rainix-sol-prelude
working-directory: lib/rain.interpreter/lib/rain.metadata
- run: nix develop -c rainix-rs-prelude
working-directory: lib/rain.interpreter/lib/rain.metadata
- run: nix develop -c rainix-sol-prelude
- run: nix develop -c rainix-rs-prelude
- run: nix develop -c raindex-prelude
- run: nix develop -c ob-ui-components-prelude
- run: ./prep-all.sh

- run: nix develop -c npm run build
working-directory: packages/ui-components
- run: nix develop -c npm run build
working-directory: packages/orderbook
- run: nix develop -c npm run svelte-lint-format-check
working-directory: packages/webapp
- run: nix develop -c npm run test
Expand Down
19 changes: 1 addition & 18 deletions .github/workflows/vercel-preview.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,8 @@ jobs:
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main

- run: nix develop -c rainix-sol-prelude
working-directory: lib/rain.interpreter
- run: nix develop -c rainix-rs-prelude
working-directory: lib/rain.interpreter
- run: nix develop -c rainix-sol-prelude
working-directory: lib/rain.interpreter/lib/rain.metadata
- run: nix develop -c rainix-rs-prelude
working-directory: lib/rain.interpreter/lib/rain.metadata
- run: nix develop -c rainix-sol-prelude
- run: nix develop -c rainix-rs-prelude
- run: nix develop -c raindex-prelude
- run: nix develop -c ob-ui-components-prelude
- run: ./prep-all.sh

- run: nix develop -c npm run build
working-directory: packages/orderbook
- run: nix develop -c npm run build
working-directory: packages/ui-components
- run: nix develop -c npm run build
working-directory: packages/orderbook
- run: nix develop .#webapp-shell -c npm run build
working-directory: packages/webapp

Expand Down
19 changes: 1 addition & 18 deletions .github/workflows/vercel-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,8 @@ jobs:
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main

- run: nix develop -c rainix-sol-prelude
working-directory: lib/rain.interpreter
- run: nix develop -c rainix-rs-prelude
working-directory: lib/rain.interpreter
- run: nix develop -c rainix-sol-prelude
working-directory: lib/rain.interpreter/lib/rain.metadata
- run: nix develop -c rainix-rs-prelude
working-directory: lib/rain.interpreter/lib/rain.metadata
- run: nix develop -c rainix-sol-prelude
- run: nix develop -c rainix-rs-prelude
- run: nix develop -c raindex-prelude
- run: nix develop -c ob-ui-components-prelude
- run: ./prep-all.sh

- run: nix develop -c npm run build
working-directory: packages/orderbook
- run: nix develop -c npm run build
working-directory: packages/ui-components
- run: nix develop -c npm run build
working-directory: packages/orderbook
- run: nix develop .#webapp-shell -c npm run build
working-directory: packages/webapp

Expand Down
65 changes: 13 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,67 +1,28 @@
# rain.orderbook

Docs at https://rainprotocol.github.io/foundry.template
## Setup for local development

## Run Tauri App for local development
- Prepare the tauri build: `./prep-tauri.sh`
- Copy `tauri-app/.env.example` to `tauri-ap/.env` and fill in values
- Run tauri for develoment: `nix develop .#tauri-shell --command cargo tauri dev`
### Environment Setup

## Use as template
1. Copy `.env.example` to `.env`
2. Copy `tauri-app/.env.example` to `tauri-app/.env` and fill out `VITE_WALLETCONNECT_PROJECT_ID` with a test project ID from [Reown (FKA WalletConnect)](https://cloud.reown.com/sign-in)

```
forge init -t rainprotocol/foundry.template <projectname>
cd <projectname>
forge install foundry-rs/forge-std
```

Then update the readme, set the docs url and configure github pages on github repo settings.

For CI deployments, setup all the environment variables and define contracts to
deploy in the matrix.

## Generating Rust Types from Graphql

**NOTICE** The crates and tauri app are currently expecting a subgraph compatible with the schema in `crates/subgraph/schema/orderbook.graphql`.
When this project is migrated to use the subgraph schema defined in `subgraph/schema/graphql`, the command below will change.

1. Run the following commands to generate Rust types from GraphQL Queries
Then run the following to install dependencies and build the project:
```bash
cynic querygen --schema crates/subgraph/schema/orderbook.graphql --query crates/subgraph/queries/vaultDetail.graphql > crates/subgraph/src/types/vault_detail.rs
cynic querygen --schema crates/subgraph/schema/orderbook.graphql --query crates/subgraph/queries/vaultsList.graphql > crates/subgraph/src/types/vaults_list.rs
cynic querygen --schema crates/subgraph/schema/orderbook.graphql --query crates/subgraph/queries/orderDetail.graphql > crates/subgraph/src/types/order_detail.rs
cynic querygen --schema crates/subgraph/schema/orderbook.graphql --query crates/subgraph/queries/ordersList.graphql > crates/subgraph/src/types/orders_list.rs
cynic querygen --schema crates/subgraph/schema/orderbook.graphql --query crates/subgraph/queries/vaultBalanceChangesList.graphql > crates/subgraph/src/types/vault_balance_changes_list.rs
cynic querygen --schema crates/subgraph/schema/orderbook.graphql --query crates/subgraph/queries/orderTakesList.graphql > crates/subgraph/src/types/order_takes_list.rs
cynic querygen --schema crates/subgraph/schema/orderbook.graphql --query crates/subgraph/queries/orderTakeDetail.graphql > crates/subgraph/src/types/order_take_detail.rs
./prep-all.sh
```

2. Prepend each generated types file with the following:
```rust
use crate::schema;
use typeshare::typeshare;
You may need to make the shell script executable:
```bash
chmod +x prep-all.sh
```

3. Add the following derives for all generated Rust types:
```rust
#[derive(Clone)]
### Run Webapp for local development
```

4. Add the following derives for all generated Rust types that also derive `cynic::QueryFragment`:
```rust
#[derive(Serialize)]
cd packages/webapp && nix develop -c npm run dev
```

5. Add the following macros to all generated Rust types
```rust
#[typeshare]
### Run Tauri App for local development
```

6. Rename the conflicting enum `TokenVaultOrderBy::VaultId` to `TokenVaultOrderBy::VaultId2` in `crates/subgraphs/src/types/vaults.rs`

## Generating Typescript Types from Rust Types

Run the following from the repo root, outside the nix shell, to generate Typescript types from Rust types in `crates/subgraph/src/types`.
```bash
nix run .#ob-tauri-prelude
nix develop .#tauri-shell --command cargo tauri dev
```
3 changes: 3 additions & 0 deletions REUSE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ path = [
"package-lock.json",
"Cargo.lock",
"Cargo.toml",
".env.example",
"tauri-app/.env.example",
"prep-all.sh",
]
SPDX-FileCopyrightText = "Copyright (c) 2020 thedavidmeister"
SPDX-License-Identifier = "LicenseRef-DCL-1.0"
Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
# Create env file with working defaults
ENV_FILE=".env"
ENV_EXAMPLE_FILE=".env.example"
cp $ENV_EXAMPLE_FILE $ENV_FILE
cp $ENV_EXAMPLE_FILE $ENV_FILE
# Add walletconnect project id from github action env to .env file
echo VITE_WALLETCONNECT_PROJECT_ID=''${WALLETCONNECT_PROJECT_ID} >> $ENV_FILE
Expand Down
75 changes: 75 additions & 0 deletions prep-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash

# Set strict error handling
set -euxo pipefail

echo "Starting project setup..."

# Environment variables that need to be set (commented out as reference)
# export CI_DEPLOY_SEPOLIA_RPC_URL=""
# export CI_FORK_SEPOLIA_DEPLOYER_ADDRESS=""
# export CI_FORK_SEPOLIA_BLOCK_NUMBER=""
# export CI_DEPLOY_POLYGON_RPC_URL=""
# export CI_SEPOLIA_METABOARD_URL=""
# export RPC_URL_ETHEREUM_FORK=""
# export COMMIT_SHA=""

# Keep environment variables when using nix-develop
keep=(
-k CI_DEPLOY_SEPOLIA_RPC_URL
-k CI_FORK_SEPOLIA_DEPLOYER_ADDRESS
-k CI_FORK_SEPOLIA_BLOCK_NUMBER
-k CI_DEPLOY_POLYGON_RPC_URL
-k CI_SEPOLIA_METABOARD_URL
-k RPC_URL_ETHEREUM_FORK
-k COMMIT_SHA
)

echo "Installing Forge dependencies..."
nix develop -c forge install

echo "Setting up rain.interpreter..."
nix develop -i ${keep[@]} -c bash -c '(cd lib/rain.interpreter && rainix-sol-prelude)'
nix develop -i ${keep[@]} -c bash -c '(cd lib/rain.interpreter && rainix-rs-prelude)'
(cd lib/rain.interpreter && nix develop -i ${keep[@]} -c bash -c i9r-prelude)

echo "Setting up rain.metadata..."
nix develop -i ${keep[@]} -c bash -c '(cd lib/rain.interpreter/lib/rain.metadata && rainix-sol-prelude)'
nix develop -i ${keep[@]} -c bash -c '(cd lib/rain.interpreter/lib/rain.metadata && rainix-rs-prelude)'

echo "Setting up main project dependencies..."
nix develop -i ${keep[@]} -c rainix-sol-prelude
nix develop -i ${keep[@]} -c rainix-rs-prelude
nix develop -i ${keep[@]} -c raindex-prelude

echo "Setting up UI components..."
nix develop -i ${keep[@]} .#tauri-shell -c ob-tauri-prelude
nix develop -i ${keep[@]} .#tauri-shell -c ob-ui-components-prelude

echo "Building packages..."
nix develop -i ${keep[@]} -c bash -c '(npm run build -w @rainlanguage/orderbook)'
nix develop -i ${keep[@]} -c bash -c '(npm run build -w @rainlanguage/ui-components && npm run build -w @rainlanguage/webapp)'

# Temporarily disable command echoing
set +x

export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8

GREEN='\033[0;32m'
NC='\033[0m' # No Color

# Print the completion message
printf "\033[0;32m" # Set text to green
printf "╔════════════════════════════════════════════════════════════════════════╗\n"
printf "║ Setup Complete! ║\n"
printf "╠════════════════════════════════════════════════════════════════════════╣\n"
printf "║ How to run the apps: ║\n"
printf "║ ║\n"
printf "║ To run webapp: cd packages/webapp && nix develop -c npm run dev ║\n"
printf "║ To run tauri app: nix develop .#tauri-shell -c cargo tauri dev ║\n"
printf "╚════════════════════════════════════════════════════════════════════════╝\n"
printf "\033[0m" # Reset text color

# Re-enable command echoing
set -x
2 changes: 2 additions & 0 deletions tauri-app/.env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
COMMIT_SHA=

VITE_WALLETCONNECT_PROJECT_ID=

# The long url provided by sentry for your project configuration
Expand Down

0 comments on commit 25d28a6

Please sign in to comment.