This repository has been archived by the owner on Dec 11, 2023. It is now read-only.
-
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.
* ESLint GitHub Actions * Fix Directory Name workflow to workflows * Fix yarn does not install dependencies * Fix filter_mode * Test for ESLint CI * Reporter pr-review to pr-check * Fix permission * Revert "Test for ESLint CI" This reverts commit daf968c. * Create test.yml * Create bundle-size-diff tools * Remove name * Fix over-jobs variable * Fix Comment Settings * Create Auto Approve Actions * Fix Conditions
- Loading branch information
Showing
9 changed files
with
404 additions
and
8 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
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,11 @@ | ||
name: auto-approve | ||
on: [pull_request] | ||
|
||
jobs: | ||
auto-approve: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
pull-requests: write | ||
if: github.event.pull_request.user.login == 'AsPulse' | ||
steps: | ||
- uses: hmarr/auto-approve-action@v3 |
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,79 @@ | ||
name: bundle-size | ||
on: [pull_request] | ||
|
||
jobs: | ||
build_head: | ||
runs-on: [ubuntu-latest] | ||
permissions: | ||
contents: read | ||
outputs: | ||
result: ${{ steps.export.outputs.HEAD_RESULT }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18 | ||
cache: 'yarn' | ||
- name: Install Dependencies | ||
run: yarn install --immutable | ||
- name: Build | ||
run: yarn build | ||
- name: Export Size Info | ||
id: export | ||
run: | | ||
echo "HEAD_RESULT=$(yarn ts-node ./misc/bundle-size-diff.ts inspect)" >> $GITHUB_OUTPUT | ||
build_base: | ||
runs-on: [ubuntu-latest] | ||
permissions: | ||
contents: read | ||
outputs: | ||
result: ${{ steps.export.outputs.BASE_RESULT }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ github.base_re }} | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18 | ||
cache: 'yarn' | ||
- name: Install Dependencies | ||
run: yarn install --immutable | ||
- name: Build | ||
run: yarn build | ||
- name: Export Size Info | ||
id: export | ||
run: | | ||
echo "BASE_RESULT=$(yarn ts-node ./misc/bundle-size-diff.ts inspect)" >> $GITHUB_OUTPUT | ||
compare: | ||
runs-on: [ubuntu-latest] | ||
needs: [build_base, build_head] | ||
permissions: | ||
contents: read | ||
pull-requests: write | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ github.base_re }} | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18 | ||
cache: 'yarn' | ||
- name: Install Dependencies | ||
run: yarn install --immutable | ||
- name: Export Markdown | ||
env: | ||
HEAD_RESULT: ${{ needs.build_head.outputs.result }} | ||
BASE_RESULT: ${{ needs.build_base.outputs.result }} | ||
run: yarn ts-node ./misc/bundle-size-diff.ts diff $HEAD_RESULT $BASE_RESULT | ||
- name: Post Review Comment | ||
uses: mshick/add-pr-comment@v2 | ||
with: | ||
message-path: 'bundle-size/result.md' |
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,26 @@ | ||
name: lint | ||
on: [pull_request] | ||
|
||
jobs: | ||
eslint: | ||
runs-on: [ubuntu-latest] | ||
permissions: | ||
contents: read | ||
pull-requests: write | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18 | ||
cache: 'yarn' | ||
- name: Install Dependencies | ||
run: yarn install --immutable | ||
- name: Run ESLint | ||
uses: reviewdog/action-eslint@v1 | ||
with: | ||
github_token: ${{ secrets.github_token }} | ||
reporter: github-pr-review | ||
filter_mode: diff_context | ||
fail_on_error: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: test | ||
on: [pull_request] | ||
|
||
jobs: | ||
jest: | ||
runs-on: [ubuntu-latest] | ||
permissions: | ||
contents: read | ||
pull-requests: write | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18 | ||
cache: 'yarn' | ||
- name: Install Dependencies | ||
run: yarn install --immutable | ||
- name: Run Jest | ||
run: yarn test |
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,119 @@ | ||
/* eslint-disable no-console */ | ||
import { rm, mkdir, readFile, writeFile } from 'fs/promises'; | ||
|
||
interface Diff { | ||
head: number; | ||
base: number; | ||
diff: number; | ||
} | ||
|
||
interface DiffResult { | ||
cjs: Diff; | ||
esm: Diff; | ||
package: Diff; | ||
} | ||
|
||
function getDiff(args: string[]): DiffResult { | ||
|
||
const size = { head: args[3], base: args[4] }; | ||
if (size.head === undefined || size.base === undefined) { | ||
console.error('Usage: bundle-size-diff diff <head> <base>'); | ||
process.exit(1); | ||
} | ||
|
||
const [ headCjs, headEsm, headPackage ] = size.head.split(':').map(v => parseInt(v, 10)); | ||
const [ baseCjs, baseEsm, basePackage ] = size.base.split(':').map(v => parseInt(v, 10)); | ||
if ( | ||
headCjs === undefined || headEsm === undefined || headPackage === undefined || | ||
baseCjs === undefined || baseEsm === undefined || basePackage === undefined | ||
) { | ||
console.error('Error: invalid size format.'); | ||
process.exit(1); | ||
} | ||
|
||
return { | ||
cjs: { head: headCjs, base: baseCjs, diff: headCjs - baseCjs }, | ||
esm: { head: headEsm, base: baseEsm, diff: headEsm - baseEsm }, | ||
package: { head: headPackage, base: basePackage, diff: headPackage - basePackage }, | ||
}; | ||
|
||
} | ||
|
||
async function exportToMarkdown(data: DiffResult): Promise<void> { | ||
const result = [ | ||
'## Bundle Size Summary', | ||
'||Base branch|HEAD branch|Diff|', | ||
'|--:|:--:|:--:|:--:|', | ||
[ | ||
'', | ||
'CommonJS', | ||
formatSize(data.cjs.base), formatSize(data.cjs.head), | ||
`**${getSymbol(data.cjs.diff)} ${formatSize(Math.abs(data.cjs.diff))}**`, | ||
'', | ||
].join('|'), | ||
[ | ||
'', | ||
'ES Module', | ||
formatSize(data.esm.base), formatSize(data.esm.head), | ||
`**${getSymbol(data.esm.diff)} ${formatSize(Math.abs(data.esm.diff))}**`, | ||
'', | ||
].join('|'), | ||
[ | ||
'', | ||
'Package', | ||
formatSize(data.package.base), formatSize(data.package.head), | ||
`**${getSymbol(data.package.diff)} ${formatSize(Math.abs(data.package.diff))}**`, | ||
'', | ||
].join('|'), | ||
].join('\n'); | ||
await rm('./bundle-size', { recursive: true, force: true }); | ||
await mkdir('./bundle-size', { recursive: true }); | ||
await writeFile('./bundle-size/result.md', result); | ||
console.log('Result is exported to: bundle-size/result.md'); | ||
return; | ||
} | ||
|
||
export function getSymbol(diff: number): string { | ||
return diff === 0 ? '+/-' : diff < 0 ? '-' : '+'; | ||
} | ||
export function formatSize(byte: number): string { | ||
return `${Math.round(byte / 10) / 100} kB`; | ||
} | ||
|
||
async function main(): Promise<void> { | ||
const args = process.argv; | ||
switch (args[2]) { | ||
case 'inspect': | ||
try { | ||
const cjs = await readFile('./dist/cjs/index.js'); | ||
const esm = await readFile('./dist/esm/index.js'); | ||
const cjsDts = await readFile('./dist/cjs/index.d.ts'); | ||
const esmDts = await readFile('./dist/esm/index.d.ts'); | ||
const packageJson = await readFile('./package.json'); | ||
const license = await readFile('./LICENSE'); | ||
const readme = await readFile('./README.md'); | ||
console.log([ | ||
cjs.byteLength, | ||
esm.byteLength, | ||
[ cjs, esm, cjsDts, esmDts, packageJson, license, readme ] | ||
.map(v => v.byteLength) | ||
.reduce((a, b) => a + b, 0), | ||
].join(':')); | ||
} catch { | ||
console.error('Error: some of build artifacts not found.'); | ||
process.exit(1); | ||
} | ||
break; | ||
|
||
case 'diff': | ||
await exportToMarkdown( getDiff(args) ); | ||
break; | ||
|
||
default: | ||
console.error('Usage: bundle-size-diff [inspect|diff]'); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
|
||
void main(); |
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.