Skip to content

Commit

Permalink
[workflow] Improve PR title checker for the release tag (#1244)
Browse files Browse the repository at this point in the history
* [skip ci] [workflow] Improve PR title checker for the release tag

* [skip ci] enforce code format

* [skip ci] Apply suggestions from code review

Co-authored-by: Yuanming Hu <yuanming-hu@users.noreply.github.com>

Co-authored-by: Taichi Gardener <taichigardener@gmail.com>
Co-authored-by: Yuanming Hu <yuanming-hu@users.noreply.github.com>
  • Loading branch information
3 people committed Jun 17, 2020
1 parent 59861fc commit 6963c30
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
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 an old version!')


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 start with "v", got: {ver}')
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 titles must start with uppercase letters: {x}')

print('OK!')

0 comments on commit 6963c30

Please sign in to comment.