build: limit check for edits of autogenerated files to only commits in a pull request

This commit is contained in:
albertony
2025-07-14 15:06:38 +02:00
parent da9c99272c
commit d1ac6c2fe1

View File

@ -4,7 +4,9 @@ This script checks for unauthorized modifications in autogenerated sections of m
It is designed to be used in a GitHub Actions workflow or a local pre-commit hook. It is designed to be used in a GitHub Actions workflow or a local pre-commit hook.
Features: Features:
- Detects markdown files changed between two commits (default last commit). - Detects markdown files changed between a commit and one of its ancestors. Default is to
check the last commit only. When triggered on a pull request it should typically compare the
pull request branch head and its merge base - the commit on the main branch before it diverged.
- Identifies modified autogenerated sections marked by specific comments. - Identifies modified autogenerated sections marked by specific comments.
- Reports violations using GitHub Actions error messages. - Reports violations using GitHub Actions error messages.
- Exits with a nonzero status code if unauthorized changes are found. - Exits with a nonzero status code if unauthorized changes are found.
@ -24,14 +26,14 @@ def get_changed_files(base, head):
""" """
Retrieve a list of markdown files that were changed between the base and head commits. Retrieve a list of markdown files that were changed between the base and head commits.
""" """
files = run_git(["diff", "--name-only", base, head]).splitlines() files = run_git(["diff", "--name-only", f"{base}...{head}"]).splitlines()
return [f for f in files if f.endswith(".md")] return [f for f in files if f.endswith(".md")]
def get_diff(file, base, head): def get_diff(file, base, head):
""" """
Get the diff of a given file between the base and head commits. Get the diff of a given file between the base and head commits.
""" """
return run_git(["diff", "-U0", base, head, "--", file]).splitlines() return run_git(["diff", "-U0", f"{base}...{head}", "--", file]).splitlines()
def get_file_content(ref, file): def get_file_content(ref, file):
""" """