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

[Sweep GHA Fix] Fix the failing GitHub Actions on 7c67f79 (main) #65

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
77 changes: 45 additions & 32 deletions scripts/check_changelog_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,46 +57,59 @@ def get_referenced_issues(pr_number):

# The above returns {'data': {'repository': {'pullRequest': {'closingIssuesReferences': {'edges': [{'node': {'number': 4944}}]}}}}}

ref_edges = ref_result["data"]["repository"]["pullRequest"][
"closingIssuesReferences"
]["edges"]

if not ref_edges:
return []

return [edge["node"]["number"] for edge in ref_edges if edge]

with open(file_name, "r", encoding="utf-8") as file:
for line in file:
line = line.strip()
if not is_valid_line(line):
print(f'Invalid entry in change log: "{line}"')
sys.exit(1)

# Check if a line matches any of the specified patterns
def is_valid_line(line):
patterns = [r"^Fixes:\s*.*$", r"^Implements:\s*.*$", r"^Thanks:\s*.*$"]
for pattern in patterns:
if re.match(pattern, line):
return True
return False
# Handle specific error related to QUOTED_LITERAL token
if "Unexpected QUOTED_LITERAL token" in line:
print("Error: Unexpected QUOTED_LITERAL token in change log")
sys.exit(1)

# The referenced issue number should be valid.
for issue_number in re.findall("#([0-9]+)", line):
issue_number = int(issue_number)
try:
issue = repo.get_issue(number=issue_number)
except github.UnknownObjectException:
print(
f"The changelog entry references an invalid issue #{issue_number}:\n{line}"
)
sys.exit(1)

def main():
github_token = os.environ.get("GITHUB_TOKEN")
as_pr = None
try:
as_pr = issue.as_pull_request()
except github.UnknownObjectException:
# Not a pull request
pass

if not github_token:
print("Please populate the GITHUB_TOKEN environment variable.")
sys.exit(1)
# Accept references to PR itself.
if as_pr:
if issue_number != this_pr_number:
print(
f"The changelog for PR #{this_pr_number} references another PR #{issue_number}"
)
sys.exit(1)
changelog_issues = pr_issues
else:
changelog_issues.add(issue_number)

github_obj = github.Github(github_token)
repo = github_obj.get_repo("timescale/timescaledb")
# Get the file name from the command line argument
if len(sys.argv) != 2:
print("Please provide a file name as a command-line argument.")
if changelog_issues != pr_issues:
print(
"Instead of "
+ (f"the issues {pr_issues}" if pr_issues else "no issues")
+ f" linked to the PR #{this_pr_number}, the changelog references "
+ (f"the issues {changelog_issues}" if changelog_issues else "no issues")
)
sys.exit(1)

file_name = sys.argv[1]
this_pr_number = int(os.environ["PR_NUMBER"])
pr_issues = set(get_referenced_issues(this_pr_number))

# Read the file and check non-empty lines
changelog_issues = set()
with open(file_name, "r", encoding="utf-8") as file:
if __name__ == "__main__":
main()
for line in file:
line = line.strip()
if not is_valid_line(line):
Expand Down
2 changes: 1 addition & 1 deletion scripts/cmake_format_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
SCRIPTDIR=$(cd "$(dirname $0)" || exit; pwd)
BASEDIR=$(dirname $SCRIPTDIR)

find $BASEDIR -name CMakeLists.txt -exec cmake-format -i {} +
find $BASEDIR -name CMakeLists.txt -exec cmake-format -i {} + || { echo 'Error: Failed to run cmake-format command'; exit 1; }
find $BASEDIR/src $BASEDIR/test $BASEDIR/tsl -name '*.cmake' -exec cmake-format -i {} +
Loading