Skip to content

Commit

Permalink
{CI} Add test py code (#7235)
Browse files Browse the repository at this point in the history
* add warning label
  • Loading branch information
AllyW committed Feb 1, 2024
1 parent edf4d02 commit b82353c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/VersionCalPRComment.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: Generate Release Version and Comment PR

on:
workflow_dispatch:
on:
pull_request_target:
types: [opened, labeled, unlabeled, synchronize]
paths:
Expand All @@ -12,7 +11,7 @@ permissions:

jobs:
version-cal:
if: startsWith(github.head_ref, 'auto-version')
if: contains(github.event.pull_request.labels.*.name, 'auto-cal-version')
runs-on: ubuntu-latest
steps:
- name: Set Init Version Message
Expand Down Expand Up @@ -94,6 +93,7 @@ jobs:
source ./env/bin/activate
echo github.event.pull_request.base.ref: ${{ github.event.pull_request.base.ref }}
git checkout ${{ github.event.pull_request.base.ref }}
mkdir ${base_meta_path}
for mod in `cat changed_modules`
do
echo **************************
Expand All @@ -106,6 +106,7 @@ jobs:
done
echo github.event.pull_request.head.ref: ${{ github.event.pull_request.head.ref }}
git checkout ${{ github.event.pull_request.head.ref }}
mkdir ${diff_meta_path}
for mod in `cat changed_modules`
do
echo **************************
Expand Down
29 changes: 21 additions & 8 deletions scripts/ci/release_version_cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

# pylint: disable=line-too-long
import os
from packaging.version import parse

Expand Down Expand Up @@ -63,11 +63,15 @@ def get_next_version_segment_tag():
return None


def add_suggest_header(comment_message):
comment_message.append("## :warning: Suggestions")


def gen_comment_message(mod, next_version, comment_message):
comment_message.append("### module: {0}".format(mod))
comment_message.append(" - suggested next version number in setup.py: {0}".format(next_version.get("version", "-")))
comment_message.append("### Module: {0}".format(mod))
comment_message.append(" - Update version to `{0}` in setup.py".format(next_version.get("version", "-")))
if next_version.get("has_preview_tag", False):
comment_message.append(' - azext_{0}/azext_metadata.json: "azext.isPreview": true,'.format(mod))
comment_message.append(' - Set `azext.isPreview` to `true` in azext_{0}/azext_metadata.json'.format(mod))


def add_label_hint_message(comment_message):
Expand All @@ -77,6 +81,13 @@ def add_label_hint_message(comment_message):
comment_message.append(" - Major/minor/patch/pre increment of version number is calculated by pull request "
"code changes automatically. "
"If needed, please add `major`/`minor`/`patch`/`pre` label to adjust it.")
comment_message.append(" - For more info about extension versioning, please refer to [Extension version schema](https://github.com/Azure/azure-cli/blob/release/doc/extensions/versioning_guidelines.md)")


def save_comment_message(cli_ext_path, file_name, comment_message):
with open(os.path.join(cli_ext_path, file_name), "w") as f:
for line in comment_message:
f.write(line + "\n")


def main():
Expand All @@ -91,11 +102,15 @@ def main():
print("output_file: ", output_file)
print("changed_module_list: ", changed_module_list)
print("pr_label_list: ", pr_label_list)
comment_message = []
if len(changed_module_list) == 0:
save_comment_message(cli_ext_path, output_file, comment_message)
return
next_version_pre_tag = get_next_version_pre_tag()
next_version_segment_tag = get_next_version_segment_tag()
print("next_version_pre_tag: ", next_version_pre_tag)
print("next_version_segment_tag: ", next_version_segment_tag)
comment_message = []
add_suggest_header(comment_message)
for mod in changed_module_list:
base_meta_file = os.path.join(cli_ext_path, base_meta_path, "az_" + mod + "_meta.json")
diff_meta_file = os.path.join(cli_ext_path, diff_meta_path, "az_" + mod + "_meta.json")
Expand Down Expand Up @@ -124,9 +139,7 @@ def main():
gen_comment_message(mod, next_version, comment_message)
add_label_hint_message(comment_message)
print(comment_message)
with open(os.path.join(cli_ext_path, output_file), "w") as f:
for line in comment_message:
f.write(line + "\n")
save_comment_message(cli_ext_path, output_file, comment_message)


if __name__ == '__main__':
Expand Down

0 comments on commit b82353c

Please sign in to comment.