From 4faf6d11b71255191a7a98ad5c71a2f5afd68a80 Mon Sep 17 00:00:00 2001 From: Milan Kolar Date: Fri, 17 Sep 2021 23:09:20 +0100 Subject: [PATCH 1/2] get release type from labels on github PR --- .github/workflows/prerelease.yml | 4 ++-- tools/ci_tools.py | 40 ++++++++++++++++++++++++++++---- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/.github/workflows/prerelease.yml b/.github/workflows/prerelease.yml index ddab0e59a8..0fb07be79d 100644 --- a/.github/workflows/prerelease.yml +++ b/.github/workflows/prerelease.yml @@ -20,12 +20,12 @@ jobs: python-version: 3.7 - name: Install Python requirements - run: pip install gitpython semver + run: pip install gitpython semver PyGithub - name: 🔎 Determine next version type id: version_type run: | - TYPE=$(python ./tools/ci_tools.py --bump) + TYPE=$(python ./tools/ci_tools.py --bump --github_token ${{ secrets.GITHUB_TOKEN }}) echo ::set-output name=type::$TYPE diff --git a/tools/ci_tools.py b/tools/ci_tools.py index 3c1aaae991..d087ee08e5 100644 --- a/tools/ci_tools.py +++ b/tools/ci_tools.py @@ -3,7 +3,31 @@ import sys from semver import VersionInfo from git import Repo from optparse import OptionParser +from github import Github +import os +def get_release_type_github(Log, github_token): + # print(Log) + minor_labels = ["type: feature", "type: deprecated"] + patch_labels = ["type: enhancement", "type: bug"] + + g = Github(github_token) + repo = g.get_repo("pypeclub/ci-testing") + + for line in Log.splitlines(): + print(line) + match = re.search("pull request #(\d+)", line) + if match: + pr_number = match.group(1) + pr = repo.get_pull(int(pr_number)) + for label in pr.labels: + print(label.name) + if label.name in minor_labels: + return ("minor") + elif label.name in patch_labels: + return("patch") + return None + def remove_prefix(text, prefix): return text[text.startswith(prefix) and len(prefix):] @@ -36,7 +60,7 @@ def get_log_since_tag(version): def release_type(log): regex_minor = ["feature/", "(feat)"] - regex_patch = ["bugfix/", "fix/", "(fix)", "enhancement/"] + regex_patch = ["bugfix/", "fix/", "(fix)", "enhancement/", "update"] for reg in regex_minor: if re.search(reg, log): return "minor" @@ -135,17 +159,23 @@ def main(): parser.add_option("-l", "--lastversion", dest="lastversion", action="store", help="work with explicit version") + parser.add_option("-g", "--github_token", + dest="github_token", action="store", + help="github token") (options, args) = parser.parse_args() if options.bump: - last_CI, last_CI_tag = get_last_version("CI") last_release, last_release_tag = get_last_version("release") - bump_type_CI = release_type(get_log_since_tag(last_CI_tag)) - bump_type_release = release_type(get_log_since_tag(last_release_tag)) - if bump_type_CI is None or bump_type_release is None: + bump_type_release = get_release_type_github( + get_log_since_tag(last_release_tag), + options.github_token + ) + if bump_type_release is None: print("skip") + else: + print(bump_type_release) if options.nightly: next_tag_v = calculate_next_nightly() From da5fca2aac36da5c40827bd377bf1a4081603765 Mon Sep 17 00:00:00 2001 From: Milan Kolar Date: Fri, 17 Sep 2021 23:10:33 +0100 Subject: [PATCH 2/2] get correct repo --- tools/ci_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/ci_tools.py b/tools/ci_tools.py index d087ee08e5..3e20c1b21c 100644 --- a/tools/ci_tools.py +++ b/tools/ci_tools.py @@ -12,7 +12,7 @@ def get_release_type_github(Log, github_token): patch_labels = ["type: enhancement", "type: bug"] g = Github(github_token) - repo = g.get_repo("pypeclub/ci-testing") + repo = g.get_repo("pypeclub/OpenPype") for line in Log.splitlines(): print(line)