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

[CI] Introduce draftversion checker #281

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,12 @@ jobs:
- uses: gaurav-nelson/github-action-markdown-link-check@v1
with:
config-file: '.github/workflows/markdown-link-check.json'

draftversion-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: check correctness of draftversion fields
run: python ./tools/acle_draftversion_value_check.py .
89 changes: 89 additions & 0 deletions tools/acle_draftversion_value_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
"""
"
" Copyright (C) 2023 Arm Ltd
"
"""

from pathlib import Path
import re
import subprocess
import sys


def get_modified_file_list(repo_path: Path) -> list[str]:
"""Use git to get the list of modified files in the patch set"""
starting_point = "origin/main"
cmd = ["git", "-C", str(repo_path), "diff", "--name-only", starting_point, "HEAD"]

try:
git_result = subprocess.run(args=cmd, capture_output=True, check=True)
except subprocess.CalledProcessError as ex:
print(
f"Error: in command '{' '.join(cmd)}':\n{ex.stderr.decode()}",
file=sys.stderr,
)
sys.exit(1)

modified_files = git_result.stdout.decode().split("\n")
modified_files = [x for x in modified_files if x]
return modified_files


def check_file(file_path: Path) -> bool:
"""Check if file has a draftversion field, and if so, that it's set to true"""
with file_path.open() as file:
print(f"Checking file {file_path}")
for line in file:
re_result = re.search(r"draftversion: (\w+)", line)
if not re_result:
continue

value = re_result[1]
if value != "true":
print(
f"Error: file {file_path} has been modified but its draftversion"
" isn't set to true!",
file=sys.stderr,
)
return False

return True


def main() -> int:
"""Check if any modified file has the wrong value for draftversion"""
if len(sys.argv) != 2:
print(
"Error: this script takes a single positional argument, which is the path"
" to the ACLE repository!",
file=sys.stderr,
)
sys.exit(1)

try:
repo_path = Path(sys.argv[1]).resolve(strict=True)
except FileNotFoundError:
print(f"Error: repository {sys.argv[1]} doesn't exist!", file=sys.stderr)
sys.exit(1)

modified_files = get_modified_file_list(repo_path)
print("Files to check:")
if not modified_files:
print(" none")
else:
for path in modified_files:
print(f" - {path}")
print()

success = True
for path in modified_files:
complete_path = repo_path / Path(path)
success = check_file(complete_path) and success

print("\nEnd result: " + ("OK" if success else "issues found"))

return not success


if __name__ == "__main__":
sys.exit(main())
Loading