Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Display performance measurement results as custom metrics #3491

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 21 additions & 25 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,26 +184,17 @@ jobs:
- 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
- name: Performance measurement of type check
run: |
bun scripts/generate-app.ts
bun tsc -p tsconfig.build.json --diagnostics | bun scripts/process-results.ts > diagnostics.json
working-directory: perf-measures/type-check
- run: |
{
echo 'COMPARISON<<EOF'
bun scripts/process-results.ts | column -s '|' -t
echo 'EOF'
} >> "$GITHUB_ENV"
working-directory: perf-measures/type-check
- run: echo "$COMPARISON"
name: display comparison

- name: Run octocov
uses: k1LoW/octocov-action@v1
with:
config: perf-measures/type-check/.octocov.perf-measures.yml
env:
OCTOCOV_CUSTOM_METRICS_BENCHMARK: perf-measures/type-check/diagnostics.json

perf-measures-type-check-on-main:
runs-on: ubuntu-latest
Expand All @@ -212,11 +203,16 @@ jobs:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
- run: bun install
- run: bun scripts/generate-app.ts
- name: Performance measurement of type check
run: |
bun scripts/generate-app.ts
bun tsc -p tsconfig.build.json --diagnostics | bun scripts/process-results.ts > diagnostics.json
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
- name: Run octocov (main)
uses: k1LoW/octocov-action@v1
with:
path: perf-measures/type-check/previous-result.txt
key: type-check-perf-previous-result-${{ github.sha }}
config: perf-measures/type-check/.octocov.perf-measures.main.yml
env:
OCTOCOV_GITHUB_REF: refs/heads/main
OCTOCOV_GITHUB_SHA: none
OCTOCOV_CUSTOM_METRICS_BENCHMARK: perf-measures/type-check/diagnostics.json
13 changes: 13 additions & 0 deletions perf-measures/type-check/.octocov.perf-measures.main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
locale: "en"
repository: ${GITHUB_REPOSITORY}/perf-measures
coverage:
if: false
codeToTestRatio:
if: false
testExecutionTime:
if: false
report:
datastores:
- artifact://${GITHUB_REPOSITORY}
summary:
if: true
15 changes: 15 additions & 0 deletions perf-measures/type-check/.octocov.perf-measures.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
locale: "en"
repository: ${GITHUB_REPOSITORY}/perf-measures
coverage:
if: false
codeToTestRatio:
if: false
testExecutionTime:
if: false
diff:
datastores:
- artifact://${GITHUB_REPOSITORY}
comment:
if: is_pull_request
Comment on lines +12 to +13
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete this line if you do not need it to appear as a comment in every Pull Request.
You can also check the summary only.

summary:
if: true
48 changes: 37 additions & 11 deletions perf-measures/type-check/scripts/process-results.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,44 @@
import * as fs from 'node:fs/promises'
import * as readline from 'node:readline';

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 rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
})
const toKebabCase = (str: string): string => {
return str
.replace(/([a-z])([A-Z])/g, '$1-$2')
.replace(/[\s_\/]+/g, '-')
.toLowerCase()
}
const metrics = []
for await (const line of rl) {
if (!line || line.trim() === '') continue
const [name, value] = line.split(':')
const mainValue = previousResult?.[i]?.split(':')?.[1]
table.push(`| ${name?.trim()} | ${value?.trim()} | ${mainValue ? mainValue.trim() : 'N/A'} |`)
const unitMatch = value?.trim().match(/^(\d+(\.\d+)?)([a-zA-Z]*)$/)
if (unitMatch) {
const [, number, , unit] = unitMatch;
metrics.push({
key: toKebabCase(name?.trim()),
name: name?.trim(),
value: parseFloat(number),
unit: unit || undefined
})
} else {
metrics.push({
key: toKebabCase(name?.trim()),
name: name?.trim(),
value: parseFloat(value?.trim()),
})
}
}
const diagnostics = {
key: "diagnostics",
name: "Compiler Diagnostics",
metrics
}
console.log(table.join('\n'))
console.log(JSON.stringify(diagnostics, null, 2))
}

main()