Skip to content

Commit 6cd1f87

Browse files
pquentingithub-actions[bot]
authored andcommitted
Support validating multiple APIs at once (#4672)
This means make validate api=search,index is possible, but more importantly that validation in CI will be much faster. (cherry picked from commit 10487a1)
1 parent de7f067 commit 6cd1f87

File tree

4 files changed

+37
-25
lines changed

4 files changed

+37
-25
lines changed

.github/validate-pr/index.js

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ async function run() {
8686

8787
cd(tsValidationPath)
8888

89+
// Collect all APIs to validate
90+
const apisToValidate = new Set()
91+
8992
for (const file of specFiles) {
9093
if (file.startsWith('specification/_types')) continue
9194
if (file.startsWith('specification/_spec_utils')) continue
@@ -97,32 +100,35 @@ async function run() {
97100
.filter(endpoint => endpoint.name.split('.').filter(s => !privateNames.includes(s))[0] === getApi(file).split('.')[0])
98101
.map(endpoint => endpoint.name)
99102
for (const api of apis) {
100-
const report = await getReport({
101-
api,
102-
'generate-report': false,
103-
request: true,
104-
response: true,
105-
ci: false,
106-
verbose: false
107-
})
108-
const namespace = getNamespace(api)
109-
// Asked to validate a specific API, so we only store that one
110-
reports.set(api, report.get(namespace)[0])
103+
apisToValidate.add(api)
111104
}
112105
} else {
113106
const api = getApi(file)
114-
const report = await getReport({
115-
api,
116-
'generate-report': false,
117-
request: true,
118-
response: true,
119-
ci: false,
120-
verbose: false
121-
})
107+
apisToValidate.add(api)
108+
}
109+
}
122110

111+
// 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) {
123125
const namespace = getNamespace(api)
124-
// Asked to validate a specific API, so we only store that one
125-
reports.set(api, report.get(namespace)[0])
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+
}
131+
}
126132
}
127133
}
128134

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ make validate api=xpack.info type=request branch=main
234234

235235
# this will validate the xpack.info request and response types against the 8.15 branch
236236
make validate api=xpack.info branch=8.15
237+
238+
# this will validate the xpack.info and search request and response types against the 8.15 branch
239+
make validate api=xpack.info,search branch=8.15
237240
```
238241

239242
The last command above will install all the dependencies and run, download

compiler/run-validations.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,11 @@ async function run () {
7878
process.exit(1)
7979
}
8080

81-
if (!apis.includes(options.api)) {
82-
spinner.fail(`The api '${options.api}' does not exists, did you mean '${closest(options.api, apis)}'?`)
81+
const apiList = options.api.split(',').map(api => api.trim())
82+
const invalidApis = apiList.filter(api => !apis.includes(api))
83+
if (invalidApis.length > 0) {
84+
const suggestions = invalidApis.map(api => `'${api}' (did you mean '${closest(api, apis)}'?)`).join(', ')
85+
spinner.fail(`The following APIs do not exist: ${suggestions}`)
8386
process.exit(1)
8487
}
8588
// if the empty string it's because the make target wasn't configured with a type argument

docs/validation-example.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ The example assumes that you have already performed the necessary steps to run a
1616
if not, take a look at the [README](../README.md).
1717

1818
```sh
19-
make validate api=index type=request branch=main
19+
make validate api=index branch=main
2020
```
2121

2222
You will see an output like the following:
@@ -82,7 +82,7 @@ open it with your favourite editor and perform the fix
8282
Finally run the validation again:
8383

8484
```sh
85-
make validate api=index type=request branch=main
85+
make validate api=index branch=main
8686
```
8787

8888
If there are no more errors, open a pull request with the fix.

0 commit comments

Comments
 (0)