-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from AElfProject/feature/git-action
Feature/git action
- Loading branch information
Showing
7 changed files
with
126 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,4 @@ jobs: | |
uses: greatwizard/coverage-diff-action@v1 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,3 +153,4 @@ $RECYCLE.BIN/ | |
.idea/ | ||
|
||
package-lock.json | ||
jest-report.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters