Skip to content

Commit

Permalink
Merge pull request #77 from AElfProject/feature/git-action
Browse files Browse the repository at this point in the history
Feature/git action
  • Loading branch information
hzz780 authored Jul 24, 2024
2 parents 6fdeaa0 + f8f9c0d commit 3478e3b
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 4 deletions.
84 changes: 84 additions & 0 deletions .github/workflows/test-badge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Test Badge

on:
push:
branches:
- master

jobs:
test:
name: Coverage Diff
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 20
cache: yarn
- run: yarn install
- run: yarn run test
- name: Install xmlstarlet
run: |
sudo apt-get update
sudo apt-get install -y xmlstarlet
- name: Extract Test Counts
id: test_counts
run: |
tests=$(xmlstarlet sel -t -v "testsuites/@tests" "jest-report.xml")
failures=$(xmlstarlet sel -t -v "testsuites/@failures" "jest-report.xml")
errors=$(xmlstarlet sel -t -v "testsuites/@errors" "jest-report.xml")
echo "TESTS=$tests" >> $GITHUB_ENV
echo "FAILURES=$failures" >> $GITHUB_ENV
echo "ERRORS=$errors" >> $GITHUB_ENV
- name: Get branch name
run: echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $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 }}";
let branchName = "${{ env.BRANCH_NAME }}";
branchName = branchName.replace(/\//g, '-');
const filename = `${branchName}-test-results.json`;
const color = errors > 0 ? "red" : (failures > 0 ? "green" : "brightgreen");
const content = `{"schemaVersion":1,"label":"tests","message":"${tests} tests, ${failures} failures, ${errors} errors","color":"${color}"}`;
fs.writeFileSync(filename, content);
- name: Commit and push
uses: actions/github-script@v5
with:
github-token: ${{ secrets.COMMIT_TOKEN }}
script: |
const fs = require('fs');
const path = require('path');
let branchName = "${{ env.BRANCH_NAME }}";
branchName = branchName.replace(/\//g, '-');
const filename = `${branchName}-test-results.json`;
const filePath = path.join(process.env.GITHUB_WORKSPACE, filename);
const fileContent = fs.readFileSync(filePath, 'utf8');
const { data: { sha } } = await github.rest.repos.getContent({
owner: context.repo.owner,
repo: context.repo.repo,
path: filename,
ref: 'feature/use-github-actions'
});
await github.rest.repos.createOrUpdateFileContents({
owner: context.repo.owner,
repo: context.repo.repo,
path: filename,
message: `Update ${filename}`,
content: Buffer.from(fileContent).toString('base64'),
sha,
branch: 'feature/use-github-actions'
});
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ jobs:
uses: greatwizard/coverage-diff-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,4 @@ $RECYCLE.BIN/
.idea/

package-lock.json
jest-report.xml
1 change: 1 addition & 0 deletions feature-use-github-actions-test-results.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"schemaVersion":1,"label":"tests","message":"186 tests, 0 failures, 0 errors","color":"brightgreen"}
11 changes: 10 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,16 @@ export default {
// projects: null,

// Use this configuration option to add custom reporters to Jest
// reporters: undefined,
reporters: [
'default',
[
'jest-junit',
{
outputDirectory: '.',
outputName: 'jest-report.xml'
}
]
],

// Automatically reset mock state between every test
// resetMocks: false,
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aelf-command",
"version": "0.1.47-beta.6",
"version": "0.1.47-beta.7",
"description": "A CLI tools for AElf",
"main": "src/index.js",
"type": "module",
Expand Down Expand Up @@ -92,11 +92,12 @@
"git-cz": "^4.9.0",
"husky": "^9.0.11",
"jest": "^29.7.0",
"jest-junit": "^16.0.0",
"lint-staged": "^15.2.5",
"prettier": "^3.3.2",
"socket.io-client": "^4.7.5",
"standard-version": "^9.5.0",
"typescript": "^5.5.2",
"socket.io-client": "^4.7.5"
"typescript": "^5.5.2"
},
"keywords": [
"AElf",
Expand Down
25 changes: 25 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5029,6 +5029,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"
Expand Down Expand Up @@ -5750,6 +5760,11 @@ minimist@^1.2.0, minimist@^1.2.5, minimist@^1.2.6, minimist@^1.2.8:
resolved "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c"
integrity sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==

mkdirp@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e"
integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==

mkdirp@^3.0.1:
version "3.0.1"
resolved "https://registry.npmjs.org/mkdirp/-/mkdirp-3.0.1.tgz#e44e4c5607fb279c168241713cc6e0fea9adcb50"
Expand Down Expand Up @@ -7404,6 +7419,11 @@ util@^0.12.5:
is-typed-array "^1.1.3"
which-typed-array "^1.1.2"

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==

uuid@^9.0.1:
version "9.0.1"
resolved "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz#e188d4c8853cc722220392c424cd637f32293f30"
Expand Down Expand Up @@ -7567,6 +7587,11 @@ xdg-basedir@^5.0.1, xdg-basedir@^5.1.0:
resolved "https://registry.npmjs.org/xdg-basedir/-/xdg-basedir-5.1.0.tgz#1efba19425e73be1bc6f2a6ceb52a3d2c884c0c9"
integrity sha512-GCPAHLvrIH13+c0SuacwvRYj2SxJXQ4kaVTT5xgL3kPrz56XxkF21IGhjSE1+W0aw7gpBWRGXLCPnPby6lSpmQ==

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==

xmlhttprequest-ssl@~2.0.0:
version "2.0.0"
resolved "https://registry.npmjs.org/xmlhttprequest-ssl/-/xmlhttprequest-ssl-2.0.0.tgz#91360c86b914e67f44dce769180027c0da618c67"
Expand Down

0 comments on commit 3478e3b

Please sign in to comment.