Skip to content

Commit 30ba970

Browse files
authored
feat: add rust project boilerplate (balancednetwork#5)
* feat: add rust project boilerplate fix: rust workflows fix: specify working directory in jobs chore: run workflows in root of project chore: move .cargo folder to root fix: comment out error part fix: run cargo fmt test: directly run commands fix: github workflows feat: update optimizer script feat: install wasm32 feat: cache dependencies on workflow * feat: upload codecov * feat: fix running cargo schema command in sub projects
1 parent 4db8ed1 commit 30ba970

24 files changed

+1551
-0
lines changed

.cargo/config

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[alias]
2+
wasm = "build --release --lib --target wasm32-unknown-unknown"
3+
unit-test = "test --lib"
4+
schema = "run --bin schema"

.editorconfig

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_style = space
7+
indent_size = 2
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
max_line_length = 120
11+
12+
[*.rs]
13+
indent_size = 4
14+
max_line_length = 100

.github/workflows/Basic.yml

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Based on https://github.com/actions-rs/example/blob/master/.github/workflows/quickstart.yml
2+
name: Test and Lint CW contracts
3+
4+
on:
5+
pull_request:
6+
branches:
7+
- "**"
8+
paths:
9+
- "contracts/**"
10+
- ".github/workflows/Basic.yml"
11+
push:
12+
branches:
13+
- main
14+
15+
jobs:
16+
17+
test:
18+
name: Test Suite
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Checkout sources
23+
uses: actions/checkout@v3
24+
25+
- name: Install Rust
26+
run: rustup update stable
27+
28+
- name: Cache Rust dependencies
29+
uses: Swatinem/rust-cache@v2
30+
31+
- name: Run unit tests
32+
run: |
33+
RUST_BACKTRACE=1 cargo unit-test --locked
34+
35+
- name: Install wasm32
36+
run: |
37+
rustup target add wasm32-unknown-unknown
38+
39+
- name: Compile WASM contract
40+
run: |
41+
RUSTFLAGS='-C link-arg=-s' cargo wasm --locked
42+
43+
lints:
44+
name: Lints
45+
runs-on: ubuntu-latest
46+
steps:
47+
- name: Checkout sources
48+
uses: actions/checkout@v3
49+
50+
- name: Install Rust
51+
run: rustup update stable
52+
53+
- name: Cache Rust dependencies
54+
uses: Swatinem/rust-cache@v2
55+
56+
- name: Run cargo fmt
57+
run: |
58+
cargo fmt --all -- --check
59+
60+
- name: Run cargo clippy
61+
run: |
62+
cargo clippy -- -D warnings
63+
64+
- name: Generate schema
65+
run: |
66+
cd contracts
67+
../scripts/run_in_subprojects.sh token-contracts/cw-hub-bnusd
68+
69+
- name: Verify schema
70+
uses: tj-actions/verify-changed-files@v14
71+
id: verify-schema
72+
with:
73+
files: |
74+
contracts/*/*/schema/**
75+
76+
- name: Display changed schemas
77+
if: steps.verify-schema.outputs.files_changed == 'true'
78+
run: |
79+
echo "Changed files: ${{ steps.verify-schema.outputs.changed_files }}"

.github/workflows/cw-codecov.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: CosmWasm contracts Codecov
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- "**"
7+
paths:
8+
- "contracts/**"
9+
- ".github/workflows/cw-codecov.yml"
10+
push:
11+
branches:
12+
- main
13+
14+
jobs:
15+
code-coverage:
16+
runs-on: ubuntu-latest
17+
env:
18+
CARGO_TERM_COLOR: always
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v3
22+
with:
23+
submodules: true
24+
25+
- name: Install Rust
26+
run: rustup update stable
27+
28+
- name: Cache Rust dependencies
29+
uses: Swatinem/rust-cache@v2
30+
31+
- name: Install cargo-llvm-cov
32+
uses: taiki-e/install-action@cargo-llvm-cov
33+
34+
- name: Generate code coverage
35+
run: cargo llvm-cov --lcov --output-path lcov.info
36+
- name: Upload coverage to Codecov
37+
uses: codecov/codecov-action@v3
38+
with:
39+
token: ${{ secrets.CODECOV_TOKEN }}
40+
files: lcov.info
41+
flags: rust
42+
fail_ci_if_error: true

.github/workflows/lint-pr.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Lint PR
2+
on:
3+
pull_request_target:
4+
types:
5+
- opened
6+
- edited
7+
- synchronize
8+
jobs:
9+
main:
10+
name: Validate PR title
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: amannn/action-semantic-pull-request@v5.1.0
14+
env:
15+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16+
with:
17+
validateSingleCommit: true
18+
validateSingleCommitMatchesPrTitle: true

.gitignore

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Build results
2+
/target
3+
/schema
4+
5+
# Cargo+Git helper file (https://github.com/rust-lang/cargo/blob/0.44.1/src/cargo/sources/git/utils.rs#L320-L327)
6+
.cargo-ok
7+
8+
# Text file backups
9+
**/*.rs.bk
10+
11+
# macOS
12+
.DS_Store
13+
14+
# IDEs
15+
.vscode/
16+
*.iml
17+
.idea
18+
19+
# Build results
20+
target/
21+
22+
# Build artifacts
23+
*.wasm
24+
hash.txt
25+
contracts.txt
26+
artifacts/
27+
28+
# code coverage
29+
tarpaulin-report.*
30+
31+
contracts/**/**/schema

.prettierrc.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"overrides": [
3+
{
4+
"files": "*.md",
5+
"options": {
6+
"proseWrap": "always"
7+
}
8+
}
9+
]
10+
}

CONTRACTS.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Contracts
2+
3+
4+
5+
## Creating a new contract
6+
7+
Use [`cosmwasm-template`](https://github.com/CosmWasm/cw-template) as a basis.
8+
9+
```bash
10+
cd contracts/core-contracts #cd contracts/token-contracts
11+
cargo generate --git https://github.com/CosmWasm/cw-template.git --name PROJECT_NAME
12+
cd PROJECT_NAME
13+
rm -rf .git
14+
rm -rf .circleci
15+
rm .gitignore
16+
rm -rf .github
17+
rm .editorconfig
18+
rm .cargo-ok
19+
rm LICENSE
20+
rm NOTICE
21+
```

0 commit comments

Comments
 (0)