From 1cac59ed6fd008b08a0ad5576b0bd3edc57f2509 Mon Sep 17 00:00:00 2001 From: Amogh Desai Date: Mon, 1 Apr 2024 19:26:43 +0530 Subject: [PATCH] Introducing --latest for generate-issue-content-helm-chart command (#38648) * Introducing --latest for generate-issue-content-helm-chart command * testing only * fetching tags * review comments from potiuk --- .github/workflows/helm-tests.yml | 6 ++- ...ment_generate-issue-content-helm-chart.svg | 40 +++++++++-------- ...ment_generate-issue-content-helm-chart.txt | 2 +- .../commands/release_management_commands.py | 44 ++++++++++++------- .../release_management_commands_config.py | 1 + .../src/airflow_breeze/utils/version_utils.py | 37 ++++++++++++++++ 6 files changed, 92 insertions(+), 38 deletions(-) create mode 100644 dev/breeze/src/airflow_breeze/utils/version_utils.py diff --git a/.github/workflows/helm-tests.yml b/.github/workflows/helm-tests.yml index 96597840e717d..0c18472648ff6 100644 --- a/.github/workflows/helm-tests.yml +++ b/.github/workflows/helm-tests.yml @@ -121,11 +121,13 @@ jobs: run: ./dev/sign.sh dist/airflow-*.tgz dist/airflow-*-source.tar.gz env: SIGN_WITH: dev@airflow.apache.org + - name: "Fetch Git Tags" + run: git fetch --tags - name: "Test helm chart issue generation automatically" # Adding same tags for now, will address in a follow-up run: > - breeze release-management generate-issue-content-helm-chart - --previous-release helm-chart/0.0.0dev0 --current-release helm-chart/0.0.0dev0 + breeze release-management generate-issue-content-helm-chart --limit-pr-count 10 + --latest --verbose - name: "Upload Helm artifacts" uses: actions/upload-artifact@v4 with: diff --git a/dev/breeze/doc/images/output_release-management_generate-issue-content-helm-chart.svg b/dev/breeze/doc/images/output_release-management_generate-issue-content-helm-chart.svg index 9cb4c5c6dbe1e..83d3bf3d73741 100644 --- a/dev/breeze/doc/images/output_release-management_generate-issue-content-helm-chart.svg +++ b/dev/breeze/doc/images/output_release-management_generate-issue-content-helm-chart.svg @@ -1,4 +1,4 @@ - + - + @@ -101,9 +99,12 @@ + + + - Command: release-management generate-issue-content-helm-chart + Command: release-management generate-issue-content-helm-chart @@ -119,19 +120,20 @@ Generates content for issue to test the helm chart release. ╭─ Generate issue flags ───────────────────────────────────────────────────────────────────────────────────────────────╮ ---github-tokenGitHub token used to authenticate. You can set omit it if you have GITHUB_TOKEN env         -variable set. Can be generated with:                                                        -https://github.com/settings/tokens/new?description=Read%20sssues&scopes=repo:status         -(TEXT)                                                                                      -*--previous-releasecommit reference (for example hash or tag) of the previous release.(TEXT)[required] -*--current-releasecommit reference (for example hash or tag) of the current release.(TEXT)[required] ---excluded-pr-listComa-separated list of PRs to exclude from the issue.(TEXT) ---limit-pr-countLimit PR count processes (useful for testing small subset of PRs).(INTEGER) -╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ -╭─ Common options ─────────────────────────────────────────────────────────────────────────────────────────────────────╮ ---verbose-vPrint verbose information about performed steps. ---help-hShow this message and exit. -╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ +--github-tokenGitHub token used to authenticate. You can set omit it if you have GITHUB_TOKEN env variable   +set. Can be generated with:                                                                    +https://github.com/settings/tokens/new?description=Read%20sssues&scopes=repo:status            +(TEXT)                                                                                         +--previous-releasecommit reference (for example hash or tag) of the previous release.(TEXT) +--current-releasecommit reference (for example hash or tag) of the current release.(TEXT) +--excluded-pr-listComa-separated list of PRs to exclude from the issue.(TEXT) +--limit-pr-countLimit PR count processes (useful for testing small subset of PRs).(INTEGER) +--latestRun the command against latest released version of airflow helm charts +╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ +╭─ Common options ─────────────────────────────────────────────────────────────────────────────────────────────────────╮ +--verbose-vPrint verbose information about performed steps. +--help-hShow this message and exit. +╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ diff --git a/dev/breeze/doc/images/output_release-management_generate-issue-content-helm-chart.txt b/dev/breeze/doc/images/output_release-management_generate-issue-content-helm-chart.txt index e9b6a70e80272..20d87ba8dfc30 100644 --- a/dev/breeze/doc/images/output_release-management_generate-issue-content-helm-chart.txt +++ b/dev/breeze/doc/images/output_release-management_generate-issue-content-helm-chart.txt @@ -1 +1 @@ -66451b1e0d4897113e3763e04d73b65e +3e0e080fa8422853ed7df3967725b35f diff --git a/dev/breeze/src/airflow_breeze/commands/release_management_commands.py b/dev/breeze/src/airflow_breeze/commands/release_management_commands.py index b714c0110322e..11e062252eaa2 100644 --- a/dev/breeze/src/airflow_breeze/commands/release_management_commands.py +++ b/dev/breeze/src/airflow_breeze/commands/release_management_commands.py @@ -155,6 +155,7 @@ run_command, ) from airflow_breeze.utils.shared_options import get_dry_run, get_verbose +from airflow_breeze.utils.version_utils import get_latest_airflow_version, get_latest_helm_chart_version from airflow_breeze.utils.versions import is_pre_release from airflow_breeze.utils.virtualenv_utils import create_pip_command, create_venv @@ -2290,13 +2291,11 @@ def print_issue_content( @click.option( "--previous-release", type=str, - required=True, help="commit reference (for example hash or tag) of the previous release.", ) @click.option( "--current-release", type=str, - required=True, help="commit reference (for example hash or tag) of the current release.", ) @click.option("--excluded-pr-list", type=str, help="Coma-separated list of PRs to exclude from the issue.") @@ -2306,6 +2305,11 @@ def print_issue_content( default=None, help="Limit PR count processes (useful for testing small subset of PRs).", ) +@click.option( + "--latest", + is_flag=True, + help="Run the command against latest released version of airflow helm charts", +) @option_verbose def generate_issue_content_helm_chart( github_token: str, @@ -2313,6 +2317,7 @@ def generate_issue_content_helm_chart( current_release: str, excluded_pr_list: str, limit_pr_count: int | None, + latest: bool, ): generate_issue_content( github_token, @@ -2321,7 +2326,7 @@ def generate_issue_content_helm_chart( excluded_pr_list, limit_pr_count, is_helm_chart=True, - latest=False, + latest=latest, ) @@ -3264,18 +3269,25 @@ def generate_issue_content( current = current_release if latest: - import requests - - response = requests.get("https://pypi.org/pypi/apache-airflow/json") - response.raise_for_status() - latest_released_version = response.json()["info"]["version"] - previous = str(latest_released_version) - current = os.getenv("VERSION", "HEAD") - if current == "HEAD": - get_console().print( - "\n[warning]Environment variable VERSION not set, setting current release " - "version as 'HEAD'\n" - ) + if is_helm_chart: + latest_helm_version = get_latest_helm_chart_version() + get_console().print(f"\n[info] Latest stable version of helm chart is {latest_helm_version}\n") + previous = f"helm-chart/{latest_helm_version}" + current = os.getenv("VERSION", "HEAD") + if current == "HEAD": + get_console().print( + "\n[warning]Environment variable VERSION not set, setting current release " + "version as 'HEAD' for helm chart release\n" + ) + else: + latest_airflow_version = get_latest_airflow_version() + previous = str(latest_airflow_version) + current = os.getenv("VERSION", "HEAD") + if current == "HEAD": + get_console().print( + "\n[warning]Environment variable VERSION not set, setting current release " + "version as 'HEAD'\n" + ) changes = get_changes(verbose, previous, current, is_helm_chart) change_prs = [change.pr for change in changes] @@ -3342,4 +3354,4 @@ def generate_issue_content( users[pr_number].add(linked_issue.user.login) progress.advance(task) - print_issue_content(current_release, pull_requests, linked_issues, users, is_helm_chart) + print_issue_content(current, pull_requests, linked_issues, users, is_helm_chart) diff --git a/dev/breeze/src/airflow_breeze/commands/release_management_commands_config.py b/dev/breeze/src/airflow_breeze/commands/release_management_commands_config.py index 97df6a77407c3..401347673725b 100644 --- a/dev/breeze/src/airflow_breeze/commands/release_management_commands_config.py +++ b/dev/breeze/src/airflow_breeze/commands/release_management_commands_config.py @@ -113,6 +113,7 @@ "--current-release", "--excluded-pr-list", "--limit-pr-count", + "--latest", ], } ], diff --git a/dev/breeze/src/airflow_breeze/utils/version_utils.py b/dev/breeze/src/airflow_breeze/utils/version_utils.py new file mode 100644 index 0000000000000..7b41fa46bdc57 --- /dev/null +++ b/dev/breeze/src/airflow_breeze/utils/version_utils.py @@ -0,0 +1,37 @@ +# 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 + + +def get_latest_helm_chart_version(): + import requests + + response = requests.get("https://airflow.apache.org/_gen/packages-metadata.json") + data = response.json() + for package in data: + if package["package-name"] == "helm-chart": + stable_version = package["stable-version"] + return stable_version + + +def get_latest_airflow_version(): + import requests + + response = requests.get("https://pypi.org/pypi/apache-airflow/json") + response.raise_for_status() + latest_released_version = response.json()["info"]["version"] + return latest_released_version