update kubescape cli e2e run from private repo#80
Conversation
📝 WalkthroughWalkthroughThe Changes
Sequence DiagramsequenceDiagram
participant GH as GitHub Actions
participant API as GitHub API
participant PrivateRepo as armosec/shared-workflows
participant Monitor as Status Monitor
GH->>GH: Set dispatch info (correlation_id)
GH->>API: Create GitHub App token
API-->>GH: Token
GH->>PrivateRepo: Repository dispatch (tests_group, artifact paths, etc.)
PrivateRepo-->>GH: Dispatch event triggered
GH->>Monitor: Find E2E workflow run (poll)
loop Poll until found
Monitor->>API: Query repository_dispatch event
API-->>Monitor: run_id (when available)
end
Monitor-->>GH: run_id, run_url
GH->>PrivateRepo: Get run status
alt Run cancelled
GH->>PrivateRepo: Full rerun
else Run failed
GH->>PrivateRepo: Rerun failed jobs only
end
GH->>Monitor: Wait for completion (poll status)
loop Poll until complete
Monitor->>API: Check run status
API-->>Monitor: Status (in_progress/completed)
end
alt Success
Monitor-->>GH: ✓ Passed
else Failure
GH->>API: Download failed job logs
API-->>GH: Logs
GH->>GH: Extract per-test context
GH->>GH: Upload failed_*.txt artifacts
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Summary:
|
|
Summary:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In @.github/workflows/kubescape-cli-e2e-tests.yaml:
- Around line 246-256: The generated failed log filename
(log_file="failed_${test_name}.txt") can become invalid or collide when job_name
contains slashes or lacks parentheses; change the filename generation to
sanitize/slugify job_name and include step_name (and optionally a short
timestamp or unique counter) to avoid collisions: replace characters like / \ :
* ? " < > | and parentheses with safe characters or remove them, normalize
whitespace to dashes, then set log_file to something like
failed_<slugified_job_name>_<slugified_step_name>[_<ts>].txt using the existing
variables (test_name, job_name, step_name) before writing the file so filenames
are valid and de-duplicated.
| log_file="failed_${test_name}.txt" | ||
| echo "════════════════════════════════════════" > "$log_file" | ||
| echo "${job_name}" >> "$log_file" | ||
| echo " Step: ${step_name}" >> "$log_file" | ||
| echo "════════════════════════════════════════" >> "$log_file" | ||
| last_endgroup=$(grep -n "##\\[endgroup\\]" /tmp/job_logs.txt | tail -1 | cut -d: -f1) | ||
| if [ -n "$last_endgroup" ]; then | ||
| tail -n +$((last_endgroup + 1)) /tmp/job_logs.txt >> "$log_file" | ||
| else | ||
| tail -500 /tmp/job_logs.txt >> "$log_file" | ||
| fi |
There was a problem hiding this comment.
Sanitize and de‑duplicate failed log filenames.
If job_name lacks parentheses or contains /, the filename can become invalid or overwrite logs for multiple failed steps. Consider slugifying and incorporating the step name.
🧽 Proposed fix
- log_file="failed_${test_name}.txt"
+ safe_test_name=$(echo "$test_name" | tr -cs 'A-Za-z0-9._-' '_' )
+ safe_step_name=$(echo "$step_name" | tr -cs 'A-Za-z0-9._-' '_' )
+ log_file="failed_${safe_test_name}__${safe_step_name}.txt"📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| log_file="failed_${test_name}.txt" | |
| echo "════════════════════════════════════════" > "$log_file" | |
| echo "${job_name}" >> "$log_file" | |
| echo " Step: ${step_name}" >> "$log_file" | |
| echo "════════════════════════════════════════" >> "$log_file" | |
| last_endgroup=$(grep -n "##\\[endgroup\\]" /tmp/job_logs.txt | tail -1 | cut -d: -f1) | |
| if [ -n "$last_endgroup" ]; then | |
| tail -n +$((last_endgroup + 1)) /tmp/job_logs.txt >> "$log_file" | |
| else | |
| tail -500 /tmp/job_logs.txt >> "$log_file" | |
| fi | |
| safe_test_name=$(echo "$test_name" | tr -cs 'A-Za-z0-9._-' '_' ) | |
| safe_step_name=$(echo "$step_name" | tr -cs 'A-Za-z0-9._-' '_' ) | |
| log_file="failed_${safe_test_name}__${safe_step_name}.txt" | |
| echo "════════════════════════════════════════" > "$log_file" | |
| echo "${job_name}" >> "$log_file" | |
| echo " Step: ${step_name}" >> "$log_file" | |
| echo "════════════════════════════════════════" >> "$log_file" | |
| last_endgroup=$(grep -n "##\\[endgroup\\]" /tmp/job_logs.txt | tail -1 | cut -d: -f1) | |
| if [ -n "$last_endgroup" ]; then | |
| tail -n +$((last_endgroup + 1)) /tmp/job_logs.txt >> "$log_file" | |
| else | |
| tail -500 /tmp/job_logs.txt >> "$log_file" | |
| fi |
🤖 Prompt for AI Agents
In @.github/workflows/kubescape-cli-e2e-tests.yaml around lines 246 - 256, The
generated failed log filename (log_file="failed_${test_name}.txt") can become
invalid or collide when job_name contains slashes or lacks parentheses; change
the filename generation to sanitize/slugify job_name and include step_name (and
optionally a short timestamp or unique counter) to avoid collisions: replace
characters like / \ : * ? " < > | and parentheses with safe characters or remove
them, normalize whitespace to dashes, then set log_file to something like
failed_<slugified_job_name>_<slugified_step_name>[_<ts>].txt using the existing
variables (test_name, job_name, step_name) before writing the file so filenames
are valid and de-duplicated.
Summary by CodeRabbit