Skip to content

Feat: Adding fetched AquaSec JSON as workflow artifact.#89

Open
tmikula-dev wants to merge 1 commit into
masterfrom
feature/88-add-aqua-json-artifact
Open

Feat: Adding fetched AquaSec JSON as workflow artifact.#89
tmikula-dev wants to merge 1 commit into
masterfrom
feature/88-add-aqua-json-artifact

Conversation

@tmikula-dev

@tmikula-dev tmikula-dev commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Overview

This pull request adds the ability to output AquaSec scan findings as a JSON artifact and improves monitoring and traceability of security scans. It introduces a new --scan-output option to the security pipeline, writes scan results to a file when requested, uploads the artifact in CI, and documents the feature. Comprehensive tests are included to ensure correct behavior.

Release Notes

  • Scan run now uploads the fetched AquaSec findings as a workflow artifact named aquasec-night-scan, containing a single aquasec_scan.json file with all findings across every severity.

Related

Closes #88

Summary by CodeRabbit

  • New Features

    • Added an optional --scan-output option to save scan findings as formatted JSON.
    • Nightly security scans now upload results as the aquasec-night-scan workflow artifact.
  • Documentation

    • Documented the scan artifact and its contents.
  • Tests

    • Added coverage for JSON output creation and optional scan-output behavior.

@tmikula-dev tmikula-dev self-assigned this Jul 23, 2026
@tmikula-dev tmikula-dev added the enhancement New feature or request label Jul 23, 2026
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

The security scan accepts an optional JSON output path, writes fetched AquaSec findings when configured, and the nightly workflow uploads the file as aquasec-night-scan. Documentation and tests cover the artifact and output behavior.

Changes

AquaSec scan artifact

Layer / File(s) Summary
Scan output pipeline
src/core/helpers.py, src/security/config.py, src/security/main.py
Adds JSON serialization, carries --scan-output through configuration, and writes fetched findings when a path is provided.
Workflow artifact delivery
.github/workflows/aquasec-scan.yml, docs/security/security.md
Passes aquasec_scan.json to the scan, uploads it as aquasec-night-scan, and documents its contents.
Scan output validation
tests/core/test_helpers.py, tests/security/test_config.py, tests/security/test_main.py
Tests JSON output, argument parsing, configuration defaults, and conditional writing behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant NightlyWorkflow
  participant SecurityMain
  participant ScanFetcher
  participant JSONFile
  participant WorkflowArtifact
  NightlyWorkflow->>SecurityMain: run with --scan-output aquasec_scan.json
  SecurityMain->>ScanFetcher: fetch findings
  ScanFetcher-->>SecurityMain: return scan_data
  SecurityMain->>JSONFile: write aquasec_scan.json
  NightlyWorkflow->>WorkflowArtifact: upload aquasec_scan.json as aquasec-night-scan
Loading

Suggested reviewers: miroslavpojer

Poem

