-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2077768
commit 455e884
Showing
14 changed files
with
1,946 additions
and
2,152 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,44 @@ | ||
name: (main) coverage badge | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
coverage-badge: | ||
strategy: | ||
matrix: | ||
os: | ||
- ubuntu-latest | ||
node: | ||
- 18.14.2 | ||
pnpm: | ||
- 7 | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- name: checkout repository | ||
uses: actions/checkout@v4 | ||
- name: setup node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node }} | ||
|
||
- name: 📥 Install Dependencies | ||
run: yarn --frozen-lockfile | ||
|
||
- name: run coverage | ||
run: yarn test:coverage | ||
|
||
- name: generate badges | ||
run: yarn generate-badges | ||
|
||
- name: push coverage artifacts to another branch | ||
uses: peaceiris/actions-gh-pages@v3 | ||
if: github.ref == 'refs/heads/main' | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
publish_dir: ./coverage | ||
publish_branch: coverage | ||
allow_empty_commit: true |
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 was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
{ | ||
"folders": [ | ||
{ | ||
"name": "gh-pages", | ||
"path": "./", | ||
}, | ||
{ | ||
"name": "website", | ||
"path": "website", | ||
}, | ||
], | ||
"extensions": { | ||
"recommendations": [ | ||
"dbaeumer.vscode-eslint" | ||
], | ||
}, | ||
"settings": { | ||
"editor.formatOnSave": true, | ||
"editor.defaultFormatter": "dbaeumer.vscode-eslint", | ||
"editor.codeActionsOnSave": { | ||
"source.fixAll.eslint": "explicit", | ||
"source.organizeImports": "never", | ||
"source.removeUnusedImports": "always", | ||
}, | ||
"files.associations": { | ||
"*.css": "tailwindcss", | ||
}, | ||
"tailwindCSS.experimental.classRegex": [ | ||
[ | ||
"cva\\(([^)]*)\\)", | ||
"[\"'`]([^\"'`]*).*?[\"'`]" | ||
], | ||
[ | ||
"cx\\(([^)]*)\\)", | ||
"(?:'|\"|`)([^']*)(?:'|\"|`)" | ||
] | ||
], | ||
// Disable vscode formatting for js,jsx,ts,tsx files | ||
// to allow dbaeumer.vscode-eslint to format them | ||
"[javascript]": { | ||
"editor.formatOnSave": true, | ||
}, | ||
"[typescript]": { | ||
"editor.formatOnSave": true, | ||
}, | ||
"[html]": { | ||
// Avoid onSave to format evolve/templates/**/*.html | ||
"editor.formatOnSave": false, | ||
}, | ||
// https://github.com/Microsoft/vscode-eslint#mono-repository-setup | ||
"eslint.workingDirectories": [ | ||
"./", | ||
"./website", | ||
], | ||
"typescript.tsdk": "root/node_modules/typescript/lib", | ||
"[jsonc]": { | ||
"editor.formatOnSave": false | ||
}, | ||
"[json]": { | ||
"editor.formatOnSave": false | ||
}, | ||
"i18n-ally.localesPaths": [ | ||
"i18n" | ||
], | ||
}, | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import cheerio from 'cheerio'; | ||
import fs from 'fs'; | ||
import https from 'https'; | ||
|
||
const coverageFile = './coverage/index.html'; | ||
const badgesDir = './coverage/badges'; | ||
|
||
// Read the coverage HTML file. | ||
fs.readFile(coverageFile, 'utf-8', (err, data) => { | ||
if (err) { | ||
console.error(`Error reading coverage file: ${err}`); | ||
process.exit(1); | ||
} | ||
|
||
// Parse the HTML using Cheerio. | ||
const $ = cheerio.load(data); | ||
|
||
// Construct the shields.io URL for each badge. | ||
const statementsBadgeUrl = generateUrl('statements', extractPercentage($, 1)); | ||
const branchesBadgeUrl = generateUrl('branches', extractPercentage($, 2)); | ||
const functionsBadgeUrl = generateUrl('functions', extractPercentage($, 3)); | ||
const linesBadgeUrl = generateUrl('lines', extractPercentage($, 4)); | ||
|
||
// Create the badges directory if it does not exist. | ||
if (!fs.existsSync(badgesDir)) { | ||
fs.mkdirSync(badgesDir); | ||
} | ||
|
||
// Download each badge and save it to the badges directory. | ||
downloadBadge(statementsBadgeUrl, `${badgesDir}/statements.svg`); | ||
downloadBadge(branchesBadgeUrl, `${badgesDir}/branches.svg`); | ||
downloadBadge(functionsBadgeUrl, `${badgesDir}/functions.svg`); | ||
downloadBadge(linesBadgeUrl, `${badgesDir}/lines.svg`); | ||
|
||
console.log('Code coverage badges created successfully.'); | ||
}); | ||
|
||
/** | ||
* Generate a shields.io URL for a badge. | ||
* | ||
* Change the color of the badge based on the percentage. | ||
* | ||
* @param {string} text The text to display on the badge. | ||
* @param {number} percentage The percentage to display on the badge. | ||
* @returns {string} The shields.io URL. | ||
*/ | ||
const generateUrl = (text, percentage) => { | ||
let color = 'brightgreen'; | ||
if (percentage < 70) { | ||
color = 'red'; | ||
} else if (percentage < 80) { | ||
color = 'yellow'; | ||
} else if (percentage < 90) { | ||
color = 'orange'; | ||
} | ||
return `https://img.shields.io/badge/coverage%3A${text}-${percentage}%25-${color}.svg`; | ||
}; | ||
|
||
/** | ||
* Extract the code coverage percentage from the HTML. | ||
* @param {Cheerio} $ The Cheerio object. | ||
* @param {number} index The index of the element to extract. | ||
*/ | ||
const extractPercentage = ($, index) => { | ||
const text = $(`.pad1y:nth-child(${index}) span.strong`) ?? '0'; | ||
const percentage = text.text().trim().replace('%', ''); | ||
return parseFloat(percentage); | ||
}; | ||
|
||
/** | ||
* Download a badge from shields.io. | ||
* @param {string} url The shields.io URL. | ||
* @param {string} filename The filename to save the badge to. | ||
*/ | ||
const downloadBadge = (url, filename) => { | ||
https.get(url, (res) => { | ||
if (res.statusCode !== 200) { | ||
console.error(`Error downloading badge: ${res.statusMessage}`); | ||
return; | ||
} | ||
|
||
const file = fs.createWriteStream(filename); | ||
res.pipe(file); | ||
file.on('finish', () => { | ||
file.close(); | ||
}); | ||
}); | ||
}; |
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import { strCamelCase } from '@/str/str-camel-case.js'; | ||
|
||
describe('should test the main file', () => { | ||
it('should test the main file', () => { | ||
expect(1).toBe(1); | ||
expect(strCamelCase('My Name')).toBe('myName'); | ||
}); | ||
}); |
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
Oops, something went wrong.