Skip to content

Commit

Permalink
Skip yamllint for removed bundles and fix parser
Browse files Browse the repository at this point in the history
In case a bundle is removed the files don't exists in the repository
anymore and it doesn't make sense to run yamllint.

The change parser also needs to distinguis between added, modified and
removed operators and bundles. Each of this category needs to be
treated differently.

JIRA: ISV-5466

Signed-off-by: Ales Raszka <[email protected]>
  • Loading branch information
Allda committed Dec 16, 2024
1 parent d169ca7 commit 4d39461
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
&& body.action == "closed"
&& body.pull_request.base.ref == "{{ branch }}"
&& body.pull_request.merged == true
&& body.sender.login == "rh-operator-bundle-bot"
)
bindings:
- ref: operator-release-pipeline-trigger-binding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ spec:
- name: pipeline_image
value: "$(params.pipeline_image)"
- name: args
value: ["-d {extends: default, rules: {line-length: {max: 180, level: warning}, indentation: {indent-sequences: whatever}}}", "$(params.bundle_path)"]
value: "-d {extends: default, rules: {line-length: {max: 180, level: warning}, indentation: {indent-sequences: whatever}}}"
- name: path
value: "$(params.bundle_path)"
workspaces:
- name: shared-workspace
workspace: pipeline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,9 @@ spec:
- name: pipeline_image
value: "$(params.pipeline_image)"
- name: args
value:
[
"-d {extends: default, rules: {line-length: {max: 180, level: warning}, indentation: {indent-sequences: whatever}}}",
"$(tasks.detect-changes.results.bundle_path)",
]
value: "-d {extends: default, rules: {line-length: {max: 180, level: warning}, indentation: {indent-sequences: whatever}}}"
- name: path
value: "$(tasks.detect-changes.results.bundle_path)"
workspaces:
- name: shared-workspace
workspace: repository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ spec:
set -xe
if [[ -z "$(params.operator_path)" ]]; then
echo -n false > "$(results.bool_merge.path)"
elif [[ ! -f "$(params.operator_path)/ci.yaml" ]]; then
echo -n false > "$(results.bool_merge.path)"
else
BOOL_MERGE=$(yq -r '.merge!=false' < "$(params.operator_path)/ci.yaml")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ spec:
CONFIG_PATH="$PKG_PATH/ci.yaml"
if [[ ! -f "$CONFIG_PATH" ]]; then
if [[ ! -d "$PKG_PATH" ]]; then
echo "Operator directory is removed."
echo -n "" | tee $(results.upgrade-graph-mode.path)
echo -n "true" | tee $(results.fbc-enabled.path)
echo -n "true" | tee "$(workspaces.output.path)/fbc_enabled"
exit 0
elif [[ ! -f "$CONFIG_PATH" ]]; then
echo "Config file $CONFIG_PATH does not exist or no bundle affected."
echo -n "replaces" | tee $(results.upgrade-graph-mode.path)
echo -n "false" | tee $(results.fbc-enabled.path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: Task
metadata:
name: yaml-lint
labels:
app.kubernetes.io/version: "0.1"
app.kubernetes.io/version: "0.2"
annotations:
tekton.dev/pipelines.minVersion: "0.12.1"
tekton.dev/categories: Code Quality
Expand All @@ -19,14 +19,23 @@ spec:
params:
- name: pipeline_image
- name: args
type: array
type: string
description: extra args needs to append
default: ["--help"]
default: "--help"
- name: path
type: string
description: path to the directory containing the YAML files
steps:
- name: lint-yaml-files
image: "$(params.pipeline_image)"
workingDir: $(workspaces.shared-workspace.path)
command:
- yamllint
args:
- $(params.args)
script: |
#!/usr/bin/env bash
set -xe
# Check if a path exists and skip the linting if it does not
if [ ! -e "$(params.path)" ]; then
echo "A path $(params.path) does not exist. Nothing to check..."
exit 0
fi
yamllint "$(params.path)" "$(params.args)"
10 changes: 7 additions & 3 deletions operator-pipeline-images/operatorcert/parsed_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def to_dict(self) -> Dict[str, Any]:
"added_bundles": [f"{x}/{y}" for x, y in self.added],
"modified_bundles": [f"{x}/{y}" for x, y in self.modified],
"deleted_bundles": [f"{x}/{y}" for x, y in self.deleted],
"added_or_modified_bundles": [
f"{x}/{y}" for x, y in self.added | self.modified
],
}


Expand Down Expand Up @@ -74,6 +77,7 @@ def to_dict(self) -> Dict[str, Any]:
"added_operators": list(self.added),
"modified_operators": list(self.modified),
"deleted_operators": list(self.deleted),
"added_or_modified_operators": list(self.added | self.modified),
}


Expand Down Expand Up @@ -192,14 +196,14 @@ def enrich_result(result: dict[str, Any]) -> None:
bundle_version = ""