A rabbit found findings, both tidy and bright,
Packed them in JSON by moonbeam light.
The night workflow carried the scan in its hat,
Then stored every severity safe and flat.
Hop, hop—artifacts bloom! 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: exporting fetched AquaSec JSON as a workflow artifact.
Description check ✅ Passed The description includes Overview, Release Notes, and Related sections with the linked issue, matching the template well.
Linked Issues check ✅ Passed The PR adds the AquaSec findings artifact and writes the fetched scan JSON, satisfying [#88]'s all-severities requirement.
Out of Scope Changes check ✅ Passed All changes support the artifact export feature; no unrelated code paths or broad refactors are introduced.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/88-add-aqua-json-artifact

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Checkov (3.3.8)
.github/workflows/aquasec-scan.yml

Traceback (most recent call last):
File "/usr/local/bin/checkov", line 2, in
from checkov.main import Checkov
ModuleNotFoundError: No module named 'checkov'


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
tests/core/test_helpers.py (1)

106-110: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add type hints to the new public test functions.

  • tests/core/test_helpers.py#L106-L110: annotate tmp_path as Path.
  • tests/security/test_main.py#L137-L151: annotate mocker as MockerFixture and add -> None to both tests.

As per coding guidelines, Python public functions must use type hints.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/core/test_helpers.py` around lines 106 - 110, Add the requested type
hints to the new public tests: in tests/core/test_helpers.py lines 106-110,
annotate the tmp_path parameter of test_write_json_writes_indented_content as
Path; in tests/security/test_main.py lines 137-151, annotate each test’s mocker
parameter as MockerFixture and add -> None return annotations to both test
functions.

Source: Coding guidelines

src/core/helpers.py (1)

54-55: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use a Google-style docstring for the new public helper.

Document path and data under an Args: section.

Proposed change
 def write_json(path: str, data: Any) -> None:
-    """Write *data* to *path* as indented JSON (UTF-8)."""
+    """Write data to an indented UTF-8 JSON file.
+
+    Args:
+        path: Destination file path.
+        data: JSON-serializable data to write.
+    """

As per coding guidelines, public functions and classes must use Google-style docstrings.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/core/helpers.py` around lines 54 - 55, Update the public write_json
function’s docstring to Google style by adding an Args: section documenting both
path and data, while retaining the existing description of its JSON and UTF-8
output behavior.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/aquasec-scan.yml:
- Around line 136-140: Update the artifact upload step in
.github/workflows/aquasec-scan.yml at lines 136-140 to run on non-cancelled
failures and suppress missing-file warnings. Update the documentation wording in
docs/security/security.md at lines 46-48 to accurately state that every
non-cancelled scan run uploads the artifact.

---

Nitpick comments:
In `@src/core/helpers.py`:
- Around line 54-55: Update the public write_json function’s docstring to Google
style by adding an Args: section documenting both path and data, while retaining
the existing description of its JSON and UTF-8 output behavior.

In `@tests/core/test_helpers.py`:
- Around line 106-110: Add the requested type hints to the new public tests: in
tests/core/test_helpers.py lines 106-110, annotate the tmp_path parameter of
test_write_json_writes_indented_content as Path; in tests/security/test_main.py
lines 137-151, annotate each test’s mocker parameter as MockerFixture and add ->
None return annotations to both test functions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: dcd43623-676c-4f12-8164-f8f3c9f8abc6

📥 Commits

Reviewing files that changed from the base of the PR and between 3b6a6b0 and f13301e.

📒 Files selected for processing (8)
  • .github/workflows/aquasec-scan.yml
  • docs/security/security.md
  • src/core/helpers.py
  • src/security/config.py
  • src/security/main.py
  • tests/core/test_helpers.py
  • tests/security/test_config.py
  • tests/security/test_main.py

Comment on lines +136 to +140
- name: Upload scan findings artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
with:
name: aquasec-night-scan
path: aquasec_scan.json

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== workflow excerpt =="
if [ -f .github/workflows/aquasec-scan.yml ]; then
  nl -ba .github/workflows/aquasec-scan.yml | sed -n '1,220p'
else
  echo "missing .github/workflows/aquasec-scan.yml"
fi

echo
echo "== docs excerpt =="
if [ -f docs/security/security.md ]; then
  nl -ba docs/security/security.md | sed -n '35,60p'
else
  echo "missing docs/security/security.md"
fi

echo
echo "== search relevant actions =="
rg -n "upload-artifact|aquasec_scan|scan Artifact|aquasec-night-scan|if-no-files-found|cancelled\\(\\)" .github docs || true

echo
echo "== git status/diff stat =="
git status --short
git diff --stat HEAD~1..HEAD 2>/dev/null || git diff --stat 2>/dev/null || true

Repository: AbsaOSS/organizational-workflows

Length of output: 233


🏁 Script executed:

#!/bin/sh
set -euo pipefail

echo "== workflow file size and excerpt =="
if [ -f .github/workflows/aquasec-scan.yml ]; then
  wc -l .github/workflows/aquasec-scan.yml
  awk 'NR>=1 && NR<=220 {printf "%6d\t%s\n", NR, $0}' .github/workflows/aquasec-scan.yml
else
  echo "missing .github/workflows/aquasec-scan.yml"
fi

echo
echo "== docs excerpt =="
if [ -f docs/security/security.md ]; then
  wc -l docs/security/security.md
  awk 'NR>=35 && NR<=60 {printf "%6d\t%s\n", NR, $0}' docs/security/security.md
else
  echo "missing docs/security/security.md"
fi

echo
echo "== search relevant actions =="
rg -n "upload-artifact|aquasec_scan|Scan Artifact|aquasec-night-scan|if-no-files-found|cancelled\\(\\)" .github docs || true

echo
echo "== git status/diff stat =="
git status --short || true
git diff --stat HEAD~1..HEAD 2>/dev/null || git diff --stat 2>/dev/null || true

Repository: AbsaOSS/organizational-workflows

Length of output: 10225


🌐 Web query:

actions/upload-artifact v4 behavior when workflow job fails does it upload artifact if files already exist skipped unless continue-on-error

💡 Result:

In GitHub Actions, the actions/upload-artifact@v4 action does not automatically upload files if a job fails; standard steps in a workflow job are skipped when a previous step fails or the job itself enters a failed state [1][2][3]. To ensure an artifact is uploaded even when a job fails, you must explicitly use the if: failure or if: always conditional on the upload step [1][3]. Regarding the behavior of v4: - Artifacts are immutable once created [4][5]. - Uploading to an artifact name that already exists in the same workflow run will cause an error (Conflict: 409) [4][6]. - If you use the overwrite: true option, the action will attempt to delete the existing artifact with that name before creating the new one [7][8]. However, this is not atomic and is intended for serial operations (e.g., modifying a file and re-uploading), not for parallel jobs trying to merge data into a single artifact [9]. - If a job fails, and you have not configured the upload step with an appropriate conditional like if: failure, that step will be skipped and no artifact will be uploaded from that job [1][2]. In summary, the action does not have a built-in mechanism to "catch" and upload artifacts upon failure unless you explicitly configure the step to run under those conditions using GitHub Actions workflow syntax [1][3].

Citations:


🌐 Web query:

actions/upload-artifact if-no-files-found ignore continue run on failed job

💡 Result:

The if-no-files-found input for the actions/upload-artifact GitHub Action is used to control the behavior of the step when no files are matched by the specified path. It accepts three values [1][2]: - warn (default): Prints a warning to the logs but the action completes successfully [1][2]. - error: Fails the action with an error message [1][2]. - ignore: Neither prints a warning nor fails the action [1][2]. This option does not inherently control whether the action runs on a failed job; that is a separate configuration concern [3]. To ensure that an artifact upload step executes even if previous steps in the job have failed, you must use the if: always() or if: failure() conditional expression [3]. Example usage: - uses: actions/upload-artifact@v7 if: always with: name: my-artifact path: path/to/files/ if-no-files-found: ignore In this configuration, the artifact step will always attempt to run (even if earlier steps failed) and will not error or warn if the specified files are missing [1][3][2].

Citations:


Upload fetched findings even when later pipeline stages fail.

main.py writes aquasec_scan.json before parsing, synchronization, and notification, but the artifact step is skipped after a failure by default. As written, the docs line that says every scan run uploads the artifact is only true when the whole job succeeds.

  • .github/workflows/aquasec-scan.yml#L136-L140: condition the upload on non-cancelled failures and suppress the missing-file warning.
  • docs/security/security.md#L46-L48: either narrow the wording to successful runs or update the docs after making upload failure-safe.
📍 Affects 2 files
  • .github/workflows/aquasec-scan.yml#L136-L140 (this comment)
  • docs/security/security.md#L46-L48
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/aquasec-scan.yml around lines 136 - 140, Update the
artifact upload step in .github/workflows/aquasec-scan.yml at lines 136-140 to
run on non-cancelled failures and suppress missing-file warnings. Update the
documentation wording in docs/security/security.md at lines 46-48 to accurately
state that every non-cancelled scan run uploads the artifact.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add fetched AquaSec JSON as an workflow artefact

1 participant