Skip to content
Merged
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
17 changes: 12 additions & 5 deletions .github/workflows/generate-stats.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ jobs:
name: Prepare benchmarks
runs-on: depot-ubuntu-24.04
outputs:
browserVersion: ${{ steps.chrome.outputs.version }}
install: ${{ steps.set-matrix.outputs.install }}
build: ${{ steps.set-matrix.outputs.build }}
devServer: ${{ steps.set-matrix.outputs.devServer }}
Expand Down Expand Up @@ -99,6 +98,18 @@ jobs:
- name: Validate first-party dependency manifests
run: pnpm --filter @framework-performance/stats-generator validate:first-party-dependencies

- name: Prepare starting CI results
env:
BROWSER_VERSION: ${{ steps.chrome.outputs.version }}
run: node packages/stats-generator/src/scripts/prepare-ci-results.ts prepared-results

- name: Upload starting CI results
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: prepared-results
path: prepared-results/*.json
if-no-files-found: error

- name: Set matrices from TypeScript config
id: set-matrix
run: |
Expand Down Expand Up @@ -163,8 +174,6 @@ jobs:
path: artifacts

- name: Validate all measurement artifacts and assembled results
env:
BROWSER_VERSION: ${{ needs.setup.outputs.browserVersion }}
run: pnpm --filter @framework-performance/stats-generator validate:ci-stats "$GITHUB_WORKSPACE/artifacts"

generate-stats:
Expand Down Expand Up @@ -200,8 +209,6 @@ jobs:
run: find artifacts -type f -name "*.json" 2>/dev/null || echo "No artifacts found"

- name: Save CI stats
env:
BROWSER_VERSION: ${{ needs.setup.outputs.browserVersion }}
run: pnpm --filter @framework-performance/stats-generator save:ci-stats "$GITHUB_WORKSPACE/artifacts"

- name: Format
Expand Down
25 changes: 16 additions & 9 deletions packages/results/src/benchmark-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ export const HTMLBaselineBenchmarkResult = z.object({
frameworkVersion: z.string(),

// For HTML Baseline this is Node Version release date it is using
frameworkReleasedAt: z.string(),
frameworkReleasedAt: z.string().min(1),

// Benchmarks
ssrThroughput: SSRThroughputBenchmark.optional(),
Expand All @@ -356,10 +356,8 @@ export const HTMLBaselineBenchmarkResult = z.object({
configuration: z.record(z.string(), z.unknown()),
})

/**
* Final Benchmark Result schema for all Meta-frameworks results
*/
export const MetaFrameworkBenchmarkResults = z.object({
/** Validates framework metadata and any benchmarks collected during CI. */
export const MetaFrameworkBenchmarkCIResults = z.object({
framework: z.enum(
FrameworkOptions.filter((option) => option !== 'baseline-html'),
),
Expand All @@ -368,7 +366,7 @@ export const MetaFrameworkBenchmarkResults = z.object({
runner: z.string(),
browserVersion: z.string(),
frameworkVersion: z.string(),
frameworkReleasedAt: z.string(),
frameworkReleasedAt: z.string().min(1),

// Benchmarks (should always be options to support new benchmarks, removing old ones and frameworks that might not be able to complete one)
dependencyCounts: DependencyCountBenchmark.optional(),
Expand All @@ -384,11 +382,20 @@ export const MetaFrameworkBenchmarkResults = z.object({
ssrThroughput: SSRThroughputBenchmark.optional(),
ssrLoad: SSRLoadBenchmark.optional(),
ssrLoadRouterLinks: SSRLoadRouterLinksBenchmark.optional(),

// Comes from packages/results/src/measurements-config.ts so leave as flexible type as this can change and is only needed as record
configuration: z.record(z.string(), z.unknown()),
})

// Validates a stored meta-framework result, including the configuration used for the run.
export const MetaFrameworkBenchmarkResults =
MetaFrameworkBenchmarkCIResults.extend({
// Comes from packages/results/src/measurements-config.ts so leave as flexible type as this can change and is only needed as record
configuration: z.record(z.string(), z.unknown()),
})

export const BenchmarkCIResultSchema = z.discriminatedUnion('framework', [
HTMLBaselineBenchmarkResult.omit({ configuration: true }),
MetaFrameworkBenchmarkCIResults,
])

export const BenchmarkResultSchema = z.discriminatedUnion('framework', [
HTMLBaselineBenchmarkResult,
MetaFrameworkBenchmarkResults,
Expand Down
17 changes: 15 additions & 2 deletions packages/stats-generator/src/initial-load-persistence.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ test('CI requires, validates, and preserves initial load artifacts', async () =>
app: { ...framework.app!, measurements: ['ssrInitialLoad' as const] },
}
const options = {
browserVersion: 'Google Chrome 156',
validateOnly: true,
frameworks: [configured],
}
Expand All @@ -33,15 +32,29 @@ test('CI requires, validates, and preserves initial load artifacts', async () =>
},
]),
)
const previous = readBenchmarkResult('astro')!
const artifact = {
frameworkVersion: readBenchmarkResult('astro')?.frameworkVersion,
frameworkVersion: previous.frameworkVersion,
ssrInitialLoad: {
name: 'ssrInitialLoad',
project: 'app',
resources,
},
}
try {
mkdirSync(join(directory, 'prepared-results'))
writeFileSync(
join(directory, 'prepared-results', 'astro.json'),
JSON.stringify({
framework: 'astro',
frameworkVersion: previous.frameworkVersion,
frameworkReleasedAt: previous.frameworkReleasedAt,
projects: previous.projects,
timingMeasuredAt: previous.timingMeasuredAt,
runner: previous.runner,
browserVersion: 'Google Chrome 156',
}),
)
await assert.rejects(
processCIStats(directory, options),
/Missing or invalid measurement artifact/,
Expand Down
73 changes: 20 additions & 53 deletions packages/stats-generator/src/save-ci-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
saveBenchmarkResult,
} from '@framework-performance/results/storage'
import {
BenchmarkCIResultSchema,
BenchmarkResultSchema,
DependencyCountBenchmark,
type BenchmarkResult,
Expand All @@ -13,60 +14,45 @@ import { getSSRLoadPath } from './ssrLoad/config.ts'
import { join } from 'node:path'
import { getFrameworks } from './get-frameworks.ts'
import { readFileSync } from 'node:fs'
import { getPublishTimes } from './release-dates.ts'
import { getPackageJsonDeps } from './utils.ts'
import {
benchmarkArtifacts,
type BenchmarkArtifact,
} from './benchmark-artifacts.ts'
import type { FrameworkConfig } from './types.ts'

const publishTimesCache = new Map<string, Promise<Record<string, string>>>()

async function getReleasedAt(packageName: string, version: string) {
if (!publishTimesCache.has(packageName)) {
publishTimesCache.set(packageName, getPublishTimes(packageName))
}
const releasedAt = (await publishTimesCache.get(packageName)!)[version]
if (releasedAt == null)
throw new Error(`No publish time for ${packageName}@${version}`)
return releasedAt
}

export async function processCIStats(
artifactsDir: string,
{
validateOnly = false,
frameworks: configuredFrameworks,
browserVersion = process.env.BROWSER_VERSION,
}: {
validateOnly?: boolean
frameworks?: FrameworkConfig[]
browserVersion?: string
} = {},
) {
const timingMeasuredAt = new Date().toISOString()
const runner = process.env.RUNNER_LABEL || 'local'
const frameworks = configuredFrameworks ?? (await getFrameworks())
const results = new Map<string, BenchmarkResult>()

for (const framework of frameworks) {
const previous = readBenchmarkResult(framework.name)
const fresh: Record<string, unknown> = {}
const dependencyCounts: Record<string, unknown> = {}
const artifactVersions = new Map<string, string>()
const projects: Partial<
Record<'starter' | 'app', BenchmarkResult['projects']['app']>
> = { ...previous?.projects }
const prepared = BenchmarkCIResultSchema.parse(
JSON.parse(
readFileSync(
join(artifactsDir, 'prepared-results', `${framework.name}.json`),
'utf8',
),
),
)
if (prepared.framework !== framework.name)
throw new Error(
`Expected prepared result for ${framework.name}, got ${prepared.framework}`,
)

for (const project of ['starter', 'app'] as const) {
const target = framework[project]
if (!target) continue
projects[project] = {
path: `packages/${target.package}` as BenchmarkResult['projects']['app']['path'],
packageJson: getPackageJsonDeps(target.package),
}

for (const [
measurement,
folder,
Expand All @@ -89,9 +75,12 @@ export async function processCIStats(
}

for (const [key, value] of Object.entries(artifact)) {
if (key === 'frameworkVersion')
artifactVersions.set(folder, String(value))
else if (key === 'dependencyCounts')
if (key === 'frameworkVersion') {
if (value !== prepared.frameworkVersion)
throw new Error(
`Framework version mismatch in ${file}: expected ${prepared.frameworkVersion}, got ${value}`,
)
} else if (key === 'dependencyCounts')
Object.assign(dependencyCounts, value)
else if (key === 'starterNodeModuleSize')
dependencyCounts[key] = value
Expand All @@ -105,20 +94,6 @@ export async function processCIStats(
!framework.starter?.measurements.length
)
continue
const versions = new Set(artifactVersions.values())
if (versions.size > 1) {
const details = [...artifactVersions]
.map(([artifact, version]) => `${artifact}=${version}`)
.join(', ')
throw new Error(
`Measurement artifacts disagree on framework version for ${framework.name}: ${details}`,
)
}
const frameworkVersion = [...versions][0] ?? previous?.frameworkVersion
if (!frameworkVersion || frameworkVersion === 'unknown')
throw new Error(`No measured version for ${framework.name}`)

const sameVersion = frameworkVersion === previous?.frameworkVersion
if (framework.starter?.measurements.includes('dependencies')) {
fresh.dependencyCounts = DependencyCountBenchmark.parse({
...dependencyCounts,
Expand All @@ -139,16 +114,8 @@ export async function processCIStats(
},
}
const assembled = BenchmarkResultSchema.parse({
...prepared,
...fresh,
framework: framework.name,
frameworkVersion,
frameworkReleasedAt: sameVersion
? previous.frameworkReleasedAt
: await getReleasedAt(framework.frameworkPackage, frameworkVersion),
browserVersion,
timingMeasuredAt,
runner,
projects,
configuration,
})
results.set(
Expand Down
62 changes: 62 additions & 0 deletions packages/stats-generator/src/scripts/prepare-ci-results.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { mkdirSync, writeFileSync } from 'node:fs'
import { join } from 'node:path'
import { BenchmarkCIResultSchema } from '@framework-performance/results/benchmark-schemas'
import { readBenchmarkResult } from '@framework-performance/results/storage'
import { frameworksConfig } from '../frameworks.ts'
import { getPublishTimes } from '../release-dates.ts'
import { getPackageJsonDeps } from '../utils.ts'

const outputDirectory = process.argv[2]
mkdirSync(outputDirectory, { recursive: true })
const timingMeasuredAt = new Date().toISOString()

for (const framework of frameworksConfig) {
const projects: Record<string, unknown> = {}
let frameworkVersion: string | undefined
for (const project of ['starter', 'app'] as const) {
const target = framework[project]
if (!target) continue
const packageJson = getPackageJsonDeps(target.package)
const version =
framework.frameworkPackage === 'node'
? process.versions.node
: (packageJson.dependencies[framework.frameworkPackage] ??
packageJson.devDependencies[framework.frameworkPackage])
if (!version)
throw new Error(`Missing framework version for ${target.package}`)
Comment on lines +25 to +26

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

if someone ever uses a range or catalog: here, every artifact fails later with expected ^x got x, which is a bit confusing. could check it's an exact version up front

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Are contribution rules specifically forbids this and each project is set up with pinned deps

if (frameworkVersion && version !== frameworkVersion)
throw new Error(
`Framework versions differ between projects for ${framework.name}: ${frameworkVersion} and ${version}`,
)
frameworkVersion = version
projects[project] = {
path: `packages/${target.package}`,
packageJson,
}
}
if (!frameworkVersion)
throw new Error(`Missing project for ${framework.name}`)
const previous = readBenchmarkResult(framework.name)
const frameworkReleasedAt =
previous?.frameworkVersion === frameworkVersion
? previous.frameworkReleasedAt
: (await getPublishTimes(framework.frameworkPackage))[frameworkVersion]
Comment thread
AlexanderKaran marked this conversation as resolved.
Resolved
if (!frameworkReleasedAt)
throw new Error(
`No publish time for ${framework.frameworkPackage}@${frameworkVersion}`,
)

const result = BenchmarkCIResultSchema.parse({
framework: framework.name,
frameworkVersion,
frameworkReleasedAt,
projects,
timingMeasuredAt,
runner: process.env.RUNNER_LABEL || 'local',
browserVersion: process.env.BROWSER_VERSION,
})
writeFileSync(
join(outputDirectory, `${framework.name}.json`),
JSON.stringify(result),
)
}
Loading