diff --git a/.github/actions/prune-vm/action.yml b/.github/actions/prune-vm/action.yml new file mode 100644 index 0000000000..8ee620825c --- /dev/null +++ b/.github/actions/prune-vm/action.yml @@ -0,0 +1,27 @@ +# Inspired by https://github.com/AdityaGarg8/remove-unwanted-software +# to free up disk space. Currently removes Dotnet, Android and Haskell. +name: Remove unwanted software +description: Default GitHub runners come with a lot of unnecessary software +runs: + using: "composite" + steps: + - name: Disk space report before modification + shell: bash + run: | + echo "==> Available space before cleanup" + echo + df -h + - name: Maximize build disk space + shell: bash + run: | + set -euo pipefail + sudo rm -rf /usr/share/dotnet + sudo rm -rf /usr/local/lib/android + sudo rm -rf /opt/ghc + sudo rm -rf /usr/local/.ghcup + - name: Disk space report after modification + shell: bash + run: | + echo "==> Available space after cleanup" + echo + df -h diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 49f5a52038..22f6207a45 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -124,6 +124,7 @@ jobs: with: nim_wakunode_image: ${{ inputs.nim_wakunode_image || 'wakuorg/nwaku:v0.31.0' }} test_type: node + allure_reports: true node_optional: uses: ./.github/workflows/test-node.yml diff --git a/.github/workflows/test-node.yml b/.github/workflows/test-node.yml index 21cc501ddc..980bfce964 100644 --- a/.github/workflows/test-node.yml +++ b/.github/workflows/test-node.yml @@ -18,18 +18,24 @@ on: required: false type: string default: '' + allure_reports: + required: false + type: boolean + default: false env: NODE_JS: "20" # Ensure test type conditions remain consistent. WAKU_SERVICE_NODE_PARAMS: ${{ (inputs.test_type == 'go-waku-master') && '--min-relay-peers-to-publish=0' || '' }} DEBUG: ${{ inputs.debug }} + GITHUB_TOKEN: ${{ secrets.DEPLOY_TEST_REPORTS_PAT }} jobs: node: runs-on: ubuntu-latest env: WAKUNODE_IMAGE: ${{ inputs.nim_wakunode_image }} + ALLURE_REPORTS: ${{ inputs.allure_reports }} permissions: contents: read actions: read @@ -39,6 +45,9 @@ jobs: with: repository: waku-org/js-waku + - name: Remove unwanted software + uses: ./.github/actions/prune-vm + - uses: actions/setup-node@v3 with: node-version: ${{ env.NODE_JS }} @@ -47,16 +56,42 @@ jobs: - run: npm run build:esm - - run: ${{ (inputs.test_type == 'node-optional') && 'npm run test:optional --workspace=@waku/tests' || 'npm run test:node' }} + - name: Run tests + timeout-minutes: 30 + run: ${{ (inputs.test_type == 'node-optional') && 'npm run test:optional --workspace=@waku/tests' || 'npm run test:node' }} + + - name: Merge allure reports + if: always() && env.ALLURE_REPORTS == 'true' + run: node ci/mergeAllureResults.cjs + + - name: Get allure history + if: always() && env.ALLURE_REPORTS == 'true' + uses: actions/checkout@v3 + continue-on-error: true + with: + repository: waku-org/allure-jswaku + ref: gh-pages + path: gh-pages + token: ${{ env.GITHUB_TOKEN }} - - name: Test Report - uses: dorny/test-reporter@v1 - if: success() || failure() + - name: Setup allure report + if: always() && env.ALLURE_REPORTS == 'true' + uses: simple-elf/allure-report-action@master + id: allure-report with: - name: Test Report - ${{ inputs.test_type }} - path: 'packages/tests/reports/mocha-*.json' - reporter: mocha-json - fail-on-error: true + allure_results: allure-results + gh_pages: gh-pages + allure_history: allure-history + keep_reports: 30 + + - name: Deploy report to Github Pages + if: always() && env.ALLURE_REPORTS == 'true' + uses: peaceiris/actions-gh-pages@v3 + with: + personal_token: ${{ env.GITHUB_TOKEN }} + external_repository: waku-org/allure-jswaku + publish_branch: gh-pages + publish_dir: allure-history - name: Upload debug logs on failure uses: actions/upload-artifact@v4 @@ -83,3 +118,11 @@ jobs: with: name: ${{ inputs.test_type }}-logs path: packages/tests/log/ + + - name: Create test summary + if: always() && env.ALLURE_REPORTS == 'true' + run: | + echo "## Run Information" >> $GITHUB_STEP_SUMMARY + echo "- **NWAKU**: ${{ env.WAKUNODE_IMAGE }}" >> $GITHUB_STEP_SUMMARY + echo "## Test Results" >> $GITHUB_STEP_SUMMARY + echo "Allure report will be available at: https://waku-org.github.io/allure-jswaku/${{ github.run_number }}" >> $GITHUB_STEP_SUMMARY \ No newline at end of file diff --git a/ci/mergeAllureResults.cjs b/ci/mergeAllureResults.cjs new file mode 100644 index 0000000000..afb414cb55 --- /dev/null +++ b/ci/mergeAllureResults.cjs @@ -0,0 +1,19 @@ +const fs = require("fs-extra"); +const glob = require("glob"); + +const ROOT_ALLURE_RESULTS = "./allure-results"; // Target directory in the root + +fs.ensureDirSync(ROOT_ALLURE_RESULTS); + +const directories = glob.sync("packages/**/allure-results"); + +directories.forEach((dir) => { + const files = fs.readdirSync(dir); + files.forEach((file) => { + const sourcePath = `${dir}/${file}`; + const targetPath = `${ROOT_ALLURE_RESULTS}/${file}`; + fs.copyFileSync(sourcePath, targetPath); + }); +}); + +console.log("All allure-results directories merged successfully!"); diff --git a/package-lock.json b/package-lock.json index 4aff4d781a..c17ac62759 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11923,6 +11923,59 @@ "ajv": "^6.9.1" } }, + "node_modules/allure-commandline": { + "version": "2.32.0", + "resolved": "https://registry.npmjs.org/allure-commandline/-/allure-commandline-2.32.0.tgz", + "integrity": "sha512-W03ors+ks8uy0SgQILHQvtvR0iadAfDYmTFC3p8Pk4pi8KXUW1cF+z8FN2+7deH3FE2cuYgjhhA+CdLdJfzOMQ==", + "dev": true, + "bin": { + "allure": "bin/allure" + } + }, + "node_modules/allure-js-commons": { + "version": "2.15.1", + "resolved": "https://registry.npmjs.org/allure-js-commons/-/allure-js-commons-2.15.1.tgz", + "integrity": "sha512-5V/VINplbu0APnfSZOkYpKOzucO36Q2EtTD1kqjWjl7n6tj7Hh+IHCZsH3Vpk/LXRDfj9RuXugBBvwYKV5YMJw==", + "dev": true, + "dependencies": { + "md5": "^2.3.0", + "properties": "^1.2.1", + "strip-ansi": "^5.2.0" + } + }, + "node_modules/allure-js-commons/node_modules/ansi-regex": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.1.tgz", + "integrity": "sha512-ILlv4k/3f6vfQ4OoP2AGvirOktlQ98ZEL1k9FaQjxa3L1abBgbuTDAdPOpvbGncC0BTVQrl+OM8xZGK6tWXt7g==", + "dev": true, + "engines": { + "node": ">=6" + } + }, + "node_modules/allure-js-commons/node_modules/strip-ansi": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", + "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", + "dev": true, + "dependencies": { + "ansi-regex": "^4.1.0" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/allure-mocha": { + "version": "2.15.1", + "resolved": "https://registry.npmjs.org/allure-mocha/-/allure-mocha-2.15.1.tgz", + "integrity": "sha512-4Hk2qUR6LdAUXNpPe73MV3DPKrBH7zy57lbAdb/D0poNIkdGEkzUYkpVPtW1imYfjqFXKBFEPOSJWqznGuiyjg==", + "dev": true, + "dependencies": { + "allure-js-commons": "2.15.1" + }, + "peerDependencies": { + "mocha": ">=6.2.x" + } + }, "node_modules/anser": { "version": "1.4.10", "resolved": "https://registry.npmjs.org/anser/-/anser-1.4.10.tgz", @@ -26336,6 +26389,22 @@ "node": ">= 14.0.0" } }, + "node_modules/mocha-multi-reporters": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/mocha-multi-reporters/-/mocha-multi-reporters-1.5.1.tgz", + "integrity": "sha512-Yb4QJOaGLIcmB0VY7Wif5AjvLMUFAdV57D2TWEva1Y0kU/3LjKpeRVmlMIfuO1SVbauve459kgtIizADqxMWPg==", + "dev": true, + "dependencies": { + "debug": "^4.1.1", + "lodash": "^4.17.15" + }, + "engines": { + "node": ">=6.0.0" + }, + "peerDependencies": { + "mocha": ">=3.1.2" + } + }, "node_modules/mocha/node_modules/cliui": { "version": "7.0.4", "resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz", @@ -33098,6 +33167,15 @@ "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", "license": "ISC" }, + "node_modules/properties": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/properties/-/properties-1.2.1.tgz", + "integrity": "sha512-qYNxyMj1JeW54i/EWEFsM1cVwxJbtgPp8+0Wg9XjNaK6VE/c4oRi6PNu5p7w1mNXEIQIjV5Wwn8v8Gz82/QzdQ==", + "dev": true, + "engines": { + "node": ">=0.10" + } + }, "node_modules/proto-list": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/proto-list/-/proto-list-1.2.4.tgz", @@ -41554,6 +41632,8 @@ "@waku/message-encryption": "*", "@waku/relay": "*", "@waku/sdk": "*", + "allure-commandline": "^2.27.0", + "allure-mocha": "^2.9.2", "chai": "^4.3.10", "cspell": "^8.6.1", "datastore-core": "^10.0.2", @@ -41561,6 +41641,7 @@ "interface-datastore": "^8.2.10", "libp2p": "2.1.8", "mocha": "^10.3.0", + "mocha-multi-reporters": "^1.5.1", "npm-run-all": "^4.1.5" }, "engines": { diff --git a/packages/core/.mocha.reporters.json b/packages/core/.mocha.reporters.json new file mode 100644 index 0000000000..8b32b1de9c --- /dev/null +++ b/packages/core/.mocha.reporters.json @@ -0,0 +1,6 @@ +{ + "reporterEnabled": "spec, allure-mocha", + "allureMochaReporter": { + "outputDir": "allure-results" + } + } \ No newline at end of file diff --git a/packages/core/.mocharc.cjs b/packages/core/.mocharc.cjs index 050314c578..2b2ce93ddf 100644 --- a/packages/core/.mocharc.cjs +++ b/packages/core/.mocharc.cjs @@ -15,13 +15,13 @@ if (process.env.CI) { console.log("Running tests in parallel"); config.parallel = true; config.jobs = 6; - console.log("Using JSON reporter for test results"); - config.reporter = 'json'; + console.log("Activating allure reporting"); + config.reporter = 'mocha-multi-reporters'; config.reporterOptions = { - output: 'reports/mocha-results.json' + configFile: '.mocha.reporters.json' }; } else { console.log("Running tests serially. To enable parallel execution update mocha config"); } -module.exports = config; +module.exports = config; \ No newline at end of file diff --git a/packages/discovery/.mocha.reporters.json b/packages/discovery/.mocha.reporters.json new file mode 100644 index 0000000000..8b32b1de9c --- /dev/null +++ b/packages/discovery/.mocha.reporters.json @@ -0,0 +1,6 @@ +{ + "reporterEnabled": "spec, allure-mocha", + "allureMochaReporter": { + "outputDir": "allure-results" + } + } \ No newline at end of file diff --git a/packages/discovery/.mocharc.cjs b/packages/discovery/.mocharc.cjs index 77cc8af51b..b61a6aaee5 100644 --- a/packages/discovery/.mocharc.cjs +++ b/packages/discovery/.mocharc.cjs @@ -15,10 +15,10 @@ if (process.env.CI) { console.log("Running tests in parallel"); config.parallel = true; config.jobs = 6; - console.log("Using JSON reporter for test results"); - config.reporter = 'json'; + console.log("Activating allure reporting"); + config.reporter = 'mocha-multi-reporters'; config.reporterOptions = { - output: 'reports/mocha-results.json' + configFile: '.mocha.reporters.json' }; } else { console.log("Running tests serially. To enable parallel execution update mocha config"); diff --git a/packages/enr/.mocha.reporters.json b/packages/enr/.mocha.reporters.json new file mode 100644 index 0000000000..8b32b1de9c --- /dev/null +++ b/packages/enr/.mocha.reporters.json @@ -0,0 +1,6 @@ +{ + "reporterEnabled": "spec, allure-mocha", + "allureMochaReporter": { + "outputDir": "allure-results" + } + } \ No newline at end of file diff --git a/packages/enr/.mocharc.cjs b/packages/enr/.mocharc.cjs index 77cc8af51b..5468a619d2 100644 --- a/packages/enr/.mocharc.cjs +++ b/packages/enr/.mocharc.cjs @@ -15,13 +15,12 @@ if (process.env.CI) { console.log("Running tests in parallel"); config.parallel = true; config.jobs = 6; - console.log("Using JSON reporter for test results"); - config.reporter = 'json'; + console.log("Activating allure reporting"); + config.reporter = 'mocha-multi-reporters'; config.reporterOptions = { - output: 'reports/mocha-results.json' + configFile: '.mocha.reporters.json' }; } else { console.log("Running tests serially. To enable parallel execution update mocha config"); } - module.exports = config; diff --git a/packages/message-encryption/.mocha.reporters.json b/packages/message-encryption/.mocha.reporters.json new file mode 100644 index 0000000000..8b32b1de9c --- /dev/null +++ b/packages/message-encryption/.mocha.reporters.json @@ -0,0 +1,6 @@ +{ + "reporterEnabled": "spec, allure-mocha", + "allureMochaReporter": { + "outputDir": "allure-results" + } + } \ No newline at end of file diff --git a/packages/message-encryption/.mocharc.cjs b/packages/message-encryption/.mocharc.cjs index 77cc8af51b..5468a619d2 100644 --- a/packages/message-encryption/.mocharc.cjs +++ b/packages/message-encryption/.mocharc.cjs @@ -15,13 +15,12 @@ if (process.env.CI) { console.log("Running tests in parallel"); config.parallel = true; config.jobs = 6; - console.log("Using JSON reporter for test results"); - config.reporter = 'json'; + console.log("Activating allure reporting"); + config.reporter = 'mocha-multi-reporters'; config.reporterOptions = { - output: 'reports/mocha-results.json' + configFile: '.mocha.reporters.json' }; } else { console.log("Running tests serially. To enable parallel execution update mocha config"); } - module.exports = config; diff --git a/packages/message-hash/.mocha.reporters.json b/packages/message-hash/.mocha.reporters.json new file mode 100644 index 0000000000..8b32b1de9c --- /dev/null +++ b/packages/message-hash/.mocha.reporters.json @@ -0,0 +1,6 @@ +{ + "reporterEnabled": "spec, allure-mocha", + "allureMochaReporter": { + "outputDir": "allure-results" + } + } \ No newline at end of file diff --git a/packages/message-hash/.mocharc.cjs b/packages/message-hash/.mocharc.cjs index 77cc8af51b..5468a619d2 100644 --- a/packages/message-hash/.mocharc.cjs +++ b/packages/message-hash/.mocharc.cjs @@ -15,13 +15,12 @@ if (process.env.CI) { console.log("Running tests in parallel"); config.parallel = true; config.jobs = 6; - console.log("Using JSON reporter for test results"); - config.reporter = 'json'; + console.log("Activating allure reporting"); + config.reporter = 'mocha-multi-reporters'; config.reporterOptions = { - output: 'reports/mocha-results.json' + configFile: '.mocha.reporters.json' }; } else { console.log("Running tests serially. To enable parallel execution update mocha config"); } - module.exports = config; diff --git a/packages/relay/.mocha.reporters.json b/packages/relay/.mocha.reporters.json new file mode 100644 index 0000000000..8b32b1de9c --- /dev/null +++ b/packages/relay/.mocha.reporters.json @@ -0,0 +1,6 @@ +{ + "reporterEnabled": "spec, allure-mocha", + "allureMochaReporter": { + "outputDir": "allure-results" + } + } \ No newline at end of file diff --git a/packages/relay/.mocharc.cjs b/packages/relay/.mocharc.cjs index 77cc8af51b..5468a619d2 100644 --- a/packages/relay/.mocharc.cjs +++ b/packages/relay/.mocharc.cjs @@ -15,13 +15,12 @@ if (process.env.CI) { console.log("Running tests in parallel"); config.parallel = true; config.jobs = 6; - console.log("Using JSON reporter for test results"); - config.reporter = 'json'; + console.log("Activating allure reporting"); + config.reporter = 'mocha-multi-reporters'; config.reporterOptions = { - output: 'reports/mocha-results.json' + configFile: '.mocha.reporters.json' }; } else { console.log("Running tests serially. To enable parallel execution update mocha config"); } - module.exports = config; diff --git a/packages/sdk/.mocha.reporters.json b/packages/sdk/.mocha.reporters.json new file mode 100644 index 0000000000..8b32b1de9c --- /dev/null +++ b/packages/sdk/.mocha.reporters.json @@ -0,0 +1,6 @@ +{ + "reporterEnabled": "spec, allure-mocha", + "allureMochaReporter": { + "outputDir": "allure-results" + } + } \ No newline at end of file diff --git a/packages/sdk/.mocharc.cjs b/packages/sdk/.mocharc.cjs index 77cc8af51b..ad2a3b2e6c 100644 --- a/packages/sdk/.mocharc.cjs +++ b/packages/sdk/.mocharc.cjs @@ -15,13 +15,12 @@ if (process.env.CI) { console.log("Running tests in parallel"); config.parallel = true; config.jobs = 6; - console.log("Using JSON reporter for test results"); - config.reporter = 'json'; + console.log("Activating allure reporting"); + config.reporter = 'mocha-multi-reporters'; config.reporterOptions = { - output: 'reports/mocha-results.json' + configFile: '.mocha.reporters.json' }; } else { console.log("Running tests serially. To enable parallel execution update mocha config"); } - -module.exports = config; +module.exports = config; \ No newline at end of file diff --git a/packages/tests/.mocha.reporters.json b/packages/tests/.mocha.reporters.json new file mode 100644 index 0000000000..8b32b1de9c --- /dev/null +++ b/packages/tests/.mocha.reporters.json @@ -0,0 +1,6 @@ +{ + "reporterEnabled": "spec, allure-mocha", + "allureMochaReporter": { + "outputDir": "allure-results" + } + } \ No newline at end of file diff --git a/packages/tests/.mocharc.cjs b/packages/tests/.mocharc.cjs index 78120b5e32..f2ea3f66ce 100644 --- a/packages/tests/.mocharc.cjs +++ b/packages/tests/.mocharc.cjs @@ -14,13 +14,12 @@ if (process.env.CI) { console.log("Running tests in parallel"); config.parallel = true; config.jobs = 6; - console.log("Using JSON reporter for test results"); - config.reporter = 'json'; + console.log("Activating allure reporting"); + config.reporter = 'mocha-multi-reporters'; config.reporterOptions = { - output: 'reports/mocha-results.json' + configFile: '.mocha.reporters.json' }; } else { console.log("Running tests serially. To enable parallel execution update mocha config"); } - -module.exports = config; +module.exports = config; \ No newline at end of file diff --git a/packages/tests/package.json b/packages/tests/package.json index 06c6e97f42..c1e3385009 100644 --- a/packages/tests/package.json +++ b/packages/tests/package.json @@ -42,8 +42,8 @@ "check:spelling": "cspell \"{README.md,{tests,src}/**/*.ts}\"", "check:tsc": "tsc -p tsconfig.dev.json", "test": "NODE_ENV=test run-s test:*", - "test:node": "NODE_ENV=test mkdir -p reports && node ./src/run-tests.js \"tests/**/!(*.optional).spec.ts\"", - "test:optional": "NODE_ENV=test mkdir -p reports && node ./src/run-tests.js \"tests/**/@(*.optional).spec.ts\"", + "test:node": "NODE_ENV=test node ./src/run-tests.js \"tests/**/!(*.optional).spec.ts\"", + "test:optional": "NODE_ENV=test node ./src/run-tests.js \"tests/**/@(*.optional).spec.ts\"", "reset-hard": "git clean -dfx -e .idea && git reset --hard && npm i && npm run build" }, "engines": { @@ -79,6 +79,8 @@ "@waku/message-encryption": "*", "@waku/relay": "*", "@waku/sdk": "*", + "allure-commandline": "^2.27.0", + "allure-mocha": "^2.9.2", "chai": "^4.3.10", "cspell": "^8.6.1", "datastore-core": "^10.0.2", @@ -86,6 +88,7 @@ "interface-datastore": "^8.2.10", "libp2p": "2.1.8", "mocha": "^10.3.0", + "mocha-multi-reporters": "^1.5.1", "npm-run-all": "^4.1.5" } } diff --git a/packages/tests/src/run-tests.js b/packages/tests/src/run-tests.js index db9547f876..b468bdc00e 100644 --- a/packages/tests/src/run-tests.js +++ b/packages/tests/src/run-tests.js @@ -1,6 +1,4 @@ import { exec, spawn } from "child_process"; -import { mkdir } from "fs/promises"; -import { dirname } from "path"; import { promisify } from "util"; const execAsync = promisify(exec); @@ -22,34 +20,10 @@ async function main() { "--require", "ts-node/register", "--project", - "./tsconfig.dev.json" + "./tsconfig.dev.json", + ...process.argv.slice(2) ]; - if (process.env.CI) { - const reportPath = "reports/mocha-results.json"; - await mkdir(dirname(reportPath), { recursive: true }); - - mochaArgs.push( - "--reporter", - "json", - "--reporter-option", - `output=${reportPath}`, - "--parallel", - "--jobs", - "6" - ); - } - - // Add test files - const testFiles = process.argv.slice(2); - if (testFiles.length === 0) { - // Default to all test files if none specified - testFiles.push("tests/**/*.spec.ts"); - } - mochaArgs.push(...testFiles); - - console.log("Running mocha with args:", mochaArgs); - // Run mocha tests const mocha = spawn("npx", mochaArgs, { stdio: "inherit", diff --git a/packages/utils/.mocha.reporters.json b/packages/utils/.mocha.reporters.json new file mode 100644 index 0000000000..8b32b1de9c --- /dev/null +++ b/packages/utils/.mocha.reporters.json @@ -0,0 +1,6 @@ +{ + "reporterEnabled": "spec, allure-mocha", + "allureMochaReporter": { + "outputDir": "allure-results" + } + } \ No newline at end of file diff --git a/packages/utils/.mocharc.cjs b/packages/utils/.mocharc.cjs index 77cc8af51b..5468a619d2 100644 --- a/packages/utils/.mocharc.cjs +++ b/packages/utils/.mocharc.cjs @@ -15,13 +15,12 @@ if (process.env.CI) { console.log("Running tests in parallel"); config.parallel = true; config.jobs = 6; - console.log("Using JSON reporter for test results"); - config.reporter = 'json'; + console.log("Activating allure reporting"); + config.reporter = 'mocha-multi-reporters'; config.reporterOptions = { - output: 'reports/mocha-results.json' + configFile: '.mocha.reporters.json' }; } else { console.log("Running tests serially. To enable parallel execution update mocha config"); } - module.exports = config;