Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 8.15] make validate: Download recordings using branch, not version #2911

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/validate-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
else
branch=$GITHUB_REF_NAME
fi
node scripts/upload-recording/download.js --branch latest
node scripts/upload-recording/download.js --branch $branch
node scripts/clone-elasticsearch/index.js --branch $branch
env:
GCS_CREDENTIALS: ${{ secrets.GCS_CREDENTIALS }}
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
SHELL := /bin/bash

validate: ## Validate a given endpoint request or response
@node compiler/run-validations.js --api $(api) --type $(type) --stack-version $(stack-version)
@node compiler/run-validations.js --api $(api) --type $(type) --branch $(branch)

validate-no-cache: ## Validate a given endpoint request or response without local cache
@node compiler/run-validations.js --api $(api) --type $(type) --stack-version $(stack-version) --no-cache
@node compiler/run-validations.js --api $(api) --type $(type) --branch $(branch) --no-cache

generate: ## Generate the output spec
@echo ">> generating the spec .."
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,16 +204,16 @@ git clone https://github.com/elastic/elasticsearch-specification.git
git clone https://github.com/elastic/clients-flight-recorder.git

cd elasticsearch-specification
# this will validate the xpack.info request type against the 8.1.0 stack version
make validate api=xpack.info type=request stack-version=8.1.0-SNAPSHOT
# this will validate the xpack.info request type against the main branch of Elasticsearch
make validate api=xpack.info type=request branch=main

# this will validate the xpack.info request and response types against the 8.1.0 stack version
make validate api=xpack.info stack-version=8.1.0-SNAPSHOT
# this will validate the xpack.info request and response types against the 8.15 branch
make validate api=xpack.info branch=8.15
```

The last command above will install all the dependencies and run, download
the test recordings and finally validate the specification.
If you need to download the recordings again, run `make validate-no-cache api=xpack.info type=request stack-version=8.1.0-SNAPSHOT`.
If you need to download the recordings again, run `make validate-no-cache api=xpack.info type=request branch=main`.

Once you see the errors, you can fix the original definition in `/specification`
and then run the command again until the types validator does not trigger any new error.
Expand Down
16 changes: 9 additions & 7 deletions compiler/run-validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async function run () {
const isStale = lastRun.getTime() + DAY < Date.now()

if (typeof argv.api !== 'string') {
spinner.fail('You must specify the api, for example: \'make validate api=index type=request stack-version=8.1.0-SNAPSHOT\'')
spinner.fail('You must specify the api, for example: \'make validate api=index type=request branch=main\'')
process.exit(1)
}

Expand All @@ -75,15 +75,16 @@ async function run () {

// if true it's because the make target wasn't configured with a type argument
if (argv.type !== true && argv.type !== 'request' && argv.type !== 'response') {
spinner.fail('You must specify the type (request or response), for example: \'make validate api=index type=request stack-version=8.1.0-SNAPSHOT\'')
spinner.fail('You must specify the type (request or response), for example: \'make validate api=index type=request branch=main\'')
process.exit(1)
}

if (typeof argv['stack-version'] !== 'string') {
spinner.fail('You must specify the stack version, for example: \'make validate api=index type=request stack-version=8.1.0-SNAPSHOT\'')
if (typeof argv.branch !== 'string' && typeof argv.branch !== 'number') {
spinner.fail('You must specify the branch, for example: \'make validate api=index type=request branch=main\'')
process.exit(1)
}


const isFlightRecorderCloned = await $`[[ -d ${path.join(__dirname, '..', '..', 'clients-flight-recorder')} ]]`.exitCode === 0
if (!isFlightRecorderCloned) {
spinner.text = 'It looks like you didn\'t cloned the flight recorder, doing that for you'
Expand Down Expand Up @@ -165,7 +166,8 @@ async function run () {

spinner.text = 'Running validations'

const branchName = argv['stack-version'].startsWith('7.') ? '7.x' : argv['stack-version'].slice(0, 3)
const branchArg = argv.branch.toString()
const branchName = branchArg.startsWith('7.') ? '7.x' : branchArg

if (noCache || isStale || metadata.branchName !== branchName) {
metadata.lastRun = new Date()
Expand All @@ -175,7 +177,7 @@ async function run () {
await $`node ${path.join(uploadRecordingsPath, 'download.js')} --branch ${branchName}`

spinner.text = 'Fetching artifacts'
await $`node ${path.join(cloneEsPath, 'index.js')} --version ${argv['stack-version']}`
await $`node ${path.join(cloneEsPath, 'index.js')} --branch ${argv['branch']}`
}

cd(tsValidationPath)
Expand All @@ -188,7 +190,7 @@ async function run () {
} else {
flags.push(`--${argv.type}`)
}
const output = await $`STACK_VERSION=${argv['stack-version']} node ${path.join(tsValidationPath, 'index.js')} --api ${argv.api} ${flags}`
const output = await $`node ${path.join(tsValidationPath, 'index.js')} --api ${argv.api} --branch ${branchName} ${flags}`

cd(path.join(compilerPath, '..'))
if (output.exitCode === 0) {
Expand Down
6 changes: 3 additions & 3 deletions docs/validation-example.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The example assumes that you have already performed the necessary steps to run a
if not, take a look at the [README](./README.md).

```sh
make validate api=index type=request stack-version=8.1.0-SNAPSHOT
make validate api=index type=request branch=main
```

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

```sh
make validate api=index type=request stack-version=8.1.0-SNAPSHOT
make validate api=index type=request branch=main
```

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