Skip to content

Commit

Permalink
feat: codecov (#30)
Browse files Browse the repository at this point in the history
* checking what files exist

* properly running coverage

* try devnet 1.25.0

* trying to do use sui-debug instead

* delete sui

* try to move debug instead

* ls to see what is created

* try copying the correct files

* trying some more things

* fix a bug

* update .gitignore

* try uploading .trace

* try uploading mvcov

* faster action

* debug

* test

* update README

* switch binary name

* add coverage script

* also show coverage sources

* fix file path

---------

Co-authored-by: Milap Sheth <[email protected]>
  • Loading branch information
Foivos and milapsheth authored May 25, 2024
1 parent 710e400 commit c705d1d
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 1 deletion.
46 changes: 46 additions & 0 deletions .github/workflows/codecov.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Code Coverage
on: pull_request

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
coverage:
runs-on: ubuntu-latest

steps:
- name: Setup Dependencies for Sui Binary
run: sudo apt-get update && sudo apt-get install -y libpq-dev

- name: Download and Install Sui
env:
SUI_VERSION: devnet-v1.25.0
run: |
curl -L -o sui-${SUI_VERSION}-ubuntu-x86_64.tgz https://github.com/MystenLabs/sui/releases/download/${SUI_VERSION}/sui-${SUI_VERSION}-ubuntu-x86_64.tgz
tar -xvf sui-${SUI_VERSION}-ubuntu-x86_64.tgz
sudo mv ./sui-test-validator /usr/local/bin/sui-test-validator
sudo mv ./sui /usr/local/bin/sui
sudo mv ./sui-debug /usr/local/bin/sui-debug
rm -rf sui-${SUI_VERSION}-ubuntu-x86_64.tgz
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 18
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Build
run: npm run build

- name: Test
run: npm run coverage

- name: Display coverage report
run: cat ./.coverage.info
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

move/**/build
Move.lock
# Local sui build
/sui

### Information Cache ###

Expand All @@ -24,6 +26,9 @@ lerna-debug.log*
# Coverage directory used by tools like istanbul
coverage
*.lcov
.trace
*.mvcov
.coverage.info

# Dependency directories
node_modules/
Expand Down
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,27 @@ Run tests for all Move packages
npm run test
```

### Coverage

To run code coverage, Sui debug binary needs to be built locally. You can also see coverage reports from the GH actions.

```sh
brew install libpq
brew link --force libpq

git clone https://github.com/MystenLabs/sui.git
cd sui
cargo build
cd ..
./sui/target/debug/sui version

# Put this sui build on the PATH with the name `sui-debug`

npm run coverage
```

See `.coverage.info` for the coverage report.

### Development

Install the `Move` extension in VS Code. It should come pre-installed with `move-analyzer`.
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"main": "index.js",
"scripts": {
"build": "for d in ./move/*/; do cd $d; sui move build --lint --warnings-are-errors; cd ../../; done",
"test": "for d in ./move/*/; do sui move test --path $d; done"
"test": "for d in ./move/*/; do sui move test --path $d; done",
"coverage": "./scripts/coverage.sh"
},
"keywords": [
"axelar",
Expand Down
44 changes: 44 additions & 0 deletions scripts/coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/sh

export SUI=sui-debug

# Check if sui-debug is available
if ! type "$SUI" >/dev/null 2>&1; then
echo "sui-debug not found. Setting SUI to ./sui/target/debug/sui."

# Default to a local Sui build
export SUI="./sui/target/debug/sui"

# Check if the file exists
if [ ! -f "$SUI" ]; then
echo "Error: $SUI not found. Exiting."
exit 1
fi
fi

echo 'Axelar Move Coverage Report' > .coverage.info
echo '' >> .coverage.info

for d in ./move/*/; do
"$SUI" move test --path "$d" --coverage &
done

wait

for d in ./move/*/; do
echo "Generating coverage info for package $d"

if [ ! -f "$d/.coverage_map.mvcov" ]; then
echo "\n NO tests found for module $d. Skipped.\n" >> .coverage.info
continue
fi

echo "\nCoverage report for module $d\n" >> .coverage.info

"$SUI" move coverage summary --path "$d" >> .coverage.info

# Display source code with coverage info
find "$d/sources" -type f -name '*.move' | while IFS= read -r f; do
"$SUI" move coverage source --path "$d" --module "$(basename "$f" .move)"
done
done

0 comments on commit c705d1d

Please sign in to comment.