Skip to content

Commit f987030

Browse files
committed
Merge remote-tracking branch 'origin/main' into rest-api-spec-converter
2 parents f974687 + aa3c923 commit f987030

File tree

97 files changed

+4684
-1203
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+4684
-1203
lines changed

.github/validate-pr/index.js

Lines changed: 28 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@
2222
import { dirname } from 'path'
2323
import { fileURLToPath } from 'url'
2424
import 'zx/globals'
25-
import assert from 'assert'
2625
import * as core from '@actions/core'
2726
import { copyFile } from 'fs/promises'
28-
import * as github from '@actions/github'
2927
import specification from '../../output/schema/schema.json' with { type: 'json' }
3028
import baselineValidation from '../../../clients-flight-recorder/recordings/types-validation/types-validation.json' with { type: 'json' }
3129
import { run as getReport } from '../../../clients-flight-recorder/scripts/types-validator/index.js'
@@ -36,7 +34,6 @@ import {
3634

3735
const __dirname = dirname(fileURLToPath(import.meta.url))
3836

39-
const octokit = github.getOctokit(argv.token)
4037

4138
const privateNames = ['_global']
4239
const tick = '`'
@@ -55,51 +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
9764
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
10365
if (getApi(file).endsWith('_types')) {
10466
const apis = specification.endpoints
10567
.filter(endpoint => endpoint.name.split('.').filter(s => !privateNames.includes(s))[0] === getApi(file).split('.')[0])
@@ -113,26 +75,27 @@ async function run() {
11375
}
11476
}
11577

78+
cd(tsValidationPath)
79+
console.log(`Validating ${apisToValidate.size} APIs...`)
80+
11681
// 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)
13699
}
137100
}
138101
}
@@ -170,7 +133,12 @@ function getApi (file) {
170133
}
171134

172135
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+
}
174142

