Skip to content
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
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,14 @@ repos:
files: ^\.pre-commit-config\.yaml$|^docs/spelling_wordlist\.txt$
require_serial: true
pass_filenames: false
- id: update-openapi-spec-tags-to-be-sorted
name: Sort alphabetically openapi spec tags
entry: ./scripts/ci/pre_commit/sort_tags_in_openapi_spec.py
types: [yaml]
language: python
files: ^\.pre-commit-config\.yaml$|^airflow/api_connexion/openapi/v1\.yaml$
require_serial: true
pass_filenames: false
- id: lint-helm-chart
name: Lint Helm Chart
entry: ./scripts/ci/pre_commit/helm_lint.py
Expand Down
2 changes: 2 additions & 0 deletions contributing-docs/08_static_code_checks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@ require Breeze Docker image to be built locally.
+-----------------------------------------------------------+--------------------------------------------------------------+---------+
| update-migration-references | Update migration ref doc | * |
+-----------------------------------------------------------+--------------------------------------------------------------+---------+
| update-openapi-spec-tags-to-be-sorted | Sort alphabetically openapi spec tags | |
+-----------------------------------------------------------+--------------------------------------------------------------+---------+
| update-providers-dependencies | Update dependencies for provider packages | |
+-----------------------------------------------------------+--------------------------------------------------------------+---------+
| update-reproducible-source-date-epoch | Update Source Date Epoch for reproducible builds | |
Expand Down
8 changes: 4 additions & 4 deletions dev/breeze/doc/images/output_static-checks.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion dev/breeze/doc/images/output_static-checks.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
74e4402e7abd79d80bca112783891cb1
cbf4a8cef8333b856b04552d5d771f7b
1 change: 1 addition & 0 deletions dev/breeze/src/airflow_breeze/pre_commit_ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
"update-installers",
"update-local-yml-file",
"update-migration-references",
"update-openapi-spec-tags-to-be-sorted",
"update-providers-dependencies",
"update-reproducible-source-date-epoch",
"update-spelling-wordlist-to-be-sorted",
Expand Down
66 changes: 66 additions & 0 deletions scripts/ci/pre_commit/sort_tags_in_openapi_spec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env python3
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from __future__ import annotations

import re
from pathlib import Path

if __name__ not in ("__main__", "__mp_main__"):
raise SystemExit(
"This file is intended to be executed as an executable program. You cannot use it as a module."
f"To run this script, run the ./{__file__} command"
)

AIRFLOW_SOURCES = Path(__file__).parents[3].resolve()


def sort_tags(filename: Path):
with filename.open() as f:
lines = f.readlines()

# Find the start index of the tags list
tag_start_pattern = re.compile(r"tags:")
start_index = next(
(index + 1 for index, line in enumerate(lines) if tag_start_pattern.match(line)),
None,
)

if start_index is None:
print("Tags list not found in the YAML file.")
return

# Find the end index of the tags list
end_index = start_index
tag_pattern = re.compile(r"\s*-\s*name:")
while end_index < len(lines) and tag_pattern.match(lines[end_index]):
end_index += 1

# Extract and sort the tags
tags_lines = lines[start_index:end_index]
sorted_tags_lines = sorted(tags_lines, key=lambda x: x.strip().split(": ")[-1])

# Replace the sorted tags in the original content
lines[start_index:end_index] = sorted_tags_lines

with filename.open("w") as f:
f.write("".join(lines))


if __name__ == "__main__":
openapi_spec_filepath = Path(AIRFLOW_SOURCES) / "airflow" / "api_connexion" / "openapi" / "v1.yaml"
sort_tags(openapi_spec_filepath)