2020-05-25 12:49:36 +02:00
|
|
|
############################################################################
|
|
|
|
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
|
|
|
#
|
2021-06-03 08:37:05 +02:00
|
|
|
# SPDX-License-Identifier: MPL-2.0
|
|
|
|
#
|
2020-05-25 12:49:36 +02:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
2020-09-14 16:20:40 -07:00
|
|
|
# file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
2020-05-25 12:49:36 +02:00
|
|
|
#
|
|
|
|
# See the COPYRIGHT file distributed with this work for additional
|
|
|
|
# information regarding copyright ownership.
|
|
|
|
############################################################################
|
|
|
|
|
2023-08-30 13:51:05 +02:00
|
|
|
import glob
|
2022-11-04 13:05:29 +01:00
|
|
|
import os
|
2020-05-25 12:49:36 +02:00
|
|
|
import re
|
|
|
|
|
2022-11-04 13:05:29 +01:00
|
|
|
import gitlab
|
|
|
|
|
2020-05-25 12:49:36 +02:00
|
|
|
# Helper functions and variables
|
|
|
|
|
2022-06-07 16:27:23 +02:00
|
|
|
|
2020-05-25 12:49:36 +02:00
|
|
|
def added_lines(target_branch, paths):
|
|
|
|
import subprocess
|
2022-06-07 16:27:23 +02:00
|
|
|
|
2023-12-07 13:23:22 +01:00
|
|
|
# Hazard fetches the target branch itself, so there is no need to fetch it
|
|
|
|
# explicitly using `git fetch --depth 1000 origin <target_branch>`. The
|
|
|
|
# refs/remotes/origin/<target_branch> ref is also expected to be readily
|
|
|
|
# usable by the time this file is executed.
|
|
|
|
|
2022-06-07 16:27:23 +02:00
|
|
|
diff = subprocess.check_output(
|
2023-12-07 13:23:22 +01:00
|
|
|
["/usr/bin/git", "diff", f"origin/{target_branch}...", "--"] + paths
|
2022-06-07 16:27:23 +02:00
|
|
|
)
|
2020-05-25 12:49:36 +02:00
|
|
|
added_lines = []
|
|
|
|
for line in diff.splitlines():
|
2022-06-07 16:27:23 +02:00
|
|
|
if line.startswith(b"+") and not line.startswith(b"+++"):
|
2020-05-25 12:49:36 +02:00
|
|
|
added_lines.append(line)
|
|
|
|
return added_lines
|
|
|
|
|
2022-06-07 16:27:23 +02:00
|
|
|
|
2021-01-18 14:57:47 +01:00
|
|
|
def lines_containing(lines, string):
|
2022-06-07 16:27:23 +02:00
|
|
|
return [l for l in lines if bytes(string, "utf-8") in l]
|
|
|
|
|
2021-01-18 14:57:47 +01:00
|
|
|
|
2022-06-07 16:27:23 +02:00
|
|
|
changes_issue_or_mr_id_regex = re.compile(rb"\[(GL [#!]|RT #)[0-9]+\]")
|
|
|
|
relnotes_issue_or_mr_id_regex = re.compile(rb":gl:`[#!][0-9]+`")
|
|
|
|
release_notes_regex = re.compile(r"doc/(arm|notes)/notes-.*\.(rst|xml)")
|
2024-03-07 16:41:46 +01:00
|
|
|
rdata_regex = re.compile(r"lib/dns/rdata/")
|
2020-05-25 12:49:36 +02:00
|
|
|
|
|
|
|
modified_files = danger.git.modified_files
|
2023-08-30 13:51:05 +02:00
|
|
|
affected_files = (
|
|
|
|
danger.git.modified_files + danger.git.created_files + danger.git.deleted_files
|
|
|
|
)
|
2020-05-25 12:49:36 +02:00
|
|
|
mr_labels = danger.gitlab.mr.labels
|
2024-06-03 13:07:21 +02:00
|
|
|
source_branch = danger.gitlab.mr.source_branch
|
2020-05-25 12:49:36 +02:00
|
|
|
target_branch = danger.gitlab.mr.target_branch
|
2022-12-15 17:39:58 +01:00
|
|
|
is_backport = "Backport" in mr_labels or "Backport::Partial" in mr_labels
|
|
|
|
is_full_backport = is_backport and "Backport::Partial" not in mr_labels
|
2020-05-25 12:49:36 +02:00
|
|
|
|
2022-11-04 13:05:29 +01:00
|
|
|
gl = gitlab.Gitlab(
|
|
|
|
url=f"https://{os.environ['CI_SERVER_HOST']}",
|
2024-05-24 15:50:31 +02:00
|
|
|
private_token=os.environ["BIND_TEAM_API_TOKEN"],
|
2022-11-04 13:05:29 +01:00
|
|
|
)
|
|
|
|
proj = gl.projects.get(os.environ["CI_PROJECT_ID"])
|
|
|
|
mr = proj.mergerequests.get(os.environ["CI_MERGE_REQUEST_IID"])
|
|
|
|
|
2024-06-03 13:07:21 +02:00
|
|
|
###############################################################################
|
|
|
|
# BRANCH NAME
|
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# - FAIL if the source branch of the merge request includes an old-style
|
|
|
|
# "-v9_x" or "-v9.x" suffix.
|
|
|
|
|
|
|
|
branch_name_regex = r"^(?P<base>.*?)(?P<suffix>-v9[_.](?P<version>[0-9]+))$"
|
|
|
|
match = re.match(branch_name_regex, source_branch)
|
|
|
|
if match:
|
|
|
|
fail(
|
|
|
|
f"Source branch name `{source_branch}` includes an old-style version "
|
|
|
|
f"suffix (`{match.group('suffix')}`). Using such suffixes is now "
|
|
|
|
"deprecated. Please resubmit the merge request with the branch name "
|
|
|
|
f"set to `{match.group('base')}-bind-9.{match.group('version')}`."
|
|
|
|
)
|
|
|
|
|
2020-05-25 12:49:36 +02:00
|
|
|
###############################################################################
|
|
|
|
# COMMIT MESSAGES
|
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# - FAIL if any of the following is true for any commit on the MR branch:
|
|
|
|
#
|
2023-01-27 12:43:45 +11:00
|
|
|
# * The subject line starts with "fixup!", "amend!" or "Apply suggestion".
|
2020-05-25 12:49:36 +02:00
|
|
|
#
|
Detect work-in-progress commits in danger CI
To avoid accidentally merging unfinished work, detect prohibited
keywords at the start of the subject line. If the first word is any of
the following, fail the check:
WIP, wip, DROP, drop, TODO, todo
The only slightly controversial is the lowercase "drop" which might have
a legitimate use - seems like four commits in the history used it as a
start of a sentence. However, since people commonly use "drop" to
indicate a commit should be dropped before merging, let's prohibit it as
well. In case of false-positive, "Drop" with a capitalized first letter
can always be used.
2022-11-07 14:18:55 +01:00
|
|
|
# * The subject line starts with a prohibited word indicating a work in
|
|
|
|
# progress commit (e.g. "WIP").
|
|
|
|
#
|
2021-01-18 14:57:47 +01:00
|
|
|
# * The subject line contains a trailing dot.
|
|
|
|
#
|
2020-05-25 12:49:36 +02:00
|
|
|
# * There is no empty line between the subject line and the log message.
|
|
|
|
#
|
|
|
|
# - WARN if any of the following is true for any commit on the MR branch:
|
|
|
|
#
|
2021-01-18 14:57:47 +01:00
|
|
|
# * The length of the subject line for a non-merge commit exceeds 72
|
|
|
|
# characters.
|
2020-05-25 12:49:36 +02:00
|
|
|
#
|
2021-01-18 14:57:47 +01:00
|
|
|
# * There is no log message present (i.e. commit only has a subject) and
|
|
|
|
# the subject line does not contain any of the following strings:
|
|
|
|
# "fixup!", " CHANGES ", " release note".
|
2020-05-25 12:49:36 +02:00
|
|
|
#
|
|
|
|
# * Any line of the log message is longer than 72 characters. This rule is
|
2021-01-18 14:57:47 +01:00
|
|
|
# not evaluated for:
|
|
|
|
#
|
|
|
|
# - lines starting with four spaces, which allows long lines to be
|
|
|
|
# included in the commit log message by prefixing them with four
|
|
|
|
# spaces (useful for pasting compiler warnings, static analyzer
|
|
|
|
# messages, log lines, etc.),
|
|
|
|
#
|
|
|
|
# - lines which contain references (i.e. those starting with "[1]",
|
|
|
|
# "[2]", etc.) which allows e.g. long URLs to be included in the
|
|
|
|
# commit log message.
|
2020-05-25 12:49:36 +02:00
|
|
|
|
Detect work-in-progress commits in danger CI
To avoid accidentally merging unfinished work, detect prohibited
keywords at the start of the subject line. If the first word is any of
the following, fail the check:
WIP, wip, DROP, drop, TODO, todo
The only slightly controversial is the lowercase "drop" which might have
a legitimate use - seems like four commits in the history used it as a
start of a sentence. However, since people commonly use "drop" to
indicate a commit should be dropped before merging, let's prohibit it as
well. In case of false-positive, "Drop" with a capitalized first letter
can always be used.
2022-11-07 14:18:55 +01:00
|
|
|
PROHIBITED_WORDS_RE = re.compile(
|
|
|
|
"^(WIP|wip|DROP|drop|DROPME|checkpoint|experiment|TODO|todo)[^a-zA-Z]"
|
|
|
|
)
|
2021-01-18 14:57:47 +01:00
|
|
|
fixup_error_logged = False
|
2020-05-25 12:49:36 +02:00
|
|
|
for commit in danger.git.commits:
|
|
|
|
message_lines = commit.message.splitlines()
|
|
|
|
subject = message_lines[0]
|
2023-09-06 09:52:12 +00:00
|
|
|
is_merge = subject.startswith("Merge branch ")
|
|
|
|
is_fixup = (
|
2023-01-27 12:43:45 +11:00
|
|
|
subject.startswith("fixup!")
|
|
|
|
or subject.startswith("amend!")
|
|
|
|
or subject.startswith("Apply suggestion")
|
2023-09-06 09:52:12 +00:00
|
|
|
)
|
|
|
|
if not fixup_error_logged and is_fixup:
|
2022-06-07 16:27:23 +02:00
|
|
|
fail(
|
|
|
|
"Fixup commits are still present in this merge request. "
|
|
|
|
"Please squash them before merging."
|
|
|
|
)
|
2021-01-18 14:57:47 +01:00
|
|
|
fixup_error_logged = True
|
Detect work-in-progress commits in danger CI
To avoid accidentally merging unfinished work, detect prohibited
keywords at the start of the subject line. If the first word is any of
the following, fail the check:
WIP, wip, DROP, drop, TODO, todo
The only slightly controversial is the lowercase "drop" which might have
a legitimate use - seems like four commits in the history used it as a
start of a sentence. However, since people commonly use "drop" to
indicate a commit should be dropped before merging, let's prohibit it as
well. In case of false-positive, "Drop" with a capitalized first letter
can always be used.
2022-11-07 14:18:55 +01:00
|
|
|
match = PROHIBITED_WORDS_RE.search(subject)
|
|
|
|
if match:
|
|
|
|
fail(
|
|
|
|
f"Prohibited keyword `{match.groups()[0]}` detected "
|
|
|
|
f"at the start of a subject line in commit {commit.sha}."
|
|
|
|
)
|
2023-09-06 09:52:12 +00:00
|
|
|
if len(subject) > 72 and not is_merge and not is_fixup:
|
2020-05-25 12:49:36 +02:00
|
|
|
warn(
|
2022-06-07 16:27:23 +02:00
|
|
|
f"Subject line for commit {commit.sha} is too long: "
|
|
|
|
f"```{subject}``` ({len(subject)} > 72 characters)."
|
2020-05-25 12:49:36 +02:00
|
|
|
)
|
2022-06-07 16:27:23 +02:00
|
|
|
if subject[-1] == ".":
|
|
|
|
fail(f"Trailing dot found in the subject of commit {commit.sha}.")
|
2020-05-25 12:49:36 +02:00
|
|
|
if len(message_lines) > 1 and message_lines[1]:
|
2022-06-07 16:27:23 +02:00
|
|
|
fail(f"No empty line after subject for commit {commit.sha}.")
|
|
|
|
if (
|
|
|
|
len(message_lines) < 3
|
|
|
|
and "fixup! " not in subject
|
2023-01-26 13:04:40 +01:00
|
|
|
and "CHANGES " not in subject
|
|
|
|
and "release note" not in subject.lower()
|
|
|
|
and "GL #" not in subject
|
2022-06-07 16:27:23 +02:00
|
|
|
):
|
|
|
|
warn(f"Please write a log message for commit {commit.sha}.")
|
2020-05-25 12:49:36 +02:00
|
|
|
for line in message_lines[2:]:
|
2022-06-07 16:27:23 +02:00
|
|
|
if (
|
|
|
|
len(line) > 72
|
|
|
|
and not line.startswith(" ")
|
|
|
|
and not re.match(r"\[[0-9]+\]", line)
|
|
|
|
):
|
2020-05-25 12:49:36 +02:00
|
|
|
warn(
|
2022-06-07 16:27:23 +02:00
|
|
|
f"Line too long in log message for commit {commit.sha}: "
|
|
|
|
f"```{line}``` ({len(line)} > 72 characters)."
|
2020-05-25 12:49:36 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# MILESTONE
|
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# FAIL if the merge request is not assigned to any milestone.
|
|
|
|
|
|
|
|
if not danger.gitlab.mr.milestone:
|
2022-06-07 16:27:23 +02:00
|
|
|
fail("Please assign this merge request to a milestone.")
|
2020-05-25 12:49:36 +02:00
|
|
|
|
|
|
|
###############################################################################
|
2022-12-15 17:39:58 +01:00
|
|
|
# BACKPORT & VERSION LABELS
|
2020-05-25 12:49:36 +02:00
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# FAIL if any of the following is true for the merge request:
|
|
|
|
#
|
2024-06-03 13:07:21 +02:00
|
|
|
# * The MR is marked as a Backport and has any "Affects v9.x" label(s) set.
|
|
|
|
#
|
2022-12-15 17:39:58 +01:00
|
|
|
# * The MR is marked as Backport and the number of version labels set is
|
2020-05-25 12:49:36 +02:00
|
|
|
# different than 1. (For backports, the version label is used for indicating
|
|
|
|
# its target branch. This is a rather ugly attempt to address a UI
|
|
|
|
# deficiency - the target branch for each MR is not visible on milestone
|
|
|
|
# dashboards.)
|
|
|
|
#
|
2022-12-15 17:39:58 +01:00
|
|
|
# * The MR is not marked as "Backport" nor any version label is set. (If the
|
|
|
|
# merge request is not a backport, version labels are used for indicating
|
2020-05-25 12:49:36 +02:00
|
|
|
# backporting preferences.)
|
2022-12-15 17:45:54 +01:00
|
|
|
#
|
|
|
|
# * The Backport MR doesn't have target branch in the merge request title.
|
2022-12-15 17:48:34 +01:00
|
|
|
#
|
|
|
|
# * The Backport MR doesn't link to the original MR is its description.
|
2022-12-15 17:51:24 +01:00
|
|
|
#
|
|
|
|
# * The original MR linked to from Backport MR hasn't been merged.
|
2020-05-25 12:49:36 +02:00
|
|
|
|
2022-12-15 17:48:34 +01:00
|
|
|
BACKPORT_OF_RE = re.compile(
|
|
|
|
r"Backport\s+of.*(merge_requests/|!)([0-9]+)", flags=re.IGNORECASE
|
|
|
|
)
|
2022-12-19 14:43:16 +01:00
|
|
|
VERSION_LABEL_RE = re.compile(r"v9.([0-9]+)(-S)?")
|
2022-06-07 16:27:23 +02:00
|
|
|
version_labels = [l for l in mr_labels if l.startswith("v9.")]
|
2022-12-19 15:14:48 +01:00
|
|
|
affects_labels = [l for l in mr_labels if l.startswith("Affects v9.")]
|
2022-12-15 17:45:54 +01:00
|
|
|
if is_backport:
|
2024-06-03 13:07:21 +02:00
|
|
|
if affects_labels:
|
|
|
|
fail("Backports must not have any *Affects v9.x* labels set.")
|
2022-12-15 17:45:54 +01:00
|
|
|
if len(version_labels) != 1:
|
|
|
|
fail(
|
|
|
|
"This MR was marked as *Backport*. "
|
|
|
|
"Please also set exactly one version label (*v9.x*)."
|
|
|
|
)
|
|
|
|
else:
|
2022-12-19 14:43:16 +01:00
|
|
|
minor_ver, edition = VERSION_LABEL_RE.search(version_labels[0]).groups()
|
|
|
|
edition = "" if edition is None else edition
|
|
|
|
title_re = f"^\\[9.{minor_ver}{edition}\\]"
|
|
|
|
match = re.search(title_re, danger.gitlab.mr.title)
|
|
|
|
if match is None:
|
2022-12-15 17:45:54 +01:00
|
|
|
fail(
|
2022-12-19 14:43:16 +01:00
|
|
|
"Backport MRs must have their target version in the title. "
|
|
|
|
f"Please put `[9.{minor_ver}{edition}]` at the start of the MR title."
|
2022-12-15 17:45:54 +01:00
|
|
|
)
|
2023-12-08 16:31:46 +01:00
|
|
|
backport_desc = BACKPORT_OF_RE.search(danger.gitlab.mr.description or "")
|
2022-12-15 17:48:34 +01:00
|
|
|
if backport_desc is None:
|
|
|
|
fail(
|
|
|
|
"Backport MRs must link to the original MR. Please put "
|
|
|
|
"`Backport of MR !XXXX` in the MR description."
|
|
|
|
)
|
2022-12-15 17:51:24 +01:00
|
|
|
else: # backport MR is linked to original MR
|
|
|
|
original_mr_id = backport_desc.groups()[1]
|
|
|
|
original_mr = proj.mergerequests.get(original_mr_id)
|
|
|
|
if original_mr.state != "merged":
|
|
|
|
fail(
|
|
|
|
f"Original MR !{original_mr_id} has not been merged. "
|
|
|
|
"Please re-run `danger` check once it's merged."
|
|
|
|
)
|
2022-12-15 17:52:52 +01:00
|
|
|
else: # check for commit IDs once original MR is merged
|
|
|
|
original_mr_commits = list(original_mr.commits(all=True))
|
|
|
|
backport_mr_commits = list(mr.commits(all=True))
|
|
|
|
for orig_commit in original_mr_commits:
|
|
|
|
for backport_commit in backport_mr_commits:
|
|
|
|
if orig_commit.id in backport_commit.message:
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
msg = (
|
|
|
|
f"Commit {orig_commit.id} from original MR !{original_mr_id} "
|
|
|
|
"is not referenced in any of the backport commits."
|
|
|
|
)
|
|
|
|
if not is_full_backport:
|
|
|
|
message(msg)
|
|
|
|
else:
|
|
|
|
msg += (
|
|
|
|
" Please use `-x` when cherry-picking to include "
|
|
|
|
"the full original commit ID. Alternately, use the "
|
|
|
|
"`Backport::Partial` label if not all original "
|
|
|
|
"commits are meant to be backported."
|
|
|
|
)
|
|
|
|
fail(msg)
|
2022-12-19 15:14:48 +01:00
|
|
|
else:
|
|
|
|
if not version_labels:
|
|
|
|
fail(
|
|
|
|
"If this merge request is a backport, set the *Backport* label and "
|
|
|
|
"a single version label (*v9.x*) indicating the target branch. "
|
|
|
|
"If not, set version labels for all targeted backport branches."
|
|
|
|
)
|
|
|
|
if not affects_labels:
|
|
|
|
warn(
|
|
|
|
"Set `Affects v9.` label(s) for all versions that are affected by "
|
|
|
|
"the issue which this MR addresses."
|
|
|
|
)
|
2020-05-25 12:49:36 +02:00
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# OTHER LABELS
|
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# WARN if any of the following is true for the merge request:
|
|
|
|
#
|
|
|
|
# * The "Review" label is not set. (It may be intentional, but rarely is.)
|
|
|
|
#
|
|
|
|
# * The "Review" label is set, but the "LGTM" label is not set. (This aims to
|
|
|
|
# remind developers about the need to set the latter on merge requests which
|
|
|
|
# passed review.)
|
|
|
|
|
2022-11-04 13:05:29 +01:00
|
|
|
approved = mr.approvals.get().approved
|
2022-06-07 16:27:23 +02:00
|
|
|
if "Review" not in mr_labels:
|
|
|
|
warn(
|
|
|
|
"This merge request does not have the *Review* label set. "
|
|
|
|
"Please set it if you would like the merge request to be reviewed."
|
|
|
|
)
|
2022-11-04 13:05:29 +01:00
|
|
|
elif not approved:
|
2022-06-07 16:27:23 +02:00
|
|
|
warn(
|
|
|
|
"This merge request is currently in review. "
|
2022-11-04 13:05:29 +01:00
|
|
|
"It should not be merged until it is approved."
|
2022-06-07 16:27:23 +02:00
|
|
|
)
|
2020-05-25 12:49:36 +02:00
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# 'CHANGES' FILE
|
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# FAIL if any of the following is true:
|
|
|
|
#
|
|
|
|
# * The merge request does not update the CHANGES file, but it does not have
|
|
|
|
# the "No CHANGES" label set. (This attempts to ensure that the author of
|
|
|
|
# the MR did not forget about adding a CHANGES entry.)
|
|
|
|
#
|
|
|
|
# * The merge request updates the CHANGES file, but it has the "No CHANGES"
|
2021-01-18 14:57:47 +01:00
|
|
|
# label set. (This attempts to ensure that the "No CHANGES" label is used in
|
2020-05-25 12:49:36 +02:00
|
|
|
# a sane way.)
|
|
|
|
#
|
2021-01-18 14:57:47 +01:00
|
|
|
# * The merge request adds any placeholder entries to the CHANGES file, but it
|
|
|
|
# does not target the "main" branch.
|
|
|
|
#
|
|
|
|
# * The merge request adds a new CHANGES entry that is not a placeholder and
|
|
|
|
# does not contain any GitLab/RT issue/MR identifiers.
|
2020-05-25 12:49:36 +02:00
|
|
|
|
2023-01-26 13:03:12 +01:00
|
|
|
changes_modified = "CHANGES" in modified_files or "CHANGES.SE" in modified_files
|
2022-06-07 16:27:23 +02:00
|
|
|
no_changes_label_set = "No CHANGES" in mr_labels
|
2020-05-25 12:49:36 +02:00
|
|
|
if not changes_modified and not no_changes_label_set:
|
2022-06-07 16:27:23 +02:00
|
|
|
fail(
|
|
|
|
"This merge request does not modify `CHANGES`. "
|
|
|
|
"Add a `CHANGES` entry or set the *No CHANGES* label."
|
|
|
|
)
|
2020-05-25 12:49:36 +02:00
|
|
|
if changes_modified and no_changes_label_set:
|
2022-06-07 16:27:23 +02:00
|
|
|
fail(
|
|
|
|
"This merge request modifies `CHANGES`. "
|
|
|
|
"Revert `CHANGES` modifications or unset the *No Changes* label."
|
|
|
|
)
|
2020-05-25 12:49:36 +02:00
|
|
|
|
2023-01-26 13:03:12 +01:00
|
|
|
changes_added_lines = added_lines(target_branch, ["CHANGES", "CHANGES.SE"])
|
2022-06-07 16:27:23 +02:00
|
|
|
placeholders_added = lines_containing(changes_added_lines, "[placeholder]")
|
2021-04-29 13:24:21 +02:00
|
|
|
identifiers_found = filter(changes_issue_or_mr_id_regex.search, changes_added_lines)
|
2021-01-18 14:57:47 +01:00
|
|
|
if changes_added_lines:
|
|
|
|
if placeholders_added:
|
2022-06-07 16:27:23 +02:00
|
|
|
if target_branch != "main":
|
|
|
|
fail(
|
|
|
|
"This MR adds at least one placeholder entry to `CHANGES`. "
|
|
|
|
"It should be targeting the `main` branch."
|
|
|
|
)
|
2021-01-18 14:57:47 +01:00
|
|
|
elif not any(identifiers_found):
|
2022-06-07 16:27:23 +02:00
|
|
|
fail("No valid issue/MR identifiers found in added `CHANGES` entries.")
|
2020-05-25 12:49:36 +02:00
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# RELEASE NOTES
|
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# - FAIL if any of the following is true:
|
|
|
|
#
|
|
|
|
# * The merge request does not update release notes and has the "Release
|
|
|
|
# Notes" label set. (This attempts to point out missing release notes.)
|
|
|
|
#
|
|
|
|
# * The merge request updates release notes but does not have the "Release
|
|
|
|
# Notes" label set. (This ensures that merge requests updating release
|
|
|
|
# notes can be easily found using the "Release Notes" label.)
|
|
|
|
#
|
2024-03-07 16:41:46 +01:00
|
|
|
# * A file was added to or deleted from the lib/dns/rdata/ subdirectory but
|
|
|
|
# release notes were not modified. This is probably a mistake because new
|
|
|
|
# RR types are a user-visible change (and so is removing support for
|
|
|
|
# existing ones).
|
|
|
|
#
|
2024-03-07 16:58:29 +01:00
|
|
|
# * "Release notes" and "No CHANGES" labels are both set at the same time.
|
|
|
|
# (If something is worth a release note, it should surely show up in
|
|
|
|
# CHANGES.) MRs with certain labels set ("Documentation", "Release") are
|
|
|
|
# exempt because these are typically used during release process.
|
|
|
|
#
|
2021-01-18 14:57:47 +01:00
|
|
|
# - WARN if any of the following is true:
|
|
|
|
#
|
|
|
|
# * This merge request does not update release notes and has the "Customer"
|
|
|
|
# label set. (Except for trivial changes, all merge requests which may
|
|
|
|
# be of interest to customers should include a release note.)
|
|
|
|
#
|
|
|
|
# * This merge request updates release notes, but no GitLab/RT issue/MR
|
|
|
|
# identifiers are found in the lines added to the release notes by this
|
|
|
|
# MR.
|
2020-05-25 12:49:36 +02:00
|
|
|
|
2022-06-07 16:27:23 +02:00
|
|
|
release_notes_regex = re.compile(r"doc/(arm|notes)/notes-.*\.(rst|xml)")
|
2024-01-05 12:51:13 +01:00
|
|
|
release_notes_changed = list(filter(release_notes_regex.match, affected_files))
|
2022-06-07 16:27:23 +02:00
|
|
|
release_notes_label_set = "Release Notes" in mr_labels
|
2021-01-18 14:57:47 +01:00
|
|
|
if not release_notes_changed:
|
|
|
|
if release_notes_label_set:
|
2022-06-07 16:27:23 +02:00
|
|
|
fail(
|
|
|
|
"This merge request has the *Release Notes* label set. "
|
2024-01-05 12:51:13 +01:00
|
|
|
"Update release notes or unset the *Release Notes* label."
|
2022-06-07 16:27:23 +02:00
|
|
|
)
|
|
|
|
elif "Customer" in mr_labels:
|
|
|
|
warn(
|
|
|
|
"This merge request has the *Customer* label set. "
|
2024-01-05 12:51:13 +01:00
|
|
|
"Update release notes unless the changes introduced are trivial."
|
2022-06-07 16:27:23 +02:00
|
|
|
)
|
2024-03-07 16:41:46 +01:00
|
|
|
rdata_types_add_rm = list(
|
|
|
|
filter(rdata_regex.match, danger.git.created_files + danger.git.deleted_files)
|
|
|
|
)
|
|
|
|
if rdata_types_add_rm:
|
|
|
|
fail(
|
|
|
|
"This merge request adds new files to `lib/dns/rdata/` and/or "
|
|
|
|
"deletes existing files from that directory, which almost certainly "
|
|
|
|
"means that it adds support for a new RR type or removes support "
|
|
|
|
"for an existing one. Please add a relevant release note."
|
|
|
|
)
|
2020-05-25 12:49:36 +02:00
|
|
|
if release_notes_changed and not release_notes_label_set:
|
2022-06-07 16:27:23 +02:00
|
|
|
fail(
|
|
|
|
"This merge request modifies release notes. "
|
|
|
|
"Revert release note modifications or set the *Release Notes* label."
|
|
|
|
)
|
2024-03-07 16:58:29 +01:00
|
|
|
if (
|
|
|
|
release_notes_label_set
|
|
|
|
and no_changes_label_set
|
|
|
|
and not ("Documentation" in mr_labels or "Release" in mr_labels)
|
|
|
|
):
|
|
|
|
fail(
|
|
|
|
"This merge request is labeled with both *Release notes* and *No CHANGES*. "
|
|
|
|
"A user-visible change should also be mentioned in the `CHANGES` file."
|
|
|
|
)
|
2020-05-25 12:49:36 +02:00
|
|
|
|
|
|
|
if release_notes_changed:
|
2024-01-05 12:51:13 +01:00
|
|
|
modified_or_new_files = danger.git.modified_files + danger.git.created_files
|
|
|
|
release_notes_added = list(filter(release_notes_regex.match, modified_or_new_files))
|
|
|
|
notes_added_lines = added_lines(target_branch, release_notes_added)
|
2021-04-29 13:24:21 +02:00
|
|
|
identifiers_found = filter(relnotes_issue_or_mr_id_regex.search, notes_added_lines)
|
2020-05-25 12:49:36 +02:00
|
|
|
if notes_added_lines and not any(identifiers_found):
|
2022-06-07 16:27:23 +02:00
|
|
|
warn("No valid issue/MR identifiers found in added release notes.")
|
2021-01-18 14:57:47 +01:00
|
|
|
else:
|
|
|
|
notes_added_lines = []
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# CVE IDENTIFIERS
|
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# FAIL if the merge request adds a CHANGES entry of type [security] and a CVE
|
|
|
|
# identifier is missing from either the added CHANGES entry or the added
|
|
|
|
# release note.
|
|
|
|
|
2022-06-07 16:27:23 +02:00
|
|
|
if lines_containing(changes_added_lines, "[security]"):
|
|
|
|
if not lines_containing(changes_added_lines, "(CVE-20"):
|
|
|
|
fail(
|
|
|
|
"This merge request fixes a security issue. "
|
|
|
|
"Please add a CHANGES entry which includes a CVE identifier."
|
|
|
|
)
|
2023-10-10 11:25:05 +11:00
|
|
|
if not lines_containing(notes_added_lines, ":cve:`20"):
|
2022-06-07 16:27:23 +02:00
|
|
|
fail(
|
|
|
|
"This merge request fixes a security issue. "
|
|
|
|
"Please add a release note which includes a CVE identifier."
|
|
|
|
)
|
2021-01-18 14:57:47 +01:00
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# PAIRWISE TESTING
|
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# FAIL if the merge request adds any new ./configure switch without an
|
|
|
|
# associated annotation used for pairwise testing.
|
|
|
|
|
2022-06-07 16:27:23 +02:00
|
|
|
configure_added_lines = added_lines(target_branch, ["configure.ac"])
|
|
|
|
switches_added = lines_containing(
|
|
|
|
configure_added_lines, "AC_ARG_ENABLE"
|
|
|
|
) + lines_containing(configure_added_lines, "AC_ARG_WITH")
|
|
|
|
annotations_added = lines_containing(configure_added_lines, "# [pairwise: ")
|
2023-04-28 10:24:17 +02:00
|
|
|
if switches_added:
|
|
|
|
if len(switches_added) > len(annotations_added):
|
|
|
|
fail(
|
|
|
|
"This merge request adds at least one new `./configure` switch that "
|
|
|
|
"is not annotated for pairwise testing purposes."
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
message(
|
|
|
|
"**Before merging**, please start a full CI pipeline for this "
|
|
|
|
"branch with the `PAIRWISE_TESTING` variable set to any "
|
|
|
|
"non-empty value (e.g. `1`). This will cause the `pairwise` "
|
|
|
|
"job to exercise the new `./configure` switches."
|
|
|
|
)
|
2022-03-15 11:55:36 +01:00
|
|
|
|
2024-03-21 15:45:25 +01:00
|
|
|
###############################################################################
|
|
|
|
# PRE-RELEASE TESTING
|
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# WARN if the merge request is marked with the "Security" label, but not with
|
|
|
|
# the label used for marking merge requests for pre-release testing (if the
|
|
|
|
# latter is defined by the relevant environment variable).
|
|
|
|
|
|
|
|
pre_release_testing_label = os.getenv("PRE_RELEASE_TESTING_LABEL")
|
|
|
|
if (
|
|
|
|
pre_release_testing_label
|
|
|
|
and "Security" in mr_labels
|
|
|
|
and pre_release_testing_label not in mr_labels
|
|
|
|
):
|
|
|
|
warn(
|
|
|
|
"This merge request is marked with the *Security* label, but it is not "
|
|
|
|
f"marked for pre-release testing (*{pre_release_testing_label}*)."
|
|
|
|
)
|
|
|
|
|
2022-03-15 11:55:36 +01:00
|
|
|
###############################################################################
|
|
|
|
# USER-VISIBLE LOG LEVELS
|
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# WARN if the merge request adds new user-visible log messages (INFO or above)
|
|
|
|
|
|
|
|
user_visible_log_levels = [
|
2022-06-07 16:27:23 +02:00
|
|
|
"ISC_LOG_INFO",
|
|
|
|
"ISC_LOG_NOTICE",
|
|
|
|
"ISC_LOG_WARNING",
|
|
|
|
"ISC_LOG_ERROR",
|
|
|
|
"ISC_LOG_CRITICAL",
|
2022-03-15 11:55:36 +01:00
|
|
|
]
|
2022-06-07 16:27:23 +02:00
|
|
|
source_added_lines = added_lines(target_branch, ["*.[ch]"])
|
2022-03-15 11:55:36 +01:00
|
|
|
for log_level in user_visible_log_levels:
|
2022-06-07 16:27:23 +02:00
|
|
|
if lines_containing(source_added_lines, log_level):
|
|
|
|
warn(
|
|
|
|
"This merge request adds new user-visible log messages with "
|
|
|
|
"level INFO or above. Please double-check log levels and make "
|
|
|
|
"sure none of the messages added is a leftover debug message."
|
|
|
|
)
|
2022-03-15 11:55:36 +01:00
|
|
|
break
|
2023-08-30 13:51:05 +02:00
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# SYSTEM TEST FILES
|
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# FAIL if newly added system test directory contains an underscore (invalid char)
|
|
|
|
# FAIL if there are no pytest files in the system test directory
|
|
|
|
# FAIL if the pytest glue file for tests.sh is missing
|
|
|
|
|
|
|
|
TESTNAME_CANDIDATE_RE = re.compile(r"bin/tests/system/([^/]+)")
|
|
|
|
testnames = set()
|
|
|
|
for path in affected_files:
|
|
|
|
match = TESTNAME_CANDIDATE_RE.search(path)
|
|
|
|
if match is not None:
|
|
|
|
testnames.add(match.groups()[0])
|
|
|
|
|
|
|
|
for testname in testnames:
|
|
|
|
dirpath = f"bin/tests/system/{testname}"
|
|
|
|
if (
|
|
|
|
not os.path.isdir(dirpath)
|
|
|
|
or testname.startswith(".")
|
|
|
|
or testname.startswith("_")
|
2023-12-04 18:05:50 +01:00
|
|
|
or testname == "isctest"
|
2023-08-30 13:51:05 +02:00
|
|
|
):
|
|
|
|
continue
|
|
|
|
if "_" in testname:
|
|
|
|
fail(
|
|
|
|
f"System test directory `{testname}` may not contain an underscore, "
|
|
|
|
"use hyphen instead."
|
|
|
|
)
|
|
|
|
if not glob.glob(f"{dirpath}/**/tests_*.py", recursive=True):
|
|
|
|
fail(
|
|
|
|
f"System test directory `{testname}` doesn't contain any "
|
|
|
|
"`tests_*.py` pytest file."
|
|
|
|
)
|
|
|
|
tests_sh_exists = os.path.exists(f"{dirpath}/tests.sh")
|
|
|
|
glue_file_name = f"tests_sh_{testname.replace('-', '_')}.py"
|
|
|
|
tests_sh_py_exists = os.path.exists(f"{dirpath}/{glue_file_name}")
|
|
|
|
if tests_sh_exists and not tests_sh_py_exists:
|
|
|
|
fail(
|
|
|
|
f"System test directory `{testname}` is missing the "
|
|
|
|
f"`{glue_file_name}` pytest glue file."
|
|
|
|
)
|