22
22
import { dirname } from 'path'
23
23
import { fileURLToPath } from 'url'
24
24
import 'zx/globals'
25
- import assert from 'assert'
26
25
import * as core from '@actions/core'
27
26
import { copyFile } from 'fs/promises'
28
- import * as github from '@actions/github'
29
27
import specification from '../../output/schema/schema.json' with { type : 'json' }
30
28
import baselineValidation from '../../../clients-flight-recorder/recordings/types-validation/types-validation.json' with { type : 'json' }
31
29
import { run as getReport } from '../../../clients-flight-recorder/scripts/types-validator/index.js'
@@ -36,7 +34,6 @@ import {
36
34
37
35
const __dirname = dirname ( fileURLToPath ( import . meta. url ) )
38
36
39
- const octokit = github . getOctokit ( argv . token )
40
37
41
38
const privateNames = [ '_global' ]
42
39
const tick = '`'
@@ -55,51 +52,16 @@ async function run() {
55
52
path . join ( __dirname , '..' , '..' , 'output' , 'typescript' , 'types.ts' ) ,
56
53
path . join ( tsValidationPath , 'types.ts' )
57
54
)
58
- const context = github . context
59
- assert ( context . payload . pull_request , 'We should be in a PR context' )
60
- const files = [ ]
61
- let page = 1
62
- while ( true ) {
63
- const { data } = await octokit . rest . pulls . listFiles ( {
64
- owner : 'elastic' ,
65
- repo : 'elasticsearch-specification' ,
66
- pull_number : context . payload . pull_request . number ,
67
- page,
68
- per_page : 100
69
- } )
70
- if ( data . length > 0 ) {
71
- files . push (
72
- ...data
73
- . filter ( ( entry ) => entry . status !== 'deleted' )
74
- . map ( ( entry ) => entry . filename )
75
- )
76
- page += 1
77
- } else {
78
- break
79
- }
80
- }
81
-
82
- const specFiles = files . filter (
83
- ( file ) => file . includes ( 'specification' ) && ! file . includes ( 'compiler/test' )
84
- )
85
55
const reports = new Map ( )
86
56
87
- cd ( tsValidationPath )
88
57
89
58
// Collect all APIs to validate
90
59
const apisToValidate = new Set ( )
91
60
92
- for ( const file of specFiles ) {
61
+ cd ( path . join ( __dirname , '..' , '..' ) )
62
+ for ( const file of await glob ( 'specification/**/*.ts' ) ) {
93
63
if ( file . startsWith ( 'specification/_types' ) ) continue
94
- if ( file . startsWith ( 'specification/_spec_utils' ) ) continue
95
- if ( file . startsWith ( 'specification/_doc_ids' ) ) continue
96
- if ( file . startsWith ( 'specification/_json_spec' ) ) continue
97
64
if ( file . startsWith ( 'specification/node_modules' ) ) continue
98
- if ( file . endsWith ( 'tsconfig.json' ) ) continue
99
- if ( file . endsWith ( 'eslint.config.js' ) ) continue
100
- if ( file . endsWith ( 'package.json' ) ) continue
101
- if ( file . endsWith ( 'package-lock.json' ) ) continue
102
- if ( file . endsWith ( '.md' ) ) continue
103
65
if ( getApi ( file ) . endsWith ( '_types' ) ) {
104
66
const apis = specification . endpoints
105
67
. filter ( endpoint => endpoint . name . split ( '.' ) . filter ( s => ! privateNames . includes ( s ) ) [ 0 ] === getApi ( file ) . split ( '.' ) [ 0 ] )
@@ -113,26 +75,27 @@ async function run() {
113
75
}
114
76
}
115
77
78
+ cd ( tsValidationPath )
79
+ console . log ( `Validating ${ apisToValidate . size } APIs...` )
80
+
116
81
// Call getReport once with all APIs
117
- if ( apisToValidate . size > 0 ) {
118
- const allApis = Array . from ( apisToValidate ) . join ( ',' )
119
- const report = await getReport ( {
120
- api : allApis ,
121
- 'generate-report' : false ,
122
- request : true ,
123
- response : true ,
124
- ci : false ,
125
- verbose : false
126
- } )
127
-
128
- // Extract individual API reports from the combined result
129
- for ( const api of apisToValidate ) {
130
- const namespace = getNamespace ( api )
131
- if ( report . has ( namespace ) ) {
132
- const namespaceReport = report . get ( namespace ) . find ( r => r . api === getName ( api ) )
133
- if ( namespaceReport ) {
134
- reports . set ( api , namespaceReport )
135
- }
82
+ const allApis = Array . from ( apisToValidate ) . join ( ',' )
83
+ const report = await getReport ( {
84
+ api : allApis ,
85
+ 'generate-report' : false ,
86
+ request : true ,
87
+ response : true ,
88
+ ci : false ,
89
+ verbose : false
90
+ } )
91
+
92
+ // Extract individual API reports from the combined result
93
+ for ( const api of apisToValidate ) {
94
+ const namespace = getNamespace ( api )
95
+ if ( report . has ( namespace ) ) {
96
+ const namespaceReport = report . get ( namespace ) . find ( r => r . api === getName ( api ) )
97
+ if ( namespaceReport ) {
98
+ reports . set ( api , namespaceReport )
136
99
}
137
100
}
138
101
}
@@ -170,7 +133,12 @@ function getApi (file) {
170
133
}
171
134
172
135
function findBaselineReport ( apiName , baselineValidation ) {
173
- const [ namespace , method ] = apiName . split ( '.' )
136
+ let namespace , method = [ null , null ]
137
+ if ( ! apiName . includes ( '.' ) ) {
138
+ [ namespace , method ] = [ 'global' , apiName ]
139
+ } else {
140
+ [ namespace , method ] = apiName . split ( '.' )
141
+ }
174
142
175
143
if ( ! baselineValidation . namespaces [ namespace ] ) {
176
144
return null
0 commit comments