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

[feat] Add testing to CI pipeline #71

Merged
merged 1 commit into from
Sep 4, 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
29 changes: 29 additions & 0 deletions .github/workflows/contract_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,32 @@ jobs:
run: |
cd contracts
scarb check

run-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Check for changes
uses: dorny/paths-filter@v3
id: changes
with:
filters: |
contracts_dir:
- 'contracts/src/**'

- name: Install scarb
if: steps.changes.outputs.contracts_dir == 'true'
run: |
cd contracts
curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh -s -- -v 2.6.5

- name: Install snfoundry
uses: foundry-rs/setup-snfoundry@v3
with:
starknet-foundry-version: "0.20.1"

- name: Run Cairo tests
id: cairo_tests
run: bash scripts/run_tests.sh
3 changes: 3 additions & 0 deletions contracts/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", ta
[dev-dependencies]
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.20.1" }

[scripts]
test = "snforge test"

[[target.starknet-contract]]
casm = true
30 changes: 30 additions & 0 deletions scripts/run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

set -e

tests_output=$(cd contracts && scarb run test || true)

# Get summary information
echo "::group::Summary"

tests_passed=$(echo "$tests_output" | awk '/Tests:/ {print $2}')
tests_failed=$(echo "$tests_output" | awk '/Tests:/ {print $4}')
skipped_count=$(echo "$tests_output" | awk '/Tests:/ {print $6}')
ignored_count=$(echo "$tests_output" | awk '/Tests:/ {print $6}')
filtered_out_count=$(echo "$tests_output" | awk '/Tests:/ {print $6}')

echo "Tests passed: $tests_passed"
echo "Tests failed: $tests_failed"
echo "Skipped: $skipped_count"
echo "Ignored: $ignored_count"
echo "Filtered out: $filtered_out_count"
echo "::endgroup::"

# Check for failed tests

if [ "$tests_failed" -gt 0 ]; then
failed_tests=$(echo "$tests_output" | awk '/Failures:/{flag=1;next}/^\s*$/{flag=0}flag')
echo "::error::Tests failed:"
echo "$failed_tests"
exit 1
fi
Loading