Skip to content

Commit 9316e60

Browse files
authored
Merge branch 'main' into xpack-usage-ilm-action
2 parents ae90545 + 008712c commit 9316e60

File tree

1,295 files changed

+54190
-11616
lines changed

Some content is hidden

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

1,295 files changed

+54190
-11616
lines changed

.github/validate-pr/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ async function run () {
5353
per_page: 100
5454
})
5555
if (data.length > 0) {
56-
files.push(...data.map(entry => entry.filename))
56+
files.push(...data.filter(entry => entry.status !== 'deleted').map(entry => entry.filename))
5757
page += 1
5858
} else {
5959
break
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
name: Check
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
types: [labeled, unlabeled, opened, reopened, synchronize]
8+
9+
permissions:
10+
pull-requests: "read"
11+
12+
jobs:
13+
check-backport-label:
14+
name: backport label
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: "Check backport label"
19+
env:
20+
GH_TOKEN: ${{ github.token }}
21+
run: |
22+
json_pr_labels='${{ toJSON(github.event.pull_request.labels) }}'
23+
readarray -t pr_labels < <(echo "${json_pr_labels}" | jq -r -c '.[].name')
24+
25+
json_all_labels="$(gh label list --repo ${{ github.repository }} --json name --search "backport" --limit 1000)"
26+
readarray -t all_labels < <(echo "${json_all_labels}" | jq -r -c '.[].name')
27+
28+
declare -A all_backport_labels=()
29+
declare -A all_floating_majors=()
30+
31+
backport_regex="^backport ([0-9])+\.([0-9]+|x)$"
32+
33+
echo "::group::Available Labels"
34+
echo "skip-backport"
35+
36+
for label in "${all_labels[@]}"; do
37+
if [[ "${label}" =~ ${backport_regex} ]]; then
38+
major="${BASH_REMATCH[1]}"
39+
minor="${BASH_REMATCH[2]}"
40+
all_backport_labels["${label}"]=1
41+
echo "${label}"
42+
43+
if [ "${minor}" = "x" ]; then
44+
all_floating_majors["${major}"]=1
45+
fi
46+
fi
47+
done
48+
49+
echo "::endgroup::"
50+
51+
has_backport_label=false
52+
has_skip_backport_label=false
53+
declare -A pr_exact_majors=()
54+
declare -A pr_floating_majors=()
55+
56+
echo "::group::Detected Labels"
57+
58+
for pr_label in "${pr_labels[@]}"; do
59+
if [ "${pr_label}" = "skip-backport" ]; then
60+
has_skip_backport_label=true
61+
echo "${pr_label}"
62+
continue
63+
fi
64+
65+
if [ -z "${all_backport_labels[${pr_label}]}" ]; then
66+
continue
67+
fi
68+
69+
has_backport_label=true
70+
71+
if [[ "${pr_label}" =~ ${backport_regex} ]]; then
72+
major="${BASH_REMATCH[1]}"
73+
minor="${BASH_REMATCH[2]}"
74+
if [ "${minor}" != "x" ]; then
75+
pr_exact_majors["${major}"]=1
76+
else
77+
pr_floating_majors["${major}"]=1
78+
fi
79+
fi
80+
81+
echo "${pr_label}"
82+
done
83+
84+
echo "::endgroup::"
85+
86+
if [ "${has_skip_backport_label}" = true ] && [ "${has_backport_label}" = true ]; then
87+
echo "::error::The 'skip-backport' not be used in combination with another backport"\
88+
"label."
89+
exit 1
90+
fi
91+
92+
if [ "${has_skip_backport_label}" != true ] && [ "${has_backport_label}" != true ]; then
93+
echo "::error::No backport label found. Please add at least one of the"\
94+
"'backport {major}.{minor|x}' labels or use 'skip-backport',"\
95+
"if this PR should not be backported."
96+
exit 1
97+
fi
98+
99+
# Validate that a floating backport label exists for each exact backport label major
100+
# version.
101+
102+
has_required_floating_labels=true
103+
104+
for pr_major in "${!pr_exact_majors[@]}"; do
105+
if [ -z "${all_floating_majors[${pr_major}]}" ]; then
106+
# There is no floating version branch for the given major version.
107+
continue
108+
fi
109+
110+
if [ -z "${pr_floating_majors[${pr_major}]}" ]; then
111+
has_required_floating_labels=false
112+
echo "::error::Missing floating backport label for '${pr_major}.x'"
113+
fi
114+
done
115+
116+
if [ "${has_required_floating_labels}" != true ]; then
117+
exit 1
118+
fi

.github/workflows/gh-pages-report.yml

Lines changed: 0 additions & 40 deletions
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
branch: ['main', '8.x', '8.16', '8.17', 7.17']
16+
branch: ['main', '8.x', '8.16', '8.17', '7.17']
1717

1818
steps:
1919
- uses: actions/checkout@v4

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ If you are using MacOS, run the following command to fix the issue:
305305
brew install coreutils
306306
```
307307

308-
### I need to modify che compiler, help!
308+
### I need to modify the compiler, help!
309309

310310
Take a look at the [compiler documentation](./docs/compiler.md).
311311

compiler-rs/Cargo.lock

Lines changed: 17 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler-rs/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ derive_more = "1.0.0-beta.6"
1717
either_n = "0.2"
1818
icu_segmenter = "1"
1919
indexmap = "2"
20+
itertools = "0.14"
2021
maplit = "1"
2122
once_cell = "1.16"
2223
openapiv3 = "2"

compiler-rs/clients_schema/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ serde_json = { workspace = true }
1111
once_cell = { workspace = true }
1212
anyhow = { workspace = true }
1313
indexmap = { workspace = true, features = ["serde"] }
14+
itertools = { workspace = true }
15+
1416

1517
arcstr = { workspace = true, features = ["serde", "substr"] }
1618
clap = { workspace = true, features = ["derive"] }
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
use std::collections::HashMap;
2+
use std::path::{Path, PathBuf};
3+
use clap::Parser;
4+
use itertools::Itertools;
5+
6+
7+
fn main() -> anyhow::Result<()> {
8+
let cli = Cli::parse();
9+
cli.run()?;
10+
Ok(())
11+
}
12+
13+
// Example usage:
14+
// (cd compiler-rs; find ../specification -name '*Request.ts' | cargo run --bin add_url_paths ../output/schema/schema.json | sh)
15+
16+
/// Adds url paths to request definitions. Stdin must be a list of files, one per line.
17+
/// Outputs a shell script that uses ast-grep.
18+
#[derive(Debug, Parser)]
19+
#[command(author, version, about, long_about)]
20+
pub struct Cli {
21+
/// input schema file, eg: ../output/schema/schema-no-generics.json
22+
schema: PathBuf,
23+
}
24+
25+
impl Cli {
26+
pub fn run(&self) -> anyhow::Result<()> {
27+
28+
// Canonicalize all file names, so that we can do some suffix mapping from the schema locations.
29+
let files: Vec<PathBuf> = std::io::read_to_string(std::io::stdin())?
30+
.lines()
31+
.flat_map(|line| std::fs::canonicalize(line)
32+
.map_err(|e| {
33+
eprintln!("File {} not found", line);
34+
Result::<PathBuf, _>::Err(e)
35+
})) // Remove errors
36+
.collect();
37+
38+
let json = std::fs::read_to_string(&self.schema)?;
39+
let schema = clients_schema::IndexedModel::from_reader(json.as_bytes())?;
40+
41+
let mut location_to_request = HashMap::<&Path, &clients_schema::Endpoint>::new();
42+
for ep in &schema.endpoints {
43+
let Some(req_name) = ep.request.as_ref() else {
44+
//eprintln!("Skipping endpoint {} with no request", ep.name);
45+
continue;
46+
};
47+
48+
let type_def = schema.types.get(req_name).unwrap();
49+
let location = type_def.base().spec_location.as_ref().unwrap();
50+
let location = Path::new(location.split_once('#').unwrap().0);
51+
52+
location_to_request.insert(location, ep);
53+
};
54+
55+
for file in files {
56+
if let Some((_, endpoint)) = location_to_request.iter().find(|(location, _)| file.ends_with(location)) {
57+
generate_astgrep_command(&file, endpoint);
58+
} else {
59+
eprintln!("No request found for {:?}", file);
60+
}
61+
}
62+
63+
Ok(())
64+
}
65+
}
66+
67+
fn generate_astgrep_command(file: &Path, endpoint: &clients_schema::Endpoint) {
68+
69+
let text = std::fs::read_to_string(file).unwrap();
70+
if text.contains("urls:") {
71+
eprintln!("Found an existing 'url' property. Skipping {file:?}");
72+
return;
73+
}
74+
75+
// We cannot express conditional parts in the source form of patterns.
76+
77+
// Requests with generic parameters
78+
let request_expr = if text.contains("Request<") {
79+
"Request<$$$PARAM>"
80+
} else {
81+
"Request"
82+
};
83+
84+
// A handful of requests don't have an extends clause
85+
let extends_expr = if text.contains(" extends ") {
86+
"extends $REQBASE"
87+
} else {
88+
""
89+
};
90+
91+
let urls: String = endpoint.urls.iter().map(|url| {
92+
let path = &url.path;
93+
let methods = url.methods.iter().map(|method| format!("\"{}\"", method)).join(", ");
94+
let deprecation = match &url.deprecation {
95+
Some(deprecation) => format!("/** @deprecated {} {} */\n ", deprecation.version, deprecation.description),
96+
None => "".to_string(),
97+
};
98+
99+
format!(r#" {{
100+
{deprecation}path: "{path}",
101+
methods: [{methods}]
102+
}}"#)
103+
}).join(",\n");
104+
105+
let pattern = format!(r#"interface {request_expr} {extends_expr} {{
106+
$$$PROPS
107+
}}"#);
108+
109+
let fix = format!(r#"interface {request_expr} {extends_expr} {{
110+
urls: [
111+
{urls}
112+
],
113+
$$$PROPS
114+
}}"#);
115+
116+
let file = file.to_str().unwrap();
117+
println!("#----- {file}");
118+
println!(r#"ast-grep --update-all --lang ts --pattern '{pattern}' --rewrite '{fix}' "{file}""#);
119+
120+
println!();
121+
}

0 commit comments

Comments
 (0)