Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[workflow] Improve PR title checker for the release tag #1244

Merged
merged 3 commits into from Jun 17, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/persubmit.yml
Expand Up @@ -81,6 +81,7 @@ jobs:

- name: Run PR Title Checker
run: |
pip install semver GitPython
python misc/check_pr_title.py "$PR_TITLE"
env:
PR_TITLE: ${{ github.event.pull_request.title }}
48 changes: 43 additions & 5 deletions misc/check_pr_title.py
@@ -1,4 +1,18 @@
import sys, os, json
import sys, os, json, semver, git


def get_old_ver():
repo = git.Repo('.')
for c in repo.iter_commits('master', max_count=200):
if c.summary.startswith('[release]'):
ver = c.summary.split(']', maxsplit=1)[1]
if ver[0] == 'v':
ver = ver[1:]
ver = ver.split(' ')[0]
oldver = semver.VersionInfo.parse(ver)
return oldver
raise ValueError('Could not find old version!')
archibate marked this conversation as resolved.
Show resolved Hide resolved


title = sys.argv[1]
print(f'Checking PR title: {title}')
Expand Down Expand Up @@ -26,10 +40,6 @@
if x[1] == ' ':
exit(f'Extra space before: {x[2:]}')

x = title.split(']')[-1].strip()
if x[0].islower():
exit(f'PR title should be uppercase at: {x}')

had_upper = False
for x in title.split('] ')[:-1]:
if x[0] != '[':
Expand All @@ -43,4 +53,32 @@
exit(f'At most 1 uppercase tag expected, got: [{x[1:]}]')
had_upper = True

is_release = False
for x in title.split('] ')[:-1]:
x = x[1:]
if x.lower() == 'release':
is_release = True
if not x.islower():
exit(f'[release] must be lowercase, got: [{x}]')

if is_release:
ts = title.split(']')
if len(ts) != 2:
exit(f'Release PRs must have only one tag "[release]", got: {title}')
ver = ts[1][1:]
if ver[0] != 'v':
exit(f'Release version must be prepended with "v", got: {ver}')
archibate marked this conversation as resolved.
Show resolved Hide resolved
ver = ver[1:]
try:
ver = semver.VersionInfo.parse(ver)
except ValueError:
exit(f'Invalid SemVer version: {ver}')
oldver = get_old_ver()
if ver not in [oldver.bump_minor(), oldver.bump_patch()]:
exit(f'Version bump incorrect: {oldver} -> {ver}')
else:
x = title.split(']')[-1].strip()
if x[0].islower():
exit(f'PR title should be uppercase at: {x}')
archibate marked this conversation as resolved.
Show resolved Hide resolved

print('OK!')