Skip to content

Commit 3478e3b

Browse files
authored
Merge pull request #77 from AElfProject/feature/git-action
Feature/git action
2 parents 6fdeaa0 + f8f9c0d commit 3478e3b

File tree

7 files changed

+126
-4
lines changed

7 files changed

+126
-4
lines changed

.github/workflows/test-badge.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: Test Badge
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
test:
10+
name: Coverage Diff
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v2
15+
- uses: actions/setup-node@v2
16+
with:
17+
node-version: 20
18+
cache: yarn
19+
- run: yarn install
20+
- run: yarn run test
21+
- name: Install xmlstarlet
22+
run: |
23+
sudo apt-get update
24+
sudo apt-get install -y xmlstarlet
25+
26+
- name: Extract Test Counts
27+
id: test_counts
28+
run: |
29+
tests=$(xmlstarlet sel -t -v "testsuites/@tests" "jest-report.xml")
30+
failures=$(xmlstarlet sel -t -v "testsuites/@failures" "jest-report.xml")
31+
errors=$(xmlstarlet sel -t -v "testsuites/@errors" "jest-report.xml")
32+
echo "TESTS=$tests" >> $GITHUB_ENV
33+
echo "FAILURES=$failures" >> $GITHUB_ENV
34+
echo "ERRORS=$errors" >> $GITHUB_ENV
35+
36+
- name: Get branch name
37+
run: echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
38+
39+
- name: Prepare Content
40+
uses: actions/github-script@v5
41+
with:
42+
github-token: ${{ secrets.COMMIT_TOKEN }}
43+
script: |
44+
const fs = require('fs');
45+
const tests = "${{ env.TESTS }}";
46+
const failures = "${{ env.FAILURES }}";
47+
const errors = "${{ env.ERRORS }}";
48+
let branchName = "${{ env.BRANCH_NAME }}";
49+
branchName = branchName.replace(/\//g, '-');
50+
const filename = `${branchName}-test-results.json`;
51+
const color = errors > 0 ? "red" : (failures > 0 ? "green" : "brightgreen");
52+
const content = `{"schemaVersion":1,"label":"tests","message":"${tests} tests, ${failures} failures, ${errors} errors","color":"${color}"}`;
53+
54+
fs.writeFileSync(filename, content);
55+
56+
- name: Commit and push
57+
uses: actions/github-script@v5
58+
with:
59+
github-token: ${{ secrets.COMMIT_TOKEN }}
60+
script: |
61+
const fs = require('fs');
62+
const path = require('path');
63+
let branchName = "${{ env.BRANCH_NAME }}";
64+
branchName = branchName.replace(/\//g, '-');
65+
const filename = `${branchName}-test-results.json`;
66+
const filePath = path.join(process.env.GITHUB_WORKSPACE, filename);
67+
const fileContent = fs.readFileSync(filePath, 'utf8');
68+
69+
const { data: { sha } } = await github.rest.repos.getContent({
70+
owner: context.repo.owner,
71+
repo: context.repo.repo,
72+
path: filename,
73+
ref: 'feature/use-github-actions'
74+
});
75+
76+
await github.rest.repos.createOrUpdateFileContents({
77+
owner: context.repo.owner,
78+
repo: context.repo.repo,
79+
path: filename,
80+
message: `Update ${filename}`,
81+
content: Buffer.from(fileContent).toString('base64'),
82+
sha,
83+
branch: 'feature/use-github-actions'
84+
});

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ jobs:
2323
uses: greatwizard/coverage-diff-action@v1
2424
with:
2525
github-token: ${{ secrets.GITHUB_TOKEN }}
26+

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,4 @@ $RECYCLE.BIN/
153153
.idea/
154154

155155
package-lock.json
156+
jest-report.xml
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"schemaVersion":1,"label":"tests","message":"186 tests, 0 failures, 0 errors","color":"brightgreen"}

jest.config.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,16 @@ export default {
9292
// projects: null,
9393

9494
// Use this configuration option to add custom reporters to Jest
95-
// reporters: undefined,
95+
reporters: [
96+
'default',
97+
[
98+
'jest-junit',
99+
{
100+
outputDirectory: '.',
101+
outputName: 'jest-report.xml'
102+
}
103+
]
104+
],
96105

97106
// Automatically reset mock state between every test
98107
// resetMocks: false,

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aelf-command",
3-
"version": "0.1.47-beta.6",
3+
"version": "0.1.47-beta.7",
44
"description": "A CLI tools for AElf",
55
"main": "src/index.js",
66
"type": "module",
@@ -92,11 +92,12 @@
9292
"git-cz": "^4.9.0",
9393
"husky": "^9.0.11",
9494
"jest": "^29.7.0",
95+
"jest-junit": "^16.0.0",
9596
"lint-staged": "^15.2.5",
9697
"prettier": "^3.3.2",
98+
"socket.io-client": "^4.7.5",
9799
"standard-version": "^9.5.0",
98-
"typescript": "^5.5.2",
99-
"socket.io-client": "^4.7.5"
100+
"typescript": "^5.5.2"
100101
},
101102
"keywords": [
102103
"AElf",

yarn.lock

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5029,6 +5029,16 @@ jest-haste-map@^29.7.0:
50295029
optionalDependencies:
50305030
fsevents "^2.3.2"
50315031

5032+
jest-junit@^16.0.0:
5033+
version "16.0.0"
5034+
resolved "https://registry.yarnpkg.com/jest-junit/-/jest-junit-16.0.0.tgz#d838e8c561cf9fdd7eb54f63020777eee4136785"
5035+
integrity sha512-A94mmw6NfJab4Fg/BlvVOUXzXgF0XIH6EmTgJ5NDPp4xoKq0Kr7sErb+4Xs9nZvu58pJojz5RFGpqnZYJTrRfQ==
5036+
dependencies:
5037+
mkdirp "^1.0.4"
5038+
strip-ansi "^6.0.1"
5039+
uuid "^8.3.2"
5040+
xml "^1.0.1"
5041+
50325042
jest-leak-detector@^29.7.0:
50335043
version "29.7.0"
50345044
resolved "https://registry.npmjs.org/jest-leak-detector/-/jest-leak-detector-29.7.0.tgz#5b7ec0dadfdfec0ca383dc9aa016d36b5ea4c728"
@@ -5750,6 +5760,11 @@ minimist@^1.2.0, minimist@^1.2.5, minimist@^1.2.6, minimist@^1.2.8:
57505760
resolved "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c"
57515761
integrity sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==
57525762

5763+
mkdirp@^1.0.4:
5764+
version "1.0.4"
5765+
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e"
5766+
integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==
5767+
57535768
mkdirp@^3.0.1:
57545769
version "3.0.1"
57555770
resolved "https://registry.npmjs.org/mkdirp/-/mkdirp-3.0.1.tgz#e44e4c5607fb279c168241713cc6e0fea9adcb50"
@@ -7404,6 +7419,11 @@ util@^0.12.5:
74047419
is-typed-array "^1.1.3"
74057420
which-typed-array "^1.1.2"
74067421

7422+
uuid@^8.3.2:
7423+
version "8.3.2"
7424+
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
7425+
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==
7426+
74077427
uuid@^9.0.1:
74087428
version "9.0.1"
74097429
resolved "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz#e188d4c8853cc722220392c424cd637f32293f30"
@@ -7567,6 +7587,11 @@ xdg-basedir@^5.0.1, xdg-basedir@^5.1.0:
75677587
resolved "https://registry.npmjs.org/xdg-basedir/-/xdg-basedir-5.1.0.tgz#1efba19425e73be1bc6f2a6ceb52a3d2c884c0c9"
75687588
integrity sha512-GCPAHLvrIH13+c0SuacwvRYj2SxJXQ4kaVTT5xgL3kPrz56XxkF21IGhjSE1+W0aw7gpBWRGXLCPnPby6lSpmQ==
75697589

7590+
xml@^1.0.1:
7591+
version "1.0.1"
7592+
resolved "https://registry.yarnpkg.com/xml/-/xml-1.0.1.tgz#78ba72020029c5bc87b8a81a3cfcd74b4a2fc1e5"
7593+
integrity sha512-huCv9IH9Tcf95zuYCsQraZtWnJvBtLVE0QHMOs8bWyZAFZNDcYjsPq1nEx8jKA9y+Beo9v+7OBPRisQTjinQMw==
7594+
75707595
xmlhttprequest-ssl@~2.0.0:
75717596
version "2.0.0"
75727597
resolved "https://registry.npmjs.org/xmlhttprequest-ssl/-/xmlhttprequest-ssl-2.0.0.tgz#91360c86b914e67f44dce769180027c0da618c67"

0 commit comments

Comments
 (0)