potiuk commented on a change in pull request #18335: URL: https://github.com/apache/airflow/pull/18335#discussion_r711343858
########## File path: scripts/ci/pre_commit/pre_commit_update_versions.py ########## @@ -0,0 +1,61 @@ +#!/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. +import glob +import json +import os +import re +from os.path import abspath, dirname, join +from re import Pattern + +import httpx + +AIRFLOW_SOURCES_DIR = abspath(join(dirname(__file__), os.pardir, os.pardir, os.pardir)) + + +def update_version(pattern: Pattern, version: str, file_path: str): + print(f"Replacing {pattern} to {version} in {file_path}") + with open(file_path, "r+") as f: + file_contents = f.read() + lines = file_contents.splitlines(keepends=True) + for i in range(0, len(lines)): + lines[i] = re.sub(pattern, fr'\g<1>{version}\g<2>', lines[i]) + file_contents = "".join(lines) + f.seek(0) + f.truncate() + f.write(file_contents) + + +REPLACEMENTS = { + r'(FROM apache/airflow:).*($)': "docs/docker-stack/docker-examples/extending/*/Dockerfile", + r'(apache/airflow:)[^-]*(\-)': "docs/docker-stack/entrypoint.rst", + r'(/constraints-)[^-]*(/constraints)': "docs/docker-stack/docker-examples/" + "restricted/restricted_environments.sh", + r'(AIRFLOW_VERSION=")[^"]*(" \\)': "docs/docker-stack/docker-examples/" + "restricted/restricted_environments.sh", +} + +if __name__ == '__main__': + airflow_pypi_info = json.loads(httpx.get("https://pypi.org/pypi/apache-airflow/json").text) Review comment: We could also use "latest" (but then the dockerfile example is not best - because users should use a specfiic version). It does not **really** matter if we use current or latest in this case - both should work fine because the tests are just testing if the "Dockerfiles" are valid and build fine, not whether particular version of Airflow works. Actually the best way is to add "setup.py" version when the image is committed, but use "latest released" when we run tests. Which I might well do. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
