Skip to content

Commit

Permalink
Add redhat prefix check
Browse files Browse the repository at this point in the history
Ported from:
https://github.com/openshift-helm-charts/development/blob/919146bc199e6366c40cf10d533d4669bd3def70/scripts/src/checkprcontent/checkpr.py#L211-L222

Signed-off-by: Matthias Goerens <mgoerens@redhat.com>

stash

Signed-off-by: Matthias Goerens <mgoerens@redhat.com>

Add owners-error-message GH output

Signed-off-by: Matthias Goerens <mgoerens@redhat.com>

Better craft pr-content-error-message

Signed-off-by: Matthias Goerens <mgoerens@redhat.com>

rework build

Fix build.yaml

add precheck to venv

fix import

fix api_url arg

Add bot_token env

first attempt fix submission env var; add owners_message debug

fix craft pr content error msg && ensure comments are added

fix condition

fix condition

pr artifcat should run always

fix submission env_var

bool env vars python

output vendor labels partners to partner

debug

remove debug and fix vendor output

fix condition for release

move github output

fix check auto merge condition

remove komish ping

Fix error messages for CI to be happy

Add check index & check tag
  • Loading branch information
mgoerens authored and github-actions[bot] committed Sep 19, 2024
1 parent 3ce600f commit b710b29
Show file tree
Hide file tree
Showing 9 changed files with 408 additions and 187 deletions.
179 changes: 125 additions & 54 deletions .github/workflows/build.yml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions scripts/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ console_scripts =
chart-repo-manager = chartrepomanager.chartrepomanager:main
chart-pr-review = chartprreview.chartprreview:main
check-pr-content = checkprcontent.checkpr:main
pre-check = precheck.precheck:main
pr-artifact = pullrequest.prartifact:main
pr-comment = pullrequest.prepare_pr_comment:main
sa-for-chart-testing = saforcharttesting.saforcharttesting:main
Expand Down
7 changes: 5 additions & 2 deletions scripts/src/chartprreview/chartprreview.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import semantic_version
import semver
import yaml
from environs import Env
from environs import Env, EnvValidationError

try:
from yaml import CLoader as Loader
Expand Down Expand Up @@ -516,7 +516,10 @@ def main():
generated_report_path = os.environ.get("GENERATED_REPORT_PATH")
generated_report_info_path = os.environ.get("REPORT_SUMMARY_PATH")
env = Env()
web_catalog_only = env.bool("WEB_CATALOG_ONLY", False)
try:
web_catalog_only = env.bool("WEB_CATALOG_ONLY", False)
except EnvValidationError:
web_catalog_only = False

submitted_report_path = os.path.join(
"charts", category, organization, chart, version, "report.yaml"
Expand Down
7 changes: 5 additions & 2 deletions scripts/src/chartrepomanager/chartrepomanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import urllib.parse

import yaml
from environs import Env
from environs import Env, EnvValidationError

try:
from yaml import CDumper as Dumper
Expand Down Expand Up @@ -448,7 +448,10 @@ def main():
)

env = Env()
web_catalog_only = env.bool("WEB_CATALOG_ONLY", False)
try:
web_catalog_only = env.bool("WEB_CATALOG_ONLY", False)
except EnvValidationError:
web_catalog_only = False
ocp_version_range = os.environ.get("OCP_VERSION_RANGE", "N/A")

print(f"[INFO] webCatalogOnly/providerDelivery is {web_catalog_only}")
Expand Down
93 changes: 0 additions & 93 deletions scripts/src/checkprcontent/checkpr.py
Original file line number Diff line number Diff line change
@@ -1,100 +1,7 @@
import argparse
import json
import os
import re
import sys

import requests
import semver
import yaml
from reporegex import matchers

try:
from yaml import CLoader as Loader
except ImportError:
from yaml import Loader

sys.path.append("../")
from owners import owners_file
from pullrequest import prartifact
from report import verifier_report
from tools import gitutils

ALLOW_CI_CHANGES = "allow/ci-changes"


def check_web_catalog_only(report_in_pr, num_files_in_pr, report_file_match):
print(f"[INFO] report in PR {report_in_pr}")
print(f"[INFO] num files in PR {num_files_in_pr}")

category, organization, chart, version = report_file_match.groups()

print(f"read owners file : {category}/{organization}/{chart}")
found_owners, owner_data = owners_file.get_owner_data(category, organization, chart)

if found_owners:
owner_web_catalog_only = owners_file.get_web_catalog_only(owner_data)
print(
f"[INFO] webCatalogOnly/providerDelivery from OWNERS : {owner_web_catalog_only}"
)
else:
msg = "[ERROR] OWNERS file was not found."
print(msg)
gitutils.add_output("owners-error-message", msg)
sys.exit(1)

if report_in_pr:
report_file_path = os.path.join(
"pr-branch", "charts", category, organization, chart, version, "report.yaml"
)
print(f"read report file : {report_file_path}")
found_report, report_data = verifier_report.get_report_data(report_file_path)

if found_report:
report_web_catalog_only = verifier_report.get_web_catalog_only(report_data)
print(
f"[INFO] webCatalogOnly/providerDelivery from report : {report_web_catalog_only}"
)
else:
msg = f"[ERROR] Failed tp open report: {report_file_path}."
print(msg)
gitutils.add_output("pr-content-error-message", msg)
sys.exit(1)

