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

74 add test coverage to readme #96

Closed
wants to merge 22 commits into from
Closed
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
31 changes: 31 additions & 0 deletions .github/coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

color="red"

# Remove the percentage sign
COVERAGE="${COVERAGE//%}"

if [ "$COVERAGE" -ge 80 ]; then
color="green"
elif [ "$COVERAGE" -ge 70 ]; then
color="orange"
fi

filename="README.md"

coverageLine=$(sed -n '3p' $filename)

regex="coverage-([0-9]+)%"

if [[ $coverageLine =~ $regex ]]; then
oldCoverage="${BASH_REMATCH[1]}"
echo "Coverage is $COVERAGE%"
else
echo "No coverage found"
fi

if [ "$oldCoverage" != "$COVERAGE" ] || [ -z "$oldCoverage" ]; then
echo "Updating badge"
newLine="![check-code-coverage](https://img.shields.io/badge/coverage-$COVERAGE%25-$color)"
sed -i "3s#.*#${newLine}#" $filename
fi
57 changes: 57 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Unit tests

on:
push:
workflow_call:

jobs:
build:

runs-on: ubuntu-latest

permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the changed files back to the repository.
contents: write

steps:
- name: Checkout code
uses: actions/checkout@v3
with:
# https://github.com/actions/checkout/issues/298#issuecomment-664976337
ref: ${{ github.head_ref }}
# Checkout code using massabot account
token: ${{ secrets.MASSABOTCLASSIC || github.token }}

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 18.x
cache: 'npm'

- name: Execute unit tests
run: |
cd smart-contracts
npm ci
npm run fmt:check
npm run test:ci

- id: coverage
name: Extract coverage
run: |
cd smart-contracts
value=$(npm run test:ci | grep -oE '^│\s*total\s+\│\s*([0-9.]+)%' | grep -oE '[0-9]+(\.[0-9]+)?%' | cut -d'.' -f1)
echo "coverage=$value" >> $GITHUB_OUTPUT

- name: Add test coverage to README
run: .github/coverage.sh
shell: bash
env:
COVERAGE: ${{ steps.coverage.outputs.coverage }}

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "Generate coverage badge"
file_pattern: "README.md"
# Commit code using massabot account that can bypass push and MR restriction
commit_author: massabot <[email protected]>
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Massa Standard Definition

![check-code-coverage](https://img.shields.io/badge/coverage-91%25-green)

Welcome to the Massa Standard Definition project!

This project aims to establish a common set of standards for the Massa blockchain ecosystem. The standards defined here will help to promote interoperability and ease of use for Massa-based applications and services.
Expand Down
3 changes: 3 additions & 0 deletions smart-contracts/as-pect-ci.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import config from './as-pect.config.js';
config.coverage = ['assembly/**/*.ts'];
export default config;
6 changes: 3 additions & 3 deletions smart-contracts/as-pect.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ export default {
/**
* A set of globs passed to the glob package that qualify typescript files for testing.
*/
entries: ['assembly/**/__tests__/**/*.spec.ts'],
entries: ['**/assembly/**/*.spec.ts'],
/**
* A set of globs passed to the glob package that quality files to be added to each test.
*/
include: ['assembly/**/__tests__/**/*.include.ts'],
// include: ['assembly/**/__tests__/**/*.include.ts'],
/**
* A set of regexp that will disclude source files from testing.
*/
Expand All @@ -20,7 +20,7 @@ export default {
return createMockedABI(memory, createImports, instantiate, binary);
},
/** Enable code coverage. */
// coverage: ["assembly/**/*.ts"],
// coverage: ['assembly/**/*.ts'],
/**
* Specify if the binary wasm file should be written to the file system.
*/
Expand Down
Loading