Skip to content

Commit

Permalink
github: workflows: Enable PR checks
Browse files Browse the repository at this point in the history
- Enforce that the length of the commit title is at most 72.
- Enforce that the first word of the PR is followed by a colon.

Signed-off-by: Hamza Butt <[email protected]>
  • Loading branch information
theComputeKid committed Oct 2, 2024
1 parent a760af4 commit 1f6a871
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 0 deletions.
73 changes: 73 additions & 0 deletions .github/automation/pr-title-check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/python3

# *******************************************************************************
# Copyright 2024 Arm Limited and affiliates.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# *******************************************************************************

import argparse


# * Ensuring the scopes end in colon and same level scopes are comma delimited.
# TODO: Limit scopes to an acceptable list of tags.
def __scopeCheck(msg: str):
firstLine = (msg.partition("\n")[0]).strip()

if not ":" in firstLine:
raise ValueError(
f"Please see contribution guidelines. First line must contain a scope ending in a colon. Got: {firstLine}"
)

# The last element of the split is the title, which we don't care about. Remove it.
scopesArray = firstLine.split(":")[:-1]
print("---")
print(f"Scopes: {scopesArray}")

for scopes in scopesArray:
print("---")
print(f"Same-level scope: {scopes}")
numWords = len(scopes.split())
numCommas = scopes.count(",")
print(f"Number of words in scope: {numWords}")
print(f"Number of commas in scope: {numCommas}")

if numWords != numCommas + 1:
raise ValueError(
f"Please see contribution guidelines. Same-level scopes must be seperated by a comma. If this is true then words == commas + 1."
)


# * Ensuring a character limit for the first line.
def __numCharacterCheck(msg: str):
summary = msg.partition("\n")[0]
msgSummaryLen = len(summary)
if msgSummaryLen >= 72:
raise ValueError(
f"Please see contribution guidelines. Message summary must be less than 72. Got: {msgSummaryLen}"
)


def main():
parser = argparse.ArgumentParser()
parser.add_argument("msg", help="Commit message to check.")
args = parser.parse_args()
msg: str = args.msg
print(f"msg: {msg}")
__numCharacterCheck(msg)
__scopeCheck(msg)


if __name__ == "__main__":
main()
33 changes: 33 additions & 0 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# *******************************************************************************
# Copyright 2024 Arm Limited and affiliates.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# *******************************************************************************

name: "PR Checks"

on:
pull_request:
types: [opened, edited, synchronize, reopened]

# Declare default permissions as read only.
permissions: read-all

jobs:
title:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Pass pull request title through script.
run: python3 ./.github/automation/pr-title-check.py "${{ github.event.pull_request.title }}"

0 comments on commit 1f6a871

Please sign in to comment.