web_catalog_only = False
if report_in_pr and num_files_in_pr > 1:
if report_web_catalog_only or owner_web_catalog_only:
msg = "[ERROR] The web catalog distribution method requires the pull request to be report only."
print(msg)
gitutils.add_output("pr-content-error-message", msg)
sys.exit(1)
elif report_in_pr:
if report_web_catalog_only and owner_web_catalog_only:
if verifier_report.get_package_digest(report_data):
web_catalog_only = True
else:
msg = "[ERROR] The web catalog distribution method requires a package digest in the report."
print(msg)
gitutils.add_output("pr-content-error-message", msg)
sys.exit(1)
elif report_web_catalog_only:
msg = "[ERROR] Report indicates web catalog only but the distribution method set for the chart is not web catalog only."
print(msg)
gitutils.add_output("pr-content-error-message", msg)
sys.exit(1)
elif owner_web_catalog_only:
msg = "[ERROR] The web catalog distribution method is set for the chart but is not set in the report."
print(msg)
gitutils.add_output("pr-content-error-message", msg)
sys.exit(1)

if web_catalog_only:
print("[INFO] webCatalogOnly/providerDelivery is a go")
gitutils.add_output("web_catalog_only", "True")
else:
gitutils.add_output("web_catalog_only", "False")
print("[INFO] webCatalogOnly/providerDelivery is a no-go")


def get_file_match_compiled_patterns():
"""Return a tuple of patterns, where the first can be used to match any file in a chart PR
Expand Down
133 changes: 133 additions & 0 deletions scripts/src/precheck/precheck.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import argparse
import json
import sys

from precheck import submission, serializer
from tools import gitutils


def write_submission_to_file(s: submission.Submission, artifact_path: str):
data = serializer.SubmissionEncoder().encode(s)

with open(artifact_path, "w") as f:
f.write(data)


def read_submission_from_file(articact_path: str):
with open(articact_path, "r") as f:
s = json.load(f, cls=serializer.SubmissionDecoder)

return s


def craft_pr_content_error_msg(s: submission.Submission, repository: str):
# Checks that this PR is a valid "Chart certification" PR
is_valid, msg = s.is_valid_certification_submission(ignore_owners=True)
if not is_valid:
return msg

# Parse the modified files and determine if it is a "web_catalog_only" certification
try:
s.parse_web_catalog_only(repo_path="pr-branch")
except submission.SubmissionError as e:
return str(e)

if s.is_web_catalog_only:
is_valid, msg = s.is_valid_web_catalog_only(repo_path="pr-branch")
if not is_valid:
return msg

index = submission.download_index_data(repository)
try:
s.chart.check_index(index)
except submission.HelmIndexError as e:
return str(e)

try:
s.chart.check_release_tag(repository)
except submission.ReleaseTagError as e:
return str(e)

return ""


def craft_owners_error_msg(s):
is_valid, msg = s.is_valid_owners_submission()
if is_valid:
msg = "[INFO] OWNERS file changes require manual review by maintainers."
return msg


def main():
parser = argparse.ArgumentParser()
parser.add_argument(
"-u",
"--api_url",
dest="api_url",
type=str,
required=True,
help="API URL for the pull request",
)
parser.add_argument(
"-r",
"--repository",
dest="repository",
type=str,
required=True,
help="Git Repository",
)
parser.add_argument(
"-o",
"--output",
dest="output",
type=str,
required=True,
help="Path to artifact file to write Submission json representation",
)
parser.add_argument(
"-c",
"--chart_submission",
dest="check_chart_submission",
default=False,
action="store_true",
help="Signify that the PR referenced by api_url is expected to be a certification submission",
)

args = parser.parse_args()
try:
s = submission.Submission(args.api_url)
except submission.SubmissionError as e:
print(str(e))
gitutils.add_output("pr-content-error-message", str(e))
sys.exit(10)

owners_error_msg = ""
if s.modified_owners:
# If the PR contains an OWNER file, craft a error message to be added as a comment in the PR
owners_error_msg = craft_owners_error_msg(s)
print(owners_error_msg)
gitutils.add_output("owners-error-message", owners_error_msg)

pr_content_error_msg = ""
if args.check_chart_submission: #TODO: why ?
pr_content_error_msg = craft_pr_content_error_msg(s, args.repository)
if pr_content_error_msg:
print(pr_content_error_msg)
gitutils.add_output("pr-content-error-message", pr_content_error_msg)

gitutils.add_output("chart_entry_name", s.chart.name)
gitutils.add_output("release_tag", s.chart.get_release_tag())
gitutils.add_output("web_catalog_only", s.is_web_catalog_only)
gitutils.add_output("category", s.chart.get_vendor_label())

if owners_error_msg or pr_content_error_msg:
print(
f"exit with owners_error_msg={owners_error_msg}; pr_content_error_msg={pr_content_error_msg}"
)
sys.exit(20)

write_submission_to_file(s, args.output)


if __name__ == "__main__":
main()
Loading

0 comments on commit b710b29

Please sign in to comment.