Skip to content

Commit

Permalink
ci: Update worflows, makefile, add test artifactsw
Browse files Browse the repository at this point in the history
  • Loading branch information
apollo-sturdy committed Sep 16, 2023
1 parent 317ae27 commit 399e5d3
Show file tree
Hide file tree
Showing 43 changed files with 350 additions and 174 deletions.
11 changes: 0 additions & 11 deletions .editorconfig

This file was deleted.

35 changes: 35 additions & 0 deletions .github/workflows/artifacts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Artifacts

on:
push:
branches:
- master
- main
pull_request:
branches:
- master
- main
workflow_dispatch:

env:
RUST_BACKTRACE: 1
CARGO_TERM_COLOR: always

jobs:
artifacts:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Install cargo make
uses: davidB/rust-cargo-make@v1

- name: Compile contracts to wasm
run: cargo make rust-optimizer

- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: artifacts
path: artifacts/
13 changes: 8 additions & 5 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v3

- name: Run cargo check
uses: actions-rs/cargo@v1
with:
command: check
args: --all-features
- name: Install cargo make
uses: davidB/rust-cargo-make@v1

- name: Install stable Rust
run: cargo make install-stable

- name: Check
run: cargo make check
33 changes: 33 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Coverage

on:
push:
branches:
- master
pull_request:

env:
RUST_BACKTRACE: 1
CARGO_TERM_COLOR: always

jobs:
coverage:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Install cargo make
uses: davidB/rust-cargo-make@v1

- name: Install stable Rust
run: cargo make install-stable

- name: Run test coverage
run: cargo make coverage-lcov

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: target/coverage/lcov.info
10 changes: 4 additions & 6 deletions .github/workflows/licenses.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v3

- name: Install cargo make
uses: davidB/rust-cargo-make@v1

- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.59.0
target: wasm32-unknown-unknown
override: true
run: cargo make install-stable

- name: run cargo deny
uses: EmbarkStudios/cargo-deny-action@v1
Expand Down
33 changes: 8 additions & 25 deletions .github/workflows/lint-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,20 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v3

- name: Install cargo make
uses: davidB/rust-cargo-make@v1

- name: Install nightly toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
components: rustfmt, clippy

- name: Install cargo-machete
uses: actions-rs/cargo@v1
with:
command: install
args: cargo-machete
run: cargo make install-nightly

- name: Run cargo clippy
uses: actions-rs/cargo@v1
with:
toolchain: nightly
command: clippy
args: --all-features -- -D warnings
run: cargo make clippy-check

- name: Run cargo fmt
uses: actions-rs/cargo@v1
with:
toolchain: nightly
command: fmt
args: --all -- --check --verbose
run: cargo make format-check

- name: Run cargo machete
uses: actions-rs/cargo@v1
with:
command: machete
run: cargo make machete-check

- name: Lint todo comments
run: ./scripts/todo-lint.sh
run: cargo make todo-check
22 changes: 11 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v3

- name: Install cargo make
uses: davidB/rust-cargo-make@v1

- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.65.0
target: wasm32-unknown-unknown
override: true
run: cargo make install-stable

- name: Run unit tests
run: cargo make unit-test
env:
RUST_BACKTRACE: 1

- name: Run tests
uses: actions-rs/cargo@v1
with:
command: test
args: --locked --lib
- name: Run integration tests
run: cargo make integration-test
env:
RUST_BACKTRACE: 1
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ default = ["osmosis", "astroport"]
library = []
osmosis = ["cw-dex/osmosis"]
astroport = ["cw-dex/astroport"]
osmosis-test-tube = ["cw-it/osmosis-test-tube"]
osmosis-test-tube = ["cw-it/osmosis-test-tube", "locked-astroport-vault-test-helpers/osmosis-test-tube"]

