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

cargo generate #75

Merged
merged 26 commits into from
Jun 13, 2024
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
2 changes: 2 additions & 0 deletions .genignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
meta/
build/
File renamed without changes.
File renamed without changes.
48 changes: 48 additions & 0 deletions .github.template/workflows/scheduled.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
permissions:
contents: read
on:
push:
branches: [main]
pull_request:
schedule:
- cron: "7 7 * * *"
name: rolling
jobs:
# https://twitter.com/mycoliza/status/1571295690063753218
nightly:
runs-on: ubuntu-latest
name: ubuntu / nightly
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Install nightly
uses: dtolnay/rust-toolchain@nightly
- name: cargo generate-lockfile
if: hashFiles('Cargo.lock') == ''
run: cargo generate-lockfile
- name: cargo test --locked
run: cargo test --locked --all-features --all-targets
# https://twitter.com/alcuadrado/status/1571291687837732873
update:
runs-on: ubuntu-latest
name: ubuntu / beta / updated
# There's no point running this if no Cargo.lock was checked in in the
# first place, since we'd just redo what happened in the regular test job.
# Unfortunately, hashFiles only works in if on steps, so we reepeat it.
# if: hashFiles('Cargo.lock') != ''
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Install beta
if: hashFiles('Cargo.lock') != ''
uses: dtolnay/rust-toolchain@beta
- name: cargo update
if: hashFiles('Cargo.lock') != ''
run: cargo update
- name: cargo test
if: hashFiles('Cargo.lock') != ''
run: cargo test --locked --all-features --all-targets
env:
RUSTFLAGS: -D deprecated
27 changes: 27 additions & 0 deletions .github.template/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
permissions:
contents: read
on:
push:
branches: [main]
pull_request:
name: test
jobs:
required:
runs-on: ubuntu-latest
name: ubuntu / ${{ matrix.toolchain }}
strategy:
matrix:
toolchain: [stable, beta]
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Install ${{ matrix.toolchain }}
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.toolchain }}
- name: cargo generate-lockfile
if: hashFiles('Cargo.lock') == ''
run: cargo generate-lockfile
- name: cargo test --locked
run: cargo test --locked --all-features --all-targets
25 changes: 25 additions & 0 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
permissions:
contents: read
on:
push:
branches: [main]
pull_request:
name: check
jobs:
clippy:
runs-on: ubuntu-latest
name: stable / clippy
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Install stable
uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- name: install cargo-generate
run: cargo install cargo-generate --locked
- name: cargo clippy
run: |
CARGO_GENERATE_TEST_CMD="cargo clippy --all-features -- -D warnings" \
cargo generate -d include_app=true -d include_adapter=true -d app_name=my_app -d adapter_name=my_adapter --test
32 changes: 5 additions & 27 deletions .github/workflows/scheduled.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,9 @@ jobs:
submodules: true
- name: Install nightly
uses: dtolnay/rust-toolchain@nightly
- name: cargo generate-lockfile
if: hashFiles('Cargo.lock') == ''
run: cargo generate-lockfile
- name: install cargo-generate
run: cargo install cargo-generate --locked
- name: cargo test --locked
run: cargo test --locked --all-features --all-targets
# https://twitter.com/alcuadrado/status/1571291687837732873
update:
runs-on: ubuntu-latest
name: ubuntu / beta / updated
# There's no point running this if no Cargo.lock was checked in in the
# first place, since we'd just redo what happened in the regular test job.
# Unfortunately, hashFiles only works in if on steps, so we reepeat it.
# if: hashFiles('Cargo.lock') != ''
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Install beta
if: hashFiles('Cargo.lock') != ''
uses: dtolnay/rust-toolchain@beta
- name: cargo update
if: hashFiles('Cargo.lock') != ''
run: cargo update
- name: cargo test
if: hashFiles('Cargo.lock') != ''
run: cargo test --locked --all-features --all-targets
env:
RUSTFLAGS: -D deprecated
run: |
CARGO_GENERATE_TEST_CMD="cargo test --all-features --all-targets" \
cargo generate -d include_app=true -d include_adapter=true -d app_name=my_app -d adapter_name=my_adapter --test
11 changes: 6 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ jobs:
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.toolchain }}
- name: cargo generate-lockfile
if: hashFiles('Cargo.lock') == ''
run: cargo generate-lockfile
- name: cargo test --locked
run: cargo test --locked --all-features --all-targets
- name: install cargo-generate
run: cargo install cargo-generate --locked
- name: cargo test
run: |
CARGO_GENERATE_TEST_CMD="cargo test --all-features --all-targets" \
cargo generate -d include_app=true -d include_adapter=true -d app_name=my_app -d adapter_name=my_adapter --test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ state.json
typescript/node_modules

contracts/**/schema
schema/

build/
11 changes: 6 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ panic = 'abort'
incremental = false

