verify-release-status-schema.mjs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { readFile } from 'node:fs/promises'
  2. import { dirname, join, resolve } from 'node:path'
  3. import { fileURLToPath } from 'node:url'
  4. import { validateJsonSchema } from './lib/simple-json-schema.mjs'
  5. const scriptDir = dirname(fileURLToPath(import.meta.url))
  6. const sourceRoot = resolve(scriptDir, '..')
  7. const args = process.argv.slice(2)
  8. function readArg(name, fallback) {
  9. const index = args.indexOf(name)
  10. return index >= 0 ? args[index + 1] : fallback
  11. }
  12. async function readJson(path) {
  13. return JSON.parse(await readFile(path, 'utf8'))
  14. }
  15. const schemaPath = resolve(
  16. sourceRoot,
  17. readArg('--schema', 'ecosystem/release-status.schema.json')
  18. )
  19. const statusPath = resolve(
  20. sourceRoot,
  21. readArg(
  22. '--status',
  23. process.env.FILE_VIEWER_PUBLIC_REPO_DIR
  24. ? join(process.env.FILE_VIEWER_PUBLIC_REPO_DIR, 'artifacts', 'release-status.json')
  25. : '../file-viewer-public/artifacts/release-status.json'
  26. )
  27. )
  28. const [schema, status] = await Promise.all([readJson(schemaPath), readJson(statusPath)])
  29. const failures = validateJsonSchema(status, schema)
  30. if (schema.$id !== 'https://github.com/flyfish-dev/file-viewer/releases/download/v2.0.1/release-status.schema.json') {
  31. failures.push('schema $id must point at the GitHub Release schema asset')
  32. }
  33. if (!schema.required?.includes('gapSummary') || !schema.required?.includes('gapDetails')) {
  34. failures.push('schema must require gapSummary and gapDetails')
  35. }
  36. if (status.gapSummary?.total !== status.gaps?.length) {
  37. failures.push('status gapSummary.total must match gaps.length')
  38. }
  39. if (status.gapDetails?.length !== status.gaps?.length) {
  40. failures.push('status gapDetails.length must match gaps.length')
  41. }
  42. if (failures.length) {
  43. throw new Error(`Release status schema verification failed:\n${failures.join('\n')}`)
  44. }
  45. console.log(`Verified release status schema ${schemaPath} against ${statusPath}.`)