Skip to content

Commit

Permalink
Adds automation around Changelog & Constraints (#262)
Browse files Browse the repository at this point in the history
This commit adds the automation (included in pre-commit) for the followings:

- Updates the constraints URL when releasing a version. E.g when releasing a version we should use a pinned constraint URL (https://github.com/apache/airflow/blob/constraints-2.1.0/constraints-3.6.txt instead of Moving which is https://github.com/apache/airflow/blob/constraints-2-0/constraints-3.6.txt).
- Verifies that a CHANGELOG.md file is created within each Airflow version folder and contains entry for each AC Version
- Adds CHANGELOG.md link in README.md
  • Loading branch information
kaxil committed May 22, 2021
1 parent 2cb7f7f commit 3ac70d7
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
71 changes: 71 additions & 0 deletions .circleci/generate_circleci_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def main():
"""

replace_version_info()
verify_changelog_entry()

config_path = os.path.join(circle_directory, "config.yml")

Expand All @@ -73,11 +74,13 @@ def replace_version_info():
Replace the VERSION in all the Dockerfiles with the corresponding VERSION in IMAGE_MAP
"""
for ac_version, distros in IMAGE_MAP.items():
dev_version = False
airflow_version = get_airflow_version(ac_version)
for distro in distros:
file_name = os.path.join(project_directory, airflow_version, distro, "Dockerfile")

if "dev" in ac_version:
dev_version = True
if airflow_version not in DEV_ALLOWLIST:
ac_version = ac_version.replace("dev", "*")

Expand All @@ -98,9 +101,77 @@ def replace_version_info():
flags=re.MULTILINE
)

# Replace Moving Constraints Version to a tag for "non-dev" version (e.g constraints-2.1.0)
# For Dev versions we use a moving constraints branch (e.g constraints-2-1)
# We only do this for all buster images
if dev_version:
branch = "-".join(airflow_version.split(".", 3)[0:2])
constraints_url = (
f'https://raw.githubusercontent.com/apache/airflow/constraints-{branch}/'
'constraints-${PYTHON_MAJOR_MINOR_VERSION}.txt'
)
else:
constraints_url = (
'https://raw.githubusercontent.com/apache/airflow/constraints-${AIRFLOW_VERSION}/'
'constraints-${PYTHON_MAJOR_MINOR_VERSION}.txt'
)
if "alpine3.10" not in distros:
new_text = re.sub(
r'https://raw.githubusercontent.com/apache/airflow/constraints-(.*)/constraints-(.*).txt',
constraints_url,
new_text,
flags=re.MULTILINE
)

with open(file_name, "w") as f:
f.write(new_text)


def verify_changelog_entry():
"""
Verify that CHANGELOG.md file has been created for each Airflow version. Also adds
links for all these CHANGELOG.md files in README.md
"""
readme_changelog_links = (
"## Changelog\n\n"
"All changes applied to available point releases will be documented "
"in the `CHANGELOG.md` files within each version folder:\n"
)

for ac_version, distros in IMAGE_MAP.items():
airflow_version = get_airflow_version(ac_version)

if "dev" not in ac_version:
# Check that Changelog entry for this Airflow Version has been created
changelog_path = os.path.join(project_directory, airflow_version, "CHANGELOG.md")
assert os.path.exists(changelog_path), f"Please add the Changelog.md file for {ac_version}"

# Changelog Readme URL to include
readme_changelog_links += (
f"- [{airflow_version} Changelog]"
f"(https://github.com/astronomer/ap-airflow/blob/master/{airflow_version}/CHANGELOG.md)\n"
)

with open(changelog_path) as changelog_file:
changelog_contents = changelog_file.read()

# Replace AC Version
assert f"Astronomer Certified {ac_version}" in changelog_contents, \
f"Please add Changelog entry for {ac_version} in {changelog_path}"

# Update the Changelog URLs in README.md
with open(os.path.join(project_directory, "README.md"), "r") as readme_file:
readme_contents = readme_file.read()
new_readme_text = re.sub(
r'<!-- CHANGELOG START -->([\s\S]*)<!-- CHANGELOG END -->',
f'<!-- CHANGELOG START -->\n{readme_changelog_links}<!-- CHANGELOG END -->',
readme_contents,
flags=re.MULTILINE
)

with open(os.path.join(project_directory, "README.md"), "w") as readme_file:
readme_file.write(new_readme_text)


if __name__ == "__main__":
main()
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,19 @@ including latest security patches. This tag is "floating" or movable.
* Source Code: <https://github.com/astronomer/ap-airflow>
* Issue Tracker: <https://github.com/astronomer/ap-airflow/issues>

<!-- CHANGELOG START -->
## Changelog

All changes applied to available point releases will be documented in the `CHANGELOG.md` files within each version folder:
- [1.10.7 Changelog](https://github.com/astronomer/ap-airflow/blob/master/1.10.7/CHANGELOG.md)
- [1.10.10 Changelog](https://github.com/astronomer/ap-airflow/blob/master/1.10.10/CHANGELOG.md)
- [1.10.12 Changelog](https://github.com/astronomer/ap-airflow/blob/master/1.10.12/CHANGELOG.md)
- [1.10.14 Changelog](https://github.com/astronomer/ap-airflow/blob/master/1.10.14/CHANGELOG.md)
- [1.10.15 Changelog](https://github.com/astronomer/ap-airflow/blob/master/1.10.15/CHANGELOG.md)
- [2.0.0 Changelog](https://github.com/astronomer/ap-airflow/blob/master/2.0.0/CHANGELOG.md)
- [2.0.2 Changelog](https://github.com/astronomer/ap-airflow/blob/master/2.0.2/CHANGELOG.md)
- [2.1.0 Changelog](https://github.com/astronomer/ap-airflow/blob/master/2.1.0/CHANGELOG.md)
<!-- CHANGELOG END -->

## Testing

Expand Down

0 comments on commit 3ac70d7

Please sign in to comment.