affected_operators = result.get("affected_operators", [])
affected_bundles = result.get("affected_bundles", [])
added_or_modified_bundles = result.get("added_or_modified_bundles", [])
affected_catalog_operators = result.get("affected_catalog_operators", [])

if affected_operators:
operator_name = affected_operators[0]

if affected_bundles:
_, bundle_version = affected_bundles[0].split("/")
if added_or_modified_bundles:
_, bundle_version = added_or_modified_bundles[0].split("/")

if affected_catalog_operators and operator_name == "":
# Even if the change affects only files in catalogs/ we still need to know
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@
"db1a066",
{
"affected_operators": ["operator-e2e"],
"added_or_modified_operators": ["operator-e2e"],
"added_operators": ["operator-e2e"],
"affected_bundles": ["operator-e2e/0.0.100"],
"added_bundles": ["operator-e2e/0.0.100"],
"added_or_modified_bundles": ["operator-e2e/0.0.100"],
},
id="Add new bundle for new operator",
),
Expand All @@ -62,9 +64,11 @@
"6a75661",
{
"affected_operators": ["operator-e2e"],
"added_or_modified_operators": ["operator-e2e"],
"modified_operators": ["operator-e2e"],
"affected_bundles": ["operator-e2e/0.0.101"],
"added_bundles": ["operator-e2e/0.0.101"],
"added_or_modified_bundles": ["operator-e2e/0.0.101"],
},
id="Add new bundle for existing operator",
),
Expand All @@ -76,13 +80,18 @@
"6a75661",
{
"affected_operators": ["operator-e2e", "operator-clone-e2e"],
"added_or_modified_operators": ["operator-e2e", "operator-clone-e2e"],
"added_operators": ["operator-clone-e2e"],
"modified_operators": ["operator-e2e"],
"affected_bundles": [
"operator-e2e/0.0.101",
"operator-clone-e2e/0.0.100",
],
"added_bundles": ["operator-e2e/0.0.101", "operator-clone-e2e/0.0.100"],
"added_or_modified_bundles": [
"operator-e2e/0.0.101",
"operator-clone-e2e/0.0.100",
],
},
id="Add bundles for multiple operators",
),
Expand All @@ -96,6 +105,7 @@
{
"extra_files": ["empty.txt", "operators/empty.txt"],
"affected_operators": ["operator-e2e", "operator-clone-e2e"],
"added_or_modified_operators": ["operator-e2e", "operator-clone-e2e"],
"modified_operators": ["operator-e2e", "operator-clone-e2e"],
"affected_bundles": [
"operator-e2e/0.0.101",
Expand All @@ -105,6 +115,10 @@
"operator-e2e/0.0.101",
"operator-clone-e2e/0.0.100",
],
"added_or_modified_bundles": [
"operator-e2e/0.0.101",
"operator-clone-e2e/0.0.100",
],
},
id="Modify bundles for multiple operators and add extra files",
),
Expand All @@ -117,6 +131,7 @@
{
"extra_files": ["empty.txt", "operators/empty.txt"],
"affected_operators": ["operator-e2e"],
"added_or_modified_operators": ["operator-e2e"],
"modified_operators": ["operator-e2e"],
"affected_bundles": ["operator-e2e/0.0.101"],
"deleted_bundles": ["operator-e2e/0.0.101"],
Expand All @@ -130,6 +145,7 @@
"2c06647",
{
"affected_operators": ["operator-clone-e2e"],
"added_or_modified_operators": ["operator-clone-e2e"],
"modified_operators": ["operator-clone-e2e"],
},
id="Add ci.yaml to an operator",
Expand Down Expand Up @@ -247,6 +263,7 @@
"244d87b92",
{
"affected_operators": ["operator-e2e"],
"added_or_modified_operators": ["operator-e2e"],
"modified_operators": ["operator-e2e"],
},
id="Add catalog template to operator-e2e",
Expand Down Expand Up @@ -295,10 +312,12 @@ def test_detect_changes(
default_expected: dict[str, Any] = {
"extra_files": [],
"affected_operators": [],
"added_or_modified_operators": [],
"added_operators": [],
"modified_operators": [],
"deleted_operators": [],
"affected_bundles": [],
"added_or_modified_bundles": [],
"added_bundles": [],
"modified_bundles": [],
"deleted_bundles": [],
Expand Down Expand Up @@ -734,10 +753,14 @@ def test_ParserRules_validate_removal_fbc_fail(
{
"affected_bundles": ["operator-e2e/0.0.101"],
"affected_operators": ["operator-e2e"],
"added_or_modified_operators": ["operator-e2e"],
"added_or_modified_bundles": ["operator-e2e/0.0.101"],
},
{
"affected_bundles": ["operator-e2e/0.0.101"],
"affected_operators": ["operator-e2e"],
"added_or_modified_operators": ["operator-e2e"],
"added_or_modified_bundles": ["operator-e2e/0.0.101"],
"operator_name": "operator-e2e",
"bundle_version": "0.0.101",
"operator_path": "operators/operator-e2e",
Expand Down

0 comments on commit 4d39461

Please sign in to comment.