From 099ad5831270779f20a762c794ca3efea0473199 Mon Sep 17 00:00:00 2001
From: aelf-lxy
Date: Tue, 13 Aug 2024 16:22:08 +0800
Subject: [PATCH 1/4] feat: test badge
---
.github/workflows/coverage.yml | 40 ++++++++++++++++++++++++++++++++
.github/workflows/publish.yml | 33 ++++++++++++++++++++++++++
.github/workflows/test-badge.yml | 20 ++++++++++++++++
README.md | 15 ++++++++++++
jest.browser.config.js | 11 ++++++++-
package.json | 1 +
yarn.lock | 25 ++++++++++++++++++++
7 files changed, 144 insertions(+), 1 deletion(-)
create mode 100644 .github/workflows/coverage.yml
create mode 100644 .github/workflows/publish.yml
create mode 100644 .github/workflows/test-badge.yml
diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml
new file mode 100644
index 00000000..99c0abfa
--- /dev/null
+++ b/.github/workflows/coverage.yml
@@ -0,0 +1,40 @@
+name: Unit Test Coverage
+
+on:
+ push:
+ branches:
+ - feature/test-chain-util
+ pull_request:
+ branches:
+ - feature/test-chain-util
+
+jobs:
+ test:
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v3
+
+ - name: Set up Node.js
+ uses: actions/setup-node@v3
+ with:
+ node-version: '18'
+
+ - name: Install dependencies
+ run: yarn install
+
+ - name: Run tests with coverage
+ run: yarn run test:coverage
+
+ - name: Generate coverage badge
+ uses: jaywcjlove/coverage-badges-cli@main
+ with:
+ source: coverage/coverage-summary.json
+ output: coverage/badges.svg
+
+ - name: Deploy to GitHub Pages
+ uses: peaceiris/actions-gh-pages@v3
+ with:
+ github_token: ${{ secrets.GITHUB_TOKEN }}
+ publish_dir: ./coverage
diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml
new file mode 100644
index 00000000..2355e34f
--- /dev/null
+++ b/.github/workflows/publish.yml
@@ -0,0 +1,33 @@
+name: Publish
+env:
+ CI: true
+on:
+ push:
+ branches:
+ - feature/test-chain-util
+ tags:
+ - '!*'
+jobs:
+ release:
+ name: Setup
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v3
+
+ - name: Set up Node.js
+ uses: actions/setup-node@v3
+ with:
+ node-version: '20'
+ registry-url: 'https://npm.pkg.github.com'
+
+ - name: Install dependencies
+ run: yarn install
+
+ - name: Publish to npm
+ run: |
+ npm config set //registry.npmjs.org/:_authToken=$NPM_TOKEN
+ npm publish || (echo "pnpm publish failed" && exit 1)
+ env:
+ NPM_TOKEN: ${{secrets.NPM_TOKEN}}
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
diff --git a/.github/workflows/test-badge.yml b/.github/workflows/test-badge.yml
new file mode 100644
index 00000000..65c9cd94
--- /dev/null
+++ b/.github/workflows/test-badge.yml
@@ -0,0 +1,20 @@
+name: Test Badge
+
+permissions:
+ contents: write
+
+on:
+ push:
+ branches:
+ - master
+ - feature/test-chain-util
+
+jobs:
+ build-and-test:
+ runs-on: ubuntu-latest
+ steps:
+ - name: Run frontend ci action
+ uses: AElfProject/frontend-ci-action@v0.0.1
+ with:
+ commit-token: ${{ secrets.COMMIT_TOKEN }}
+ branch-name: "feature/badge-json"
diff --git a/README.md b/README.md
index e1c1a545..ff066eb1 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,20 @@
# aelf-sdk.js - AELF JavaScript API
+
+
+
+
+
+
+
+
+
+
+
+ | Branch | Tests | Coverage |
+|--------------|-----------------|----------------|
+| `feature/test-chain-util` |  |  |
+
| Statements | Branches | Functions | Lines |
| --------------------------- | ----------------------- | ------------------------- | ----------------- |
|  |  |  |  |
diff --git a/jest.browser.config.js b/jest.browser.config.js
index 6797efa9..15775a5e 100644
--- a/jest.browser.config.js
+++ b/jest.browser.config.js
@@ -123,7 +123,16 @@ module.exports = {
// projects: null,
// Use this configuration option to add custom reporters to Jest
- // reporters: [],
+ reporters: [
+ 'default',
+ [
+ 'jest-junit',
+ {
+ outputDirectory: '.',
+ outputName: 'jest-report.xml'
+ }
+ ]
+ ],
// Automatically reset mock state between every test
// resetMocks: false,
diff --git a/package.json b/package.json
index 0ef8b07f..b4cbdd42 100644
--- a/package.json
+++ b/package.json
@@ -122,6 +122,7 @@
"jest-environment-jsdom": "^29.5.0",
"jest-environment-jsdom-fifteen": "^1.0.2",
"jest-github-reporter": "^1.1.1",
+ "jest-junit": "^16.0.0",
"lint-staged": "^13.2.1",
"rimraf": "^5.0.0",
"size-limit": "^8.1.2",
diff --git a/yarn.lock b/yarn.lock
index a41ed19f..4fd93f51 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -6293,6 +6293,16 @@ jest-haste-map@^29.7.0:
optionalDependencies:
fsevents "^2.3.2"
+jest-junit@^16.0.0:
+ version "16.0.0"
+ resolved "https://registry.yarnpkg.com/jest-junit/-/jest-junit-16.0.0.tgz#d838e8c561cf9fdd7eb54f63020777eee4136785"
+ integrity sha512-A94mmw6NfJab4Fg/BlvVOUXzXgF0XIH6EmTgJ5NDPp4xoKq0Kr7sErb+4Xs9nZvu58pJojz5RFGpqnZYJTrRfQ==
+ dependencies:
+ mkdirp "^1.0.4"
+ strip-ansi "^6.0.1"
+ uuid "^8.3.2"
+ xml "^1.0.1"
+
jest-leak-detector@^29.7.0:
version "29.7.0"
resolved "https://registry.npmjs.org/jest-leak-detector/-/jest-leak-detector-29.7.0.tgz#5b7ec0dadfdfec0ca383dc9aa016d36b5ea4c728"
@@ -7340,6 +7350,11 @@ mkdirp@^0.5.1:
dependencies:
minimist "^1.2.6"
+mkdirp@^1.0.4:
+ version "1.0.4"
+ resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e"
+ integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==
+
modify-values@^1.0.0:
version "1.0.1"
resolved "https://registry.npmjs.org/modify-values/-/modify-values-1.0.1.tgz#b3939fa605546474e3e3e3c63d64bd43b4ee6022"
@@ -9684,6 +9699,11 @@ uuid@^3.3.2:
resolved "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee"
integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==
+uuid@^8.3.2:
+ version "8.3.2"
+ resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
+ integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==
+
v8-to-istanbul@^9.0.1:
version "9.3.0"
resolved "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.3.0.tgz#b9572abfa62bd556c16d75fdebc1a411d5ff3175"
@@ -10057,6 +10077,11 @@ xml-name-validator@^4.0.0:
resolved "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-4.0.0.tgz#79a006e2e63149a8600f15430f0a4725d1524835"
integrity sha512-ICP2e+jsHvAj2E2lIHxa5tjXRlKDJo4IdvPvCXbXQGdzSfmSpNVyIKMvoZHjDY9DP0zV17iI85o90vRFXNccRw==
+xml@^1.0.1:
+ version "1.0.1"
+ resolved "https://registry.yarnpkg.com/xml/-/xml-1.0.1.tgz#78ba72020029c5bc87b8a81a3cfcd74b4a2fc1e5"
+ integrity sha512-huCv9IH9Tcf95zuYCsQraZtWnJvBtLVE0QHMOs8bWyZAFZNDcYjsPq1nEx8jKA9y+Beo9v+7OBPRisQTjinQMw==
+
xmlchars@^2.1.1, xmlchars@^2.2.0:
version "2.2.0"
resolved "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz#060fe1bcb7f9c76fe2a17db86a9bc3ab894210cb"
From 1df92d700466ccee2dcd85020c2c77f39e76083c Mon Sep 17 00:00:00 2001
From: aelf-lxy
Date: Tue, 13 Aug 2024 16:37:27 +0800
Subject: [PATCH 2/4] feat: test badge
---
.github/workflows/test-badge.yml | 98 ++++++-
README.md | 10 +-
jest-report.xml | 479 +++++++++++++++++++++++++++++++
3 files changed, 577 insertions(+), 10 deletions(-)
create mode 100644 jest-report.xml
diff --git a/.github/workflows/test-badge.yml b/.github/workflows/test-badge.yml
index 65c9cd94..412c07e3 100644
--- a/.github/workflows/test-badge.yml
+++ b/.github/workflows/test-badge.yml
@@ -6,15 +6,103 @@ permissions:
on:
push:
branches:
+ - dev
- master
- feature/test-chain-util
+env:
+ BRANCH_NAME: 'feature/badge-json'
+
jobs:
- build-and-test:
+ test:
+ name: Generate Test Badge
runs-on: ubuntu-latest
+
steps:
- - name: Run frontend ci action
- uses: AElfProject/frontend-ci-action@v0.0.1
+ - uses: actions/checkout@v2
+ - uses: actions/setup-node@v2
+ with:
+ node-version: 20
+ cache: yarn
+ - run: yarn install
+ - run: yarn run test:browser
+ - name: Install xmlstarlet
+ run: |
+ sudo apt-get update
+ sudo apt-get install -y xmlstarlet
+
+ - name: Extract test counts
+ run: |
+ echo "TESTS=$(xmlstarlet sel -t -v "testsuites/@tests" "jest-report.xml")" >> $GITHUB_ENV
+ echo "FAILURES=$(xmlstarlet sel -t -v "testsuites/@failures" "jest-report.xml")" >> $GITHUB_ENV
+ echo "ERRORS=$(xmlstarlet sel -t -v "testsuites/@errors" "jest-report.xml")" >> $GITHUB_ENV
+
+ - name: Set file name
+ run: echo "FILENAME=$(echo ${GITHUB_REF#refs/heads/} | tr '/' '-')-test-results.json" >> $GITHUB_ENV
+
+ - name: Prepare Content
+ uses: actions/github-script@v5
+ with:
+ github-token: ${{ secrets.COMMIT_TOKEN }}
+ script: |
+ const fs = require('fs');
+ const tests = "${{ env.TESTS }}";
+ const failures = "${{ env.FAILURES }}";
+ const errors = "${{ env.ERRORS }}";
+ const success = tests - failures;
+ const color = errors > 0 ? "red" : (failures > 0 ? "green" : "brightgreen");
+ const content = `{"schemaVersion":1,"label":"tests","message":"${tests} tests, ${success} success","color":"${color}"}`;
+
+ fs.writeFileSync("${{ env.FILENAME }}", content);
+
+ - name: Check if file exists
+ uses: actions/github-script@v5
+ with:
+ github-token: ${{ secrets.GITHUB_TOKEN }}
+ script: |
+ let fileExists = false;
+ try {
+ const { data } = await github.rest.repos.getContent({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ path: "${{ env.FILENAME }}",
+ ref: "${{ env.BRANCH_NAME }}",
+ });
+ fileExists = !!data;
+ } catch (error) {
+ if (error.status !== 404) {
+ throw error;
+ }
+ }
+ core.exportVariable('FILE_EXISTS', fileExists);
+
+ - name: Create or update file
+ uses: actions/github-script@v5
with:
- commit-token: ${{ secrets.COMMIT_TOKEN }}
- branch-name: "feature/badge-json"
+ github-token: ${{ secrets.COMMIT_TOKEN }}
+ script: |
+ const fs = require('fs');
+ const path = require('path');
+ const filePath = path.join(process.env.GITHUB_WORKSPACE, "${{ env.FILENAME }}");
+ const fileContent = fs.readFileSync(filePath, 'utf8');
+
+ const params = {
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ path: "${{ env.FILENAME }}",
+ message: `Update ${{ env.FILENAME }}`,
+ content: Buffer.from(fileContent).toString('base64'),
+ branch: "${{ env.BRANCH_NAME }}"
+ };
+
+ if (${{ env.FILE_EXISTS }}) {
+ const { data } = await github.rest.repos.getContent({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ path: "${{ env.FILENAME }}",
+ ref: "${{ env.BRANCH_NAME }}"
+ });
+ params.sha = data.sha;
+ }
+
+ await github.rest.repos.createOrUpdateFileContents(params);
diff --git a/README.md b/README.md
index ff066eb1..eb814bfc 100644
--- a/README.md
+++ b/README.md
@@ -6,18 +6,18 @@
-
-
+
+
| Branch | Tests | Coverage |
|--------------|-----------------|----------------|
-| `feature/test-chain-util` |  |  |
+| `feature/test-chain-util` |  |  |
-| Statements | Branches | Functions | Lines |
+
## 1. Introduction
diff --git a/jest-report.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
+
\ No newline at end of file
From fb0c40adc611b67dc7336070df1c3494119c2f74 Mon Sep 17 00:00:00 2001
From: aelf-lxy
Date: Tue, 13 Aug 2024 16:48:07 +0800
Subject: [PATCH 3/4] feat: test-badge
---
README.md | 6 +-
jest-report.xml | 352 ++++++++++++++++++++++++------------------------
2 files changed, 179 insertions(+), 179 deletions(-)
diff --git a/README.md b/README.md
index eb814bfc..8b3cafff 100644
--- a/README.md
+++ b/README.md
@@ -6,14 +6,14 @@
-
-
+
+
| Branch | Tests | Coverage |
|--------------|-----------------|----------------|
-| `feature/test-chain-util` |  |  |
+| `feature/test-chain-util` |  |  |