175143
if (!baselineValidation.namespaces[namespace]) {
176144
return null

.github/workflows/code-format.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ jobs:
88
runs-on: ubuntu-latest
99

1010
steps:
11-
- uses: actions/checkout@v4
11+
- uses: actions/checkout@v5
1212

1313
- name: Use Node.js 22
14-
uses: actions/setup-node@v4
14+
uses: actions/setup-node@v5
1515
with:
1616
node-version: 22
1717

.github/workflows/compiler-rs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ jobs:
1212
runs-on: ubuntu-latest
1313

1414
steps:
15-
- uses: actions/checkout@v4
15+
- uses: actions/checkout@v5
1616

1717
- name: Use Node.js 22
18-
uses: actions/setup-node@v4
18+
uses: actions/setup-node@v5
1919
with:
2020
node-version: 22
2121

.github/workflows/compiler.test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ jobs:
1111
runs-on: ubuntu-latest
1212

1313
steps:
14-
- uses: actions/checkout@v4
14+
- uses: actions/checkout@v5
1515

1616
- name: Use Node.js 22
17-
uses: actions/setup-node@v4
17+
uses: actions/setup-node@v5
1818
with:
1919
node-version: 22
2020

.github/workflows/generate.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ jobs:
3030
if: github.repository_owner == 'elastic' && github.actor != 'elasticmachine'
3131
steps:
3232
- name: Checkout
33-
uses: actions/checkout@v3
33+
uses: actions/checkout@v5
3434
with:
3535
token: ${{ secrets.PAT }}
3636
persist-credentials: true
3737

3838
- name: Setup Node 22
39-
uses: actions/setup-node@v4
39+
uses: actions/setup-node@v5
4040
with:
4141
node-version: 22
4242
cache: npm

.github/workflows/license.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-latest
99

1010
steps:
11-
- uses: actions/checkout@v4
11+
- uses: actions/checkout@v5
1212

1313
- name: Check license headers
1414
run: |

.github/workflows/linter.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ jobs:
88
runs-on: ubuntu-latest
99

1010
steps:
11-
- uses: actions/checkout@v4
11+
- uses: actions/checkout@v5
1212

1313
- name: Use Node.js 22
14-
uses: actions/setup-node@v4
14+
uses: actions/setup-node@v5
1515
with:
1616
node-version: 22
1717

.github/workflows/metamodel-sync.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313

1414
steps:
15-
- uses: actions/checkout@v4
15+
- uses: actions/checkout@v5
1616

1717
- name: Copy compiler's metamodel to typescript-generator
1818
run: |

.github/workflows/update-rest-api-json.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ jobs:
1616
branch: ['main', '9.1', '9.0', '8.19', '8.18']
1717

1818
steps:
19-
- uses: actions/checkout@v4
19+
- uses: actions/checkout@v5
2020
with:
2121
ref: ${{ matrix.branch }}
2222

2323
- name: Use Node.js 22
24-
uses: actions/setup-node@v4
24+
uses: actions/setup-node@v5
2525
with:
2626
node-version: 22
2727

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,51 @@ on:
55
branches:
66
- main
77
- '[0-9]+.[0-9]+'
8+
push:
9+
branches:
10+
- main
11+
- '[0-9]+.[0-9]+'
12+
13+
permissions:
14+
pull-requests: write # To create/update PR comments
815

916
jobs:
10-
validate-pr:
17+
validate-apis:
1118
name: build
1219
runs-on: ubuntu-latest
1320

1421
steps:
1522
- name: Check pull request was opened from branch
16-
if: github.event.pull_request.head.repo.full_name != 'elastic/elasticsearch-specification'
23+
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != 'elastic/elasticsearch-specification'
1724
run: echo "Validation is not supported from forks"; exit 1
1825

19-
- uses: actions/checkout@v4
26+
- uses: actions/checkout@v5
2027
with:
2128
path: ./elasticsearch-specification
29+
persist-credentials: false
2230

23-
- uses: actions/checkout@v4
31+
- uses: actions/checkout@v5
2432
with:
2533
repository: elastic/clients-flight-recorder
2634
path: ./clients-flight-recorder
2735
token: ${{ secrets.PAT }}
28-
ref: main
36+
ref: ${{ github.base_ref }}
37+
persist-credentials: false
2938

3039
- name: Use Node.js 22
31-
uses: actions/setup-node@v4
40+
uses: actions/setup-node@v5
3241
with:
3342
node-version: 22
3443

44+
- name: Cache JSON report
45+
id: cache-json-report
46+
uses: actions/cache@v4
47+
with:
48+
path: ./clients-flight-recorder/recordings/types-validation/types-validation.json
49+
key: types-validation-json-${{ github.event_name == 'pull_request' && format('{0}-{1}', github.base_ref, github.event.pull_request.base.sha) || format('{0}-{1}', github.ref_name, github.sha) }}
50+
restore-keys: |
51+
types-validation-json-${{ github.event_name == 'pull_request' && github.base_ref || github.ref_name }}-
52+
3553
- name: Install deps 1/2
3654
working-directory: ./clients-flight-recorder
3755
run: |
@@ -53,20 +71,30 @@ jobs:
5371
- name: Download artifacts
5472
working-directory: ./clients-flight-recorder
5573
run: |
56-
if [[ -n "${GITHUB_BASE_REF+x}" ]]; then
74+
if [[ -n "${GITHUB_BASE_REF:-}" ]]; then
5775
branch=$GITHUB_BASE_REF
5876
else
5977
branch=$GITHUB_REF_NAME
6078
fi
79+
echo "Using branch: $branch"
6180
node scripts/upload-recording/download.js --branch $branch --git
6281
node scripts/clone-elasticsearch/index.js --branch $branch
6382
64-
- name: Run validation
83+
- name: Run validation (Push)
84+
if: github.event_name == 'push'
85+
working-directory: ./clients-flight-recorder/scripts/types-validator
86+
env:
87+
BRANCH: ${{ github.ref_name }}
88+
run: node index.js --generate-report --ci --branch $BRANCH
89+
90+
- name: Run validation (PR)
91+
if: github.event_name == 'pull_request'
6592
id: validation
6693
working-directory: ./elasticsearch-specification
6794
run: node .github/validate-pr --token ${{ secrets.GITHUB_TOKEN }}
6895

6996
- name: Find existing comment
97+
if: github.event_name == 'pull_request'
7098
uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3.1.0
7199
id: find-comment
72100
with:
@@ -75,6 +103,7 @@ jobs:
75103
body-includes: 'Following you can find the validation changes'
76104

77105
- name: Create or update comment
106+
if: github.event_name == 'pull_request'
78107
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
79108
with:
80109
token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)