[workspace.dependencies]
{% if include_app %}
{{app_name | kebab_case}} = { path = "contracts/{{app_name}}" }
{% endif %}
{% if include_adapter %}
{{adapter_name | kebab_case}} = { path = "contracts/{{adapter_name}}" }
{% endif %}
cosmwasm-std = { version = "1.5.3" }
cosmwasm-schema = { version = "1.5.3" }
cw-controllers = { version = "1.1.2" }
Expand All @@ -26,13 +32,8 @@ abstract-adapter = { version = "0.22.2" }
abstract-interface = { version = "0.22.0" }
abstract-client = { version = "0.22.0" }
lazy_static = "1.4.0"


cw-orch = { version = "0.22.2" }
const_format = "0.2.32"

my-app = { path = "contracts/my-app" }
my-adapter = { path = "contracts/my-adapter" }
speculoos = "0.11.0"
semver = "1.0"
dotenv = "0.15.0"
Expand Down
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@ This template includes examples for both an app and adapter in a workspace.

### Requirements

[cargo-generate](https://github.com/cargo-generate/cargo-generate)

Learn more about the requirements for developing Abstract apps in the [getting started documentation](https://docs.abstract.money/4_get_started/1_index.html).

### Setup

To get started, clone this repository and run the following command:
To get started, the following commands:

```shell
chmod +x ./template-setup.sh
./template-setup.sh
cargo generate --git https://github.com/AbstractSDK/app-template.git
```

The setup will suggest you to install a few tools that are used in the template. You can skip this step if you already have them installed or if you're not planning on using them.
It will prompt Project Name(will be used for namespace), App Name and Adapter Name.

### Updating Names
```shell
cd {{project-name}}
```

We recommend updating the names of the packages and variables to be custom to your application. You should be able to do this easily with a global replace.
to go to your newly created project and finish setup by running the following command:

For example:
```shell
./template-setup.sh
```

- ~~my-app~~ -> ibcmail-client
- ~~my_app~~ -> ibcmail_client
- ~~MyApp~~ -> IbcMailClient
- ~~my-adapter~~ -> ibcmail-server
- ~~my_adapter~~ -> ibcmail_server
- ~~MyAdapter~~ -> IbcMailServer
The setup will suggest you to install a few tools that are used in the template. You can skip this step if you already have them installed or if you're not planning on using them.

## Using the Justfile

Expand All @@ -54,7 +54,7 @@ Here are some of the tasks available in the `justfile`:
- `lintfix`: Fix linting errors automatically.
- `watch`: Watch the codebase and run `cargo check` on changes.
- `watch-test`: Watch the codebase and run tests on changes.
- `publish {{chain-id}}`: Publish the App to a network.
- `publish CHAIN_ID`: Publish the App to a network.
- `schema`: Generate the json schemas for the contract
<!-- - `ts-codegen`: Generate the typescript app code for the contract -->
<!-- - `ts-publish`: Publish the typescript app code to npm -->
Expand Down Expand Up @@ -88,7 +88,7 @@ Before attempting to publish your app you need to add your mnemonic to the `.env
<!-- It's also assumed that you have an account and module namespace claimed with this account before publishing. You can read how to do that [here](https://docs.abstract.money/4_get_started/5_abstract_client.html). -->
Select from a wide range of [supported chains](https://orchestrator.abstract.money/chains/index.html) before proceeding. Make sure you've some balance enough to pay gas for the transaction.

You can now use `just publish {{chain-id}}` to run the [`examples/publish.rs`](./examples/publish.rs) script. The script will publish the app to the networks that you provided. Make sure you have enough funds in your wallet on the different networks you aim to publish on.
You can now use `just publish CHAIN_ID` to run the [`examples/publish.rs`](./examples/publish.rs) script. The script will publish the app to the networks that you provided. Make sure you have enough funds in your wallet on the different networks you aim to publish on.

### Publishing Module Schemas

Expand All @@ -100,7 +100,7 @@ Please install [github cli](https://cli.github.com/) before proceeding. Also log
just publish-schemas <namespace> <name> <version>
```

- `namespace`: Your module's namespace
- `namespace`: Your module's namespace({{project-name}})
- `name`: Your module's name
- `version`: Your module's version. Note that if you only include the minor version (e.g., `0.1`), you don't have to reupload the schemas for every patch version.

Expand Down
21 changes: 21 additions & 0 deletions cargo-generate.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[template]
ignore = [".github", "artifacts", "target"]

[hooks]
post = ["post-script.rhai"]

[placeholders]
include_app = { prompt = "Include App Module", default = true, type = "bool" }
include_adapter = { prompt = "Include Adapter Module", default = true, type = "bool" }

[conditional.'include_app'.placeholders]
app_name = { prompt = "Enter App Name", default = "my_app", type = "string" }

[conditional.'include_adapter'.placeholders]
adapter_name = { prompt = "Enter Adapter Name", default = "my_adapter", type = "string" }

# Ignore files if not included
[conditional.'!include_app']
ignore = ["contracts/{{app_name}}"]
[conditional.'!include_adapter']
ignore = ["contracts/{{adapter_name}}"]
35 changes: 0 additions & 35 deletions contracts/my-adapter/src/contract.rs

This file was deleted.

17 changes: 0 additions & 17 deletions contracts/my-adapter/src/lib.rs

This file was deleted.

40 changes: 0 additions & 40 deletions contracts/my-app/src/contract.rs

This file was deleted.

Loading