Skip to content

Commit

Permalink
Merge pull request #71 from bitfalt/dev
Browse files Browse the repository at this point in the history
[feat] Add testing to CI pipeline
  • Loading branch information
adrianvrj authored Sep 4, 2024
2 parents 586e74e + e4f8cda commit 3f81e0c
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
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

0 comments on commit 3f81e0c

Please sign in to comment.