potiuk commented on a change in pull request #18335:
URL: https://github.com/apache/airflow/pull/18335#discussion_r711366514



##########
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:
       Small update. I changed it to use "latest released"  version for tests 
rather than fixed - this way we will not have to maintain it - right after 
releasing a new version to PyPI the `docekr builds` will start using the new 
version - but they should just continue building in people's PR. if they will 
start failing, that means that we should fix it (so that should solve the 
problem @mik-laj mentioned). 
   
   This way we get an early warning system - if any of our "example extension 
Dockerfile" for any reason will stop working with latest released airflow, we 
will know it right after the new version has been released.
   
   This is also nice as it will flag the cases in case we pushed a new release 
to PyPI but forgot to release the image. There is a slight race - if someone 
makes PR between PyPI and image release, the Dockerfile test might fail - but 
that is really rare and should not be a problem if the release manager has fast 
build-push cycle.




-- 
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]


Reply via email to