Skip to content

Commit 193ce49

Browse files
github: workflows: Enable PR checks (#2143)
Signed-off-by: Hamza Butt <hamza.butt@arm.com>
1 parent 47b2b9b commit 193ce49

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed

.github/automation/pr-title-check.py

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/python3
2+
3+
# *******************************************************************************
4+
# Copyright 2024 Arm Limited and affiliates.
5+
# SPDX-License-Identifier: Apache-2.0
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
# *******************************************************************************
19+
20+
import argparse
21+
22+
23+
# * Ensuring the scopes end in colon and same level scopes are comma delimited.
24+
# TODO: Limit scopes to an acceptable list of tags.
25+
def __scopeCheck(msg: str):
26+
firstLine = (msg.partition("\n")[0]).strip()
27+
28+
if not ":" in firstLine:
29+
raise ValueError(
30+
f"Please see contribution guidelines. First line must contain a scope ending in a colon. Got: {firstLine}"
31+
)
32+
33+
# The last element of the split is the title, which we don't care about. Remove it.
34+
scopesArray = firstLine.split(":")[:-1]
35+
print("---")
36+
print(f"Scopes: {scopesArray}")
37+
38+
for scopes in scopesArray:
39+
print("---")
40+
print(f"Same-level scope: {scopes}")
41+
numWords = len(scopes.split())
42+
numCommas = scopes.count(",")
43+
print(f"Number of words in scope: {numWords}")
44+
print(f"Number of commas in scope: {numCommas}")
45+
46+
if numWords != numCommas + 1:
47+
raise ValueError(
48+
f"Please see contribution guidelines. Same-level scopes must be seperated by a comma. If this is true then words == commas + 1."
49+
)
50+
51+
52+
# * Ensuring a character limit for the first line.
53+
def __numCharacterCheck(msg: str):
54+
summary = msg.partition("\n")[0]
55+
msgSummaryLen = len(summary)
56+
if msgSummaryLen >= 72:
57+
raise ValueError(
58+
f"Please see contribution guidelines. Message summary must be less than 72. Got: {msgSummaryLen}"
59+
)
60+
61+
62+
def main():
63+
parser = argparse.ArgumentParser()
64+
parser.add_argument("msg", help="Commit message to check.")
65+
args = parser.parse_args()
66+
msg: str = args.msg
67+
print(f"msg: {msg}")
68+
__numCharacterCheck(msg)
69+
__scopeCheck(msg)
70+
71+
72+
if __name__ == "__main__":
73+
main()

.github/workflows/pr-check.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# *******************************************************************************
2+
# Copyright 2024 Arm Limited and affiliates.
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
# *******************************************************************************
17+
18+
name: "PR Checks"
19+
20+
on:
21+
pull_request:
22+
types: [opened, edited, synchronize, reopened]
23+
24+
# Declare default permissions as read only.
25+
permissions: read-all
26+
27+
jobs:
28+
title:
29+
runs-on: ubuntu-latest
30+
steps:
31+
- uses: actions/checkout@v4
32+
- name: Pass pull request title through script.
33+
run: python3 ./.github/automation/pr-title-check.py "${{ github.event.pull_request.title }}"

0 commit comments

Comments
 (0)