mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-10-25 04:44:20 +00:00
fix(ui): stabilize cloud e2e prerequisites (#12024)
This commit is contained in:
1 parent
7a6a35afec
commit
7a62926a09
13 files changed
+298
-64
No files matched your search
@@ -0,0 +1,29 @@
|
||||
from pathlib import Path
|
||||
|
||||
REPOSITORY_ROOT = Path(__file__).parents[2]
|
||||
WORKFLOW_PATH = REPOSITORY_ROOT / ".github/workflows/api-tests.yml"
|
||||
|
||||
|
||||
def _indented_block(text, heading):
|
||||
lines = text.splitlines()
|
||||
start = lines.index(heading)
|
||||
indentation = len(heading) - len(heading.lstrip())
|
||||
end = len(lines)
|
||||
|
||||
for index in range(start + 1, len(lines)):
|
||||
line = lines[index]
|
||||
if line.strip() and len(line) - len(line.lstrip()) <= indentation:
|
||||
end = index
|
||||
break
|
||||
|
||||
return lines[start:end]
|
||||
|
||||
|
||||
def test_codecov_configuration_changes_run_api_tests():
|
||||
workflow = WORKFLOW_PATH.read_text()
|
||||
changed_files_step = _indented_block(
|
||||
workflow, " - name: Check for API changes"
|
||||
)
|
||||
files = _indented_block("\n".join(changed_files_step), " files: |")
|
||||
|
||||
assert "codecov.yml" in {line.strip() for line in files[1:]}
|
||||
@@ -0,0 +1,79 @@
|
||||
from pathlib import Path
|
||||
|
||||
REPOSITORY_ROOT = Path(__file__).parents[2]
|
||||
WORKFLOW_PATH = REPOSITORY_ROOT / ".github/workflows/ui-e2e-tests-v2.yml"
|
||||
NODE_IMAGE_DIGEST = (
|
||||
"sha256:d1b3b4da11eefd5941e7f0b9cf17783fc99d9c6fc34884a665f40a06dbdfc94f"
|
||||
)
|
||||
|
||||
|
||||
def _indented_block(text, heading):
|
||||
lines = text.splitlines()
|
||||
start = lines.index(heading)
|
||||
indentation = len(heading) - len(heading.lstrip())
|
||||
end = len(lines)
|
||||
|
||||
for index in range(start + 1, len(lines)):
|
||||
line = lines[index]
|
||||
if line.strip() and len(line) - len(line.lstrip()) <= indentation:
|
||||
end = index
|
||||
break
|
||||
|
||||
return "\n".join(lines[start:end])
|
||||
|
||||
|
||||
def _multiline_value(block, key):
|
||||
lines = block.splitlines()
|
||||
heading = next(line for line in lines if line.strip() == f"{key}: |")
|
||||
value_block = _indented_block(block, heading)
|
||||
return "\n".join(value_block.splitlines()[1:])
|
||||
|
||||
|
||||
def _normalize(expression):
|
||||
return " ".join(expression.split())
|
||||
|
||||
|
||||
def test_fork_pull_requests_use_explicit_skip_route():
|
||||
workflow = WORKFLOW_PATH.read_text()
|
||||
e2e_job = _indented_block(workflow, " e2e-tests:")
|
||||
fork_job = _indented_block(workflow, " fork-e2e-unavailable:")
|
||||
|
||||
assert _normalize(_multiline_value(e2e_job, "if")) == (
|
||||
"github.repository == 'prowler-cloud/prowler' && "
|
||||
"(github.event_name != 'pull_request' || "
|
||||
"github.event.pull_request.head.repo.fork == false) && "
|
||||
"(needs.impact-analysis.outputs.has-ui-e2e == 'true' || "
|
||||
"needs.impact-analysis.outputs.run-all == 'true')"
|
||||
)
|
||||
assert _normalize(_multiline_value(fork_job, "if")) == (
|
||||
"github.repository == 'prowler-cloud/prowler' && "
|
||||
"github.event_name == 'pull_request' && "
|
||||
"github.event.pull_request.head.repo.fork == true && "
|
||||
"(needs.impact-analysis.outputs.has-ui-e2e == 'true' || "
|
||||
"needs.impact-analysis.outputs.run-all == 'true')"
|
||||
)
|
||||
assert _indented_block(fork_job, " permissions:") == (
|
||||
" permissions:\n contents: read"
|
||||
)
|
||||
|
||||
reporting_step = _indented_block(
|
||||
fork_job, " - name: Report unavailable E2E tests"
|
||||
)
|
||||
assert "GITHUB_STEP_SUMMARY" in reporting_step
|
||||
assert (
|
||||
"UI E2E tests require repository secrets and cannot run for fork pull requests."
|
||||
in reporting_step
|
||||
)
|
||||
|
||||
prerequisite_step = _indented_block(
|
||||
e2e_job, " - name: Validate E2E prerequisites"
|
||||
)
|
||||
assert "IS_FORK_PR" not in prerequisite_step
|
||||
assert "exit 0" not in prerequisite_step
|
||||
|
||||
|
||||
def test_docker_node_image_matches_nvmrc():
|
||||
node_version = (REPOSITORY_ROOT / "ui/.nvmrc").read_text().strip()
|
||||
dockerfile = (REPOSITORY_ROOT / "ui/Dockerfile").read_text()
|
||||
|
||||
assert f"FROM node:{node_version}-alpine@{NODE_IMAGE_DIGEST} AS base" in dockerfile
|
||||
Reference in new issue
Block a user