diff options
-rw-r--r-- | .github/workflows/pr-conflicts.yml | 4 | ||||
-rwxr-xr-x | scripts/check-pr-title-and-commit-messages.py | 54 | ||||
-rwxr-xr-x | scripts/image-build/build-vyos-image | 2 |
3 files changed, 57 insertions, 3 deletions
diff --git a/.github/workflows/pr-conflicts.yml b/.github/workflows/pr-conflicts.yml index 96040cd6..2fd0bb42 100644 --- a/.github/workflows/pr-conflicts.yml +++ b/.github/workflows/pr-conflicts.yml @@ -6,10 +6,10 @@ on: jobs: Conflict_Check: name: 'Check PR status: conflicts and resolution' - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest steps: - name: check if PRs are dirty - uses: eps1lon/actions-label-merge-conflict@releases/2.x + uses: eps1lon/actions-label-merge-conflict@v3 with: dirtyLabel: "state: conflict" removeOnDirtyLabel: "state: conflict resolved" diff --git a/scripts/check-pr-title-and-commit-messages.py b/scripts/check-pr-title-and-commit-messages.py new file mode 100755 index 00000000..8fe3ca79 --- /dev/null +++ b/scripts/check-pr-title-and-commit-messages.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 + +import re +import sys +import time + +import requests + +# Use the same regex for PR title and commit messages for now +title_regex = r'^(([a-zA-Z\-_.]+:\s)?)T\d+:\s+[^\s]+.*' +commit_regex = title_regex + + +def check_pr_title(title): + if not re.match(title_regex, title): + print(f"PR title '{title}' does not match the required format!") + print("Valid title example: T99999: make IPsec secure") + sys.exit(1) + + +def check_commit_message(title): + if not re.match(commit_regex, title): + print("Commit title '{title}' does not match the required format!") + print("Valid title example: T99999: make IPsec secure") + sys.exit(1) + + +if __name__ == '__main__': + if len(sys.argv) < 2: + print("Please specify pull request URL!") + sys.exit(1) + + # There seems to be a race condition that causes this scripts to receive + # an incomplete PR object that is missing certain fields, + # which causes temporary CI failures that require re-running the script + # + # It's probably better to add a small delay to prevent that + time.sleep(5) + + # Get the pull request object + pr = requests.get(sys.argv[1]).json() + if "title" not in pr: + print("The PR object does not have a title field!") + print("Did not receive a valid pull request object, please check the URL!") + sys.exit(1) + + check_pr_title(pr["title"]) + + # Get the list of commits + commits = requests.get(pr["commits_url"]).json() + for c in commits: + # Retrieve every individual commit and check its title + co = requests.get(c["url"]).json() + check_commit_message(co["commit"]["message"]) diff --git a/scripts/image-build/build-vyos-image b/scripts/image-build/build-vyos-image index 3b265a01..e41b3eff 100755 --- a/scripts/image-build/build-vyos-image +++ b/scripts/image-build/build-vyos-image @@ -229,7 +229,7 @@ if __name__ == "__main__": sys.exit(1) # Validate characters in version name - if 'version' in args: + if 'version' in args and args['version'] != None: allowed = string.ascii_letters + string.digits + '.' + '-' + '+' if not set(args['version']) <= set(allowed): print(f'Version contained illegal character(s), allowed: {allowed}') |