Skip to content

Commit

Permalink
Add tests to ci
Browse files Browse the repository at this point in the history
  • Loading branch information
aon committed Sep 20, 2023
1 parent 759969c commit 8217be9
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 8 deletions.
59 changes: 51 additions & 8 deletions .github/workflows/general-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,57 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Update Rust
run: rustup update
- name: Run cargo fmt
run: make fmt-rust-check

- name: Install Rust
run: rustup install 1.69 --profile minimal
test-prepare:
name: Prepare tests
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.create-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v3

- name: Install Rustfmt
run: rustup component add rustfmt --toolchain 1.69-x86_64-unknown-linux-gnu
- name: Cache
uses: actions/cache@v3
with:
path: |
~/substrate-contracts-node
key: ${{ runner.os }}-test-prepare-${{ github.run_id }}

- name: Run cargo fmt
run: make fmt-rust-check
- name: Create test matrix
id: create-matrix
run: |
echo "matrix=$(python3 scripts/create-test-matrix.py)" >> $GITHUB_OUTPUT
- name: Download substrate-contracts-node
run: |
wget https://github.com/paritytech/substrate-contracts-node/releases/latest/download/substrate-contracts-node-linux.tar.gz -P ~/substrate-contracts-node
cd ~/substrate-contracts-node
tar -xvf substrate-contracts-node-linux.tar.gz
mv artifacts/substrate-contracts-node-linux/substrate-contracts-node .
rm -rf artifacts substrate-contracts-node-linux.tar.gz
test:
name: Test
runs-on: ubuntu-latest
needs: test-prepare
strategy:
matrix:
test: ${{ fromJson(needs.test-prepare.outputs.matrix) }}
steps:
- uses: actions/checkout@v3

- name: Cache
uses: actions/cache@v3
with:
path: |
~/substrate-contracts-node
key: ${{ runner.os }}-test-prepare-${{ github.run_id }}

- name: Run test
env:
CONTRACTS_NODE: ~/substrate-contracts-node/substrate-contracts-node
run: |
cd test-cases/${{ matrix.test }}
cargo test --all --all-features
25 changes: 25 additions & 0 deletions scripts/create-test-matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import json
import os
from pathlib import Path


def is_special_directory(path):
return path.name.startswith(".") or path.name in ["template", "target"]


if __name__ == "__main__":
ROOT_PATH = Path(__file__).parent.parent
TEST_CASES_PATH = ROOT_PATH / "test-cases"

# Get list of all directories
subfolders = [f for f in os.scandir(TEST_CASES_PATH) if f.is_dir()]

# Filter out special directories
subfolders = [f for f in subfolders if not is_special_directory(f)]

# Get list of all test cases
testcases = [f.name for f in subfolders]
testcases.sort()

# Print list as JSON
print(json.dumps(testcases))

0 comments on commit 8217be9

Please sign in to comment.