diff --git a/.github/workflows/massa-web3-unit-test.yml b/.github/workflows/workspace-unit-test.yml similarity index 86% rename from .github/workflows/massa-web3-unit-test.yml rename to .github/workflows/workspace-unit-test.yml index 2f735f175..d64555453 100644 --- a/.github/workflows/massa-web3-unit-test.yml +++ b/.github/workflows/workspace-unit-test.yml @@ -6,9 +6,9 @@ on: jobs: build: - defaults: - run: - working-directory: ./packages/massa-web3/examples/smartContracts/ + strategy: + matrix: + project: [massa-web3, web3-utils] runs-on: ubuntu-latest @@ -44,13 +44,6 @@ jobs: npm run build working-directory: ./ - - name: Execute unit tests - run: | - npm ci - npm run build - npm run fmt:check - npm run test - - name: allow access to coverage.sh run: chmod +x ./scripts/coverage.sh shell: bash @@ -58,7 +51,7 @@ jobs: - name: Extract coverage id: coverage run: | - value=$(npm run test:cov | awk '/All files/ {print $10}' | tr -d '%') + value=$(npm run test:cov -w ${{ matrix.project }} | awk '/All files/ {print $10}' | tr -d '%') echo "coverage=$value" >> $GITHUB_OUTPUT - name: Add test coverage to README @@ -66,6 +59,7 @@ jobs: shell: bash env: COVERAGE: ${{ steps.coverage.outputs.coverage }} + PROJECT: ${{ matrix.project }} - name: Check if coverage changed id: check_coverage_changed diff --git a/README.md b/README.md new file mode 100644 index 000000000..2d75d0e1c --- /dev/null +++ b/README.md @@ -0,0 +1,35 @@ +# Massa Web3 Workspace + +Welcome to the Massa Web3 Workspace. This space houses a collection of projects designed to bolster interaction with the Massa blockchain through TypeScript. Below is an overview of each project with links to their respective READMEs for more in-depth information. + +## Projects within the Workspace + +### 1. **Massa-web3** + +![check-code-coverage](https://img.shields.io/badge/coverage-95.25%25-green) + +**Description:** +Massa-web3 is a TypeScript library that facilitates communication with the Massa blockchain. It's your key to extracting data, interfacing with smart contracts, monitoring blockchain events, and much more. + +- [📖 Read the full `Massa-web3` README](https://github.com/massalabs/massa-web3#readme) for detailed installation instructions, prerequisites, and additional resources. + +### 2. **Web3-Utils** + +![check-code-coverage](https://img.shields.io/badge/coverage-40%25-red) + +**Description:** +Web3-Utils is a toolkit crafted for the Massa TypeScript projects. Although it currently lacks a dedicated README, this utility provides an array of essential tools to streamline and enhance your blockchain interactions. + +- README for `Web3-Utils` will be available soon. + +## Contributing + +Community contributions are the backbone of our projects. If you wish to be a part of our growth and improve our tools, we'd love to have you! Please consult the [CONTRIBUTING guidelines](CONTRIBUTING.md) of the respective project. + +## License + +All projects within the Massa Web3 Workspace are released under the [MIT License](LICENSE). + +## Powered By + +These tools are developed with ❤️ by MassaLabs. Check out the [Powered By](powered-by.md) section to see the open-source projects that make our tools possible. diff --git a/package.json b/package.json index 3107360a4..d4ac8cc37 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "main": "index.js", "scripts": { "test": "npm run test --ws --if-present", + "test:cov": "npm run test:cov --ws --if-present", "build": "npm run build --ws --if-present", "prettier": "npm run prettier --ws --if-present", "prettier:fix": "npm run prettier:fix --ws --if-present", diff --git a/packages/massa-web3/package.json b/packages/massa-web3/package.json index 6f1ca7e7e..b125796e7 100644 --- a/packages/massa-web3/package.json +++ b/packages/massa-web3/package.json @@ -19,7 +19,7 @@ "test": "jest ----detectOpenHandles --forceExit", "test:watch": "jest --watch", "test:watch:all": "jest --watchAll", - "test:cov": "jest --coverage", + "test:cov": "jest --coverage --silent", "test-smart-contract-example": "ts-node ./examples/smartContracts/index.ts", "test-wallet": "ts-node ./examples/wallet/index.ts", "lint": "eslint .", diff --git a/packages/web3-utils/package.json b/packages/web3-utils/package.json index 05a07e9c6..1ca954ff8 100644 --- a/packages/web3-utils/package.json +++ b/packages/web3-utils/package.json @@ -11,7 +11,7 @@ "build-commonjs": "tsc --project tsconfig.commonjs.json", "build": "npm-run-all clean-dist build-*", "test": "jest --passWithNoTests", - "test:cov": "jest --coverage --passWithNoTests", + "test:cov": "jest --coverage --silent --passWithNoTests", "lint": "eslint .", "lint:fix": "eslint . --fix", "prettier": "prettier --check .", diff --git a/scripts/coverage.sh b/scripts/coverage.sh index 57958aba8..4aa87c673 100755 --- a/scripts/coverage.sh +++ b/scripts/coverage.sh @@ -1,28 +1,71 @@ #!/bin/bash -color="red" +# Define the color based on coverage threshold +determine_color() { + local coverage=$1 -if [ "$(echo "$COVERAGE >= 80" | bc -l)" -eq 1 ]; then - color="green" -elif [ "$(echo "$COVERAGE >= 70" | bc -l)" -eq 1 ]; then - color="orange" -fi + if (( $(echo "$coverage >= 80" | bc -l) )); then + echo "green" + elif (( $(echo "$coverage >= 70" | bc -l) )); then + echo "orange" + else + echo "red" + fi +} filename="README.md" -coverageLine=$(sed -n '3p' $filename) +# Indexed arrays for projects and their corresponding line numbers +projects=("massa-web3" "web3-utils") +lines=(9 18) + +# Get line number for the given project +get_line_number() { + local project=$1 + local i=0 + for p in "${projects[@]}"; do + if [ "$p" == "$project" ]; then + echo "${lines[$i]}" + return + fi + ((i++)) + done + echo "" +} -regex="coverage-([0-9]+([.][0-9]+)?)%" +line_number=$(get_line_number $PROJECT) + +# If no line number found, exit the script +if [ -z "$line_number" ]; then + echo "Project '$PROJECT' not found in the map." + exit 1 +fi + +# If no line number found, exit the script +if [ -z "$line_number" ]; then + echo "Project '$PROJECT' not found in the map." + exit 1 +fi + +# Extract the current coverage badge from the specified line +coverageLine=$(sed -n "${line_number}p" $filename) + +# Regex to match the coverage percentage +regex="${PROJECT}:\s*([0-9]+([.][0-9]+)?)%" if [[ $coverageLine =~ $regex ]]; then oldCoverage="${BASH_REMATCH[1]}" - echo "Coverage is $COVERAGE%" + echo "Coverage for $PROJECT is $COVERAGE%" else - echo "No coverage found" + echo "No coverage found for $PROJECT." fi -if [ -z "$oldCoverage" ] || [ "$(echo "$COVERAGE - $oldCoverage >= 1" | bc -l)" -eq 1 ] || [ "$(echo "$oldCoverage - $COVERAGE >= 1" | bc -l)" -eq 1 ]; then - echo "Updating badge" +# Determine the color for the badge based on the coverage +color=$(determine_color $COVERAGE) + +# Update the coverage badge if the difference in coverage is greater than or equal to 1% +if [ -z "$oldCoverage" ] || (( $(echo "$COVERAGE - $oldCoverage >= 1" | bc -l) )) || (( $(echo "$oldCoverage - $COVERAGE >= 1" | bc -l) )); then + echo "Updating badge for $PROJECT." newLine="![check-code-coverage](https://img.shields.io/badge/coverage-$COVERAGE%25-$color)" - sed -i "3s#.*#${newLine}#" $filename + sed -i "" "${line_number}s#.*#${newLine}#" $filename fi \ No newline at end of file