From c705d1d02ef57b39aa1340650ccdf7ef62a57f23 Mon Sep 17 00:00:00 2001 From: Foivos Date: Sun, 26 May 2024 01:17:35 +0300 Subject: [PATCH] feat: codecov (#30) * 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 --- .github/workflows/codecov.yaml | 46 ++++++++++++++++++++++++++++++++++ .gitignore | 5 ++++ README.md | 21 ++++++++++++++++ package.json | 3 ++- scripts/coverage.sh | 44 ++++++++++++++++++++++++++++++++ 5 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/codecov.yaml create mode 100755 scripts/coverage.sh diff --git a/.github/workflows/codecov.yaml b/.github/workflows/codecov.yaml new file mode 100644 index 00000000..31b0c81d --- /dev/null +++ b/.github/workflows/codecov.yaml @@ -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 diff --git a/.gitignore b/.gitignore index 400d01d3..df403927 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,8 @@ move/**/build Move.lock +# Local sui build +/sui ### Information Cache ### @@ -24,6 +26,9 @@ lerna-debug.log* # Coverage directory used by tools like istanbul coverage *.lcov +.trace +*.mvcov +.coverage.info # Dependency directories node_modules/ diff --git a/README.md b/README.md index 43c90b69..1367590a 100644 --- a/README.md +++ b/README.md @@ -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`. diff --git a/package.json b/package.json index ffb90f5f..03259caf 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts/coverage.sh b/scripts/coverage.sh new file mode 100755 index 00000000..fe3a8163 --- /dev/null +++ b/scripts/coverage.sh @@ -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