2222import  {  dirname  }  from  'path' 
2323import  {  fileURLToPath  }  from  'url' 
2424import  'zx/globals' 
25- import  assert  from  'assert' 
2625import  *  as  core  from  '@actions/core' 
2726import  {  copyFile  }  from  'fs/promises' 
28- import  *  as  github  from  '@actions/github' 
2927import  specification  from  '../../output/schema/schema.json'  with  {  type : 'json'  } 
3028import  baselineValidation  from  '../../../clients-flight-recorder/recordings/types-validation/types-validation.json'  with  {  type : 'json'  } 
3129import  {  run  as  getReport  }  from  '../../../clients-flight-recorder/scripts/types-validator/index.js' 
@@ -36,7 +34,6 @@ import {
3634
3735const  __dirname  =  dirname ( fileURLToPath ( import . meta. url ) ) 
3836
39- const  octokit  =  github . getOctokit ( argv . token ) 
4037
4138const  privateNames  =  [ '_global' ] 
4239const  tick  =  '`' 
@@ -55,46 +52,16 @@ async function run() {
5552    path . join ( __dirname ,  '..' ,  '..' ,  'output' ,  'typescript' ,  'types.ts' ) , 
5653    path . join ( tsValidationPath ,  'types.ts' ) 
5754  ) 
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-   ) 
8555  const  reports  =  new  Map ( ) 
8656
87-   cd ( tsValidationPath ) 
8857
8958  // Collect all APIs to validate 
9059  const  apisToValidate  =  new  Set ( ) 
9160
92-   for  ( const  file  of  specFiles )  { 
61+   cd ( path . join ( __dirname ,  '..' ,  '..' ) ) 
62+   for  ( const  file  of  await  glob ( 'specification/**/*.ts' ) )  { 
9363    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-     if  ( file  ===  'specification/tsconfig.json' )  continue 
64+     if  ( file . startsWith ( 'specification/node_modules' ) )  continue 
9865    if  ( getApi ( file ) . endsWith ( '_types' ) )  { 
9966      const  apis  =  specification . endpoints 
10067        . filter ( endpoint  =>  endpoint . name . split ( '.' ) . filter ( s  =>  ! privateNames . includes ( s ) ) [ 0 ]  ===  getApi ( file ) . split ( '.' ) [ 0 ] ) 
@@ -108,26 +75,27 @@ async function run() {
10875    } 
10976  } 
11077
78+   cd ( tsValidationPath ) 
79+   console . log ( `Validating ${ apisToValidate . size }   APIs...` ) 
80+ 
11181  // Call getReport once with all APIs 
112-   if  ( apisToValidate . size  >  0 )  { 
113-     const  allApis  =  Array . from ( apisToValidate ) . join ( ',' ) 
114-     const  report  =  await  getReport ( { 
115-       api : allApis , 
116-       'generate-report' : false , 
117-       request : true , 
118-       response : true , 
119-       ci : false , 
120-       verbose : false 
121-     } ) 
122- 
123-     // Extract individual API reports from the combined result 
124-     for  ( const  api  of  apisToValidate )  { 
125-       const  namespace  =  getNamespace ( api ) 
126-       if  ( report . has ( namespace ) )  { 
127-         const  namespaceReport  =  report . get ( namespace ) . find ( r  =>  r . api  ===  getName ( api ) ) 
128-         if  ( namespaceReport )  { 
129-           reports . set ( api ,  namespaceReport ) 
130-         } 
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 ) 
13199      } 
132100    } 
133101  } 
@@ -165,7 +133,12 @@ function getApi (file) {
165133} 
166134
167135function  findBaselineReport ( apiName ,  baselineValidation )  { 
168-   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+   } 
169142
170143  if  ( ! baselineValidation . namespaces [ namespace ] )  { 
171144    return  null 
0 commit comments