[package.metadata.scripts]
optimize = """docker run --rm -v "$(pwd)":/code \
Expand Down
127 changes: 103 additions & 24 deletions Makefile.toml
Original file line number Diff line number Diff line change
@@ -1,45 +1,83 @@
extend = [{ path = "coverage_grcov.Makefile.toml" }]

[config]
default_to_workspace = false
skip_core_tasks = true

[env]
CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true
# If you bump this version, verify RUST_VERSION correctness
RUST_OPTIMIZER_VERSION = "0.13.0"
# Use rust version from rust-optimizer Dockerfile (see https://github.com/CosmWasm/rust-optimizer/blob/main/Dockerfile#L1)
# to be sure that we compile / test against the same version
RUST_VERSION = "1.69.0"
NIGHTLY_VERSION = "nightly-2023-08-29"

[tasks.install-stable]
script = '''
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain ${RUST_VERSION}
rustup target add wasm32-unknown-unknown --toolchain ${RUST_VERSION}
rustup component add rustfmt --toolchain ${RUST_VERSION}
rustup component add clippy --toolchain ${RUST_VERSION}
rustup component add llvm-tools-preview --toolchain ${RUST_VERSION}
'''

[tasks.install-nightly]
script = '''
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain ${NIGHTLY_VERSION}
rustup target add wasm32-unknown-unknown --toolchain ${NIGHTLY_VERSION}
rustup component add rustfmt --toolchain ${NIGHTLY_VERSION}
rustup component add clippy --toolchain ${NIGHTLY_VERSION}
'''

[tasks.rust-optimizer]
cwd = "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}"
script = """
if [[ $(arch) == "arm64" ]]; then
image="cosmwasm/workspace-optimizer-arm64:${RUST_OPTIMIZER_VERSION}"
else
image="cosmwasm/workspace-optimizer:${RUST_OPTIMIZER_VERSION}"
fi
docker run --rm -v "$(pwd)":/code \
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
${image}
"""

[tasks.format]
toolchain = "nightly"
toolchain = "${NIGHTLY_VERSION}"
install_crate = { crate_name = "rustfmt-nightly", rustup_component_name = "rustfmt-preview", binary = "rustfmt", test_arg = "--help" }
command = "cargo"
args = ["fmt", "--all", "--", "--emit=files","--verbose"]
[tasks.format-check]
toolchain = "nightly"
toolchain = "${NIGHTLY_VERSION}"
install_crate = { crate_name = "rustfmt-nightly", rustup_component_name = "rustfmt-preview", binary = "rustfmt", test_arg = "--help" }
command = "cargo"
args = ["fmt", "--all", "--","--verbose", "--check"]

# This task requires the `cargo-udeps` package: https://crates.io/crates/cargo-udeps
[tasks.udeps]
toolchain = "nightly"
command = "cargo"
args = ["udeps"]

[tasks.deny]
command = "cargo"
args = ["deny", "check"]

[tasks.check]
toolchain = "${RUST_VERSION}"
command = "cargo"
args = ["check"]

[tasks.clippy-check]
toolchain = "nightly"
toolchain = "${NIGHTLY_VERSION}"
command = "cargo"
args = ["clippy","--all-features","--","-D","warnings"]
[tasks.clippy-fix]
toolchain = "nightly"
toolchain = "${NIGHTLY_VERSION}"
command = "cargo"
args = ["clippy","--fix","--allow-staged","--","-D","warnings"]
args = ["clippy","--all-features", "--fix","--allow-staged", "--allow-dirty", "--","-D","warnings"]

[tasks.todo-check]
script = { file = "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/scripts/todo-lint.sh", absolute_path = true }

# This task requires the `cargo-tarpaulin` package: https://crates.io/crates/cargo-tarpaulin
[tasks.cov]
toolchain = "${RUST_VERSION}"
command = "cargo"
args = [
"tarpaulin",
Expand All @@ -51,6 +89,7 @@ args = [
]

[tasks.docs]
toolchain = "${RUST_VERSION}"
command = "cargo"
args = [
"doc",
Expand All @@ -69,34 +108,74 @@ args = [

# This task requires the `cargo-machete` package: https://crates.io/crates/cargo-machete
[tasks.machete-check]
toolchain = "${NIGHTLY_VERSION}"
command = "cargo"
args = ["machete"]
[tasks.machete-fix]
command = "cargo"
args = ["machete", "--fix"]

# Run automatically on "cargo make". This is the default task. We keep all the
# default tasks and add our own "custom" task.
[tasks.dev-test-flow]
run_task = "custom-default"

# Custom tasks to run on "cargo make"
[tasks.custom-default]
dependencies = ["deny", "clippy-fix", "docs", "machete-fix"]

# Wasm build of test contract
# Unoptimized Wasm build of contract for testing
[tasks.wasm]
toolchain = "${RUST_VERSION}"
command = "cargo"
args = [
"build",
"-p",
"vault-zapper",
"--target",
"wasm32-unknown-unknown",
"--lib",
"--release",
"--package",
"osmosis-test-contract"
]

# Run all tests
[tasks.test]
toolchain = "${RUST_VERSION}"
command = "cargo"
args = ["test", "--locked"]

# Run unit tests
[tasks.unit-test]
toolchain = "${RUST_VERSION}"
command = "cargo"
args = [
"test",
"--lib"
]

# Run integration tests
[tasks.integration-test]
env = { TEST_RUNNER = "osmosis-test-app" }
cwd = "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}"
dependencies = ["wasm"]
toolchain = "${RUST_VERSION}"
command = "cargo"
args = [
"test",
"--features",
"osmosis-test-tube,osmosis,astroport",
"--test",
"*",
]

# Create HTML coverage report
[tasks.coverage-html]
alias = "coverage-grcov-html"

# Create LCOV coverage report
[tasks.coverage-lcov]
alias = "coverage-grcov-lcov"

# Run automatically on "cargo make". This is the default task.
[tasks.default]
alias = "custom-default"

# Custom tasks to run on "cargo make"
[tasks.custom-default]
dependencies = ["format", "clippy-fix", "deny", "machete-fix", "unit-test", "integration-test"]

# Docs and Test coverage are not run by default. Can run all with "cargo make all".
[tasks.all]
dependencies = ["dev-test-flow", "custom-default", "cov"]
dependencies = ["custom-default", "coverage-html"]
2 changes: 1 addition & 1 deletion NOTICE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2022 Sturdy <sturdy@apollo.farm>
Copyright 2022 Apollo Digital Holdings <shared@apollo.farm>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Loading

0 comments on commit 399e5d3

Please sign in to comment.