mirror of
https://github.com/honojs/hono.git
synced 2024-11-21 18:18:57 +01:00
ci: Type check perf (#3406)
* chore: add scripts to monitor type check performance * chore: add jobs for type-check-perf-monitoring * chore: rm a comment * refactor: mv type-check-perf perf-measures/type-check * rm .eslintrc.cjs * chore: ignore *result.txt
This commit is contained in:
parent
dfbd717263
commit
66df4e1296
51
.github/workflows/ci.yml
vendored
51
.github/workflows/ci.yml
vendored
@ -177,3 +177,54 @@ jobs:
|
||||
with:
|
||||
name: coverage-lambda-edge
|
||||
path: coverage/
|
||||
|
||||
perf-measures-type-check-on-pr:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: 'read'
|
||||
pull-requests: 'write'
|
||||
if: github.event_name == 'pull_request'
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: oven-sh/setup-bun@v1
|
||||
- run: bun install
|
||||
- uses: actions/cache/restore@v4
|
||||
with:
|
||||
path: perf-measures/type-check/previous-result.txt
|
||||
restore-keys: |
|
||||
type-check-perf-previous-result-
|
||||
key: type-check-perf-previous-result-
|
||||
- run: bun scripts/generate-app.ts
|
||||
working-directory: perf-measures/type-check
|
||||
- run: bun tsc -p tsconfig.build.json --diagnostics > result.txt
|
||||
working-directory: perf-measures/type-check
|
||||
- run: |
|
||||
{
|
||||
echo 'COMPARISON<<EOF'
|
||||
bun scripts/process-results.ts
|
||||
echo 'EOF'
|
||||
} >> "$GITHUB_ENV"
|
||||
working-directory: perf-measures/type-check
|
||||
- run: echo "$COMPARISON"
|
||||
# remove the comment out after we make sure that caching is working
|
||||
# - uses: thollander/actions-comment-pull-request@v2
|
||||
# with:
|
||||
# comment_tag: perf-measures/type-check
|
||||
# message: ${{ env.COMPARISON }}
|
||||
|
||||
|
||||
perf-measures-type-check-on-main:
|
||||
runs-on: ubuntu-latest
|
||||
if: github.ref == 'refs/heads/main'
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: oven-sh/setup-bun@v1
|
||||
- run: bun install
|
||||
- run: bun scripts/generate-app.ts
|
||||
working-directory: perf-measures/type-check
|
||||
- run: bun tsc -p tsconfig.build.json --diagnostics > previous-result.txt
|
||||
working-directory: perf-measures/type-check
|
||||
- uses: actions/cache/save@v4
|
||||
with:
|
||||
path: perf-measures/type-check/previous-result.txt
|
||||
key: type-check-perf-previous-result-${{ github.sha }}
|
||||
|
13
perf-measures/tsconfig.json
Normal file
13
perf-measures/tsconfig.json
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"module": "esnext",
|
||||
"noEmit": true,
|
||||
"rootDir": "..",
|
||||
"strict": true
|
||||
},
|
||||
"include": [
|
||||
"**/*.ts",
|
||||
"**/*.tsx"
|
||||
]
|
||||
}
|
4
perf-measures/type-check/.gitignore
vendored
Normal file
4
perf-measures/type-check/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
generated
|
||||
!generated/.gitkeep
|
||||
trace
|
||||
*result.txt
|
4
perf-measures/type-check/client.ts
Normal file
4
perf-measures/type-check/client.ts
Normal file
@ -0,0 +1,4 @@
|
||||
import type { app } from './generated/app'
|
||||
import { hc } from '../../src/client'
|
||||
|
||||
const client = hc<typeof app>('/')
|
0
perf-measures/type-check/generated/.gitkeep
Normal file
0
perf-measures/type-check/generated/.gitkeep
Normal file
25
perf-measures/type-check/scripts/generate-app.ts
Normal file
25
perf-measures/type-check/scripts/generate-app.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { writeFile } from 'node:fs'
|
||||
import * as path from 'node:path'
|
||||
|
||||
const count = 200
|
||||
|
||||
const generateRoutes = (count: number) => {
|
||||
let routes = `import { Hono } from '../../../src'
|
||||
export const app = new Hono()`
|
||||
for (let i = 1; i <= count; i++) {
|
||||
routes += `
|
||||
.get('/route${i}/:id', (c) => {
|
||||
return c.json({
|
||||
ok: true
|
||||
})
|
||||
})`
|
||||
}
|
||||
return routes
|
||||
}
|
||||
|
||||
const routes = generateRoutes(count)
|
||||
|
||||
writeFile(path.join(import.meta.dirname, '../generated/app.ts'), routes, (err) => {
|
||||
if (err) { throw err }
|
||||
console.log(`${count} routes have been written to app.ts`)
|
||||
})
|
18
perf-measures/type-check/scripts/process-results.ts
Normal file
18
perf-measures/type-check/scripts/process-results.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import * as fs from 'node:fs/promises'
|
||||
|
||||
async function main() {
|
||||
const currentResult = (await fs.readFile('./result.txt')).toString().split('\n')
|
||||
const previousResult = await fs.readFile('./previous-result.txt')
|
||||
.then((data) => data.toString().split('\n'))
|
||||
.catch(() => null)
|
||||
const table = ['|| Current | Previous |', '|---|---|---|']
|
||||
for (const [i, line] of currentResult.entries()) {
|
||||
if (line === '') {continue}
|
||||
const [name, value] = line.split(':')
|
||||
const mainValue = previousResult?.[i]?.split(':')?.[1]
|
||||
table.push(`| ${name?.trim()} | ${value?.trim()} | ${mainValue ? mainValue.trim() : 'N/A'} |`)
|
||||
}
|
||||
console.log(table.join('\n'))
|
||||
}
|
||||
|
||||
main()
|
4
perf-measures/type-check/tsconfig.build.json
Normal file
4
perf-measures/type-check/tsconfig.build.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"include": ["client.ts"]
|
||||
}
|
@ -22,6 +22,7 @@ export default defineConfig({
|
||||
'runtime-tests',
|
||||
'build.ts',
|
||||
'src/test-utils',
|
||||
'perf-measures',
|
||||
|
||||
// types are compile-time only, so their coverage cannot be measured
|
||||
'src/**/types.ts',
|
||||
|
Loading…
Reference in New Issue
Block a user