Skip to content

Commit

Permalink
Merge pull request #1 from k2tzumi/octocov-custom-metrix
Browse files Browse the repository at this point in the history
Display performance measurement results as custom metrics
  • Loading branch information
k2tzumi authored Oct 5, 2024
2 parents 31b4cd4 + 5543989 commit a27e3ca
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 36 deletions.
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
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()

0 comments on commit a27e3ca

Please sign in to comment.