Expose versioned JSON results from the Policy as Code Action - #209
Merged
Conversation
Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add option for structured output in policy-as-code action
Expose versioned JSON results from the Policy as Code Action
Aug 18, 2026
felickz
marked this pull request as ready for review
August 18, 2026 22:47
Contributor
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Contributor
There was a problem hiding this comment.
Review details
Suppressed comments (2)
README.md:77
- The example step name says "Advance Security Policy as Code"; this reads like a typo and should be "Advanced Security Policy as Code" for consistency and clarity.
- name: Advance Security Policy as Code
ghascompliance/main.py:249
errorsis incremented both for policy violations and for runtime/authentication exceptions, so writing it astotal_violationscan make the JSON output misleading (and can diverge from the sum of per-check counts). Consider emitting the sum of per-check violation counts astotal_violations.
write_results(arguments.output, errors, check_results)
- Files reviewed: 5/5 changed files
- Comments generated: 1
- Review effort level: Lite
Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Review details
Suppressed comments (2)
README.md:67
- The README’s quick-start workflow snippet still uses “Advance Security …” (missing “d”), which can propagate the typo into users’ workflows. Please align it with the project name (“Advanced Security …”).
uses: advanced-security/policy-as-code@v2.11.1
action.yml:62
- The composite action’s main step invokes
python3, but the results step already accounts for environments where onlypythonis available. For better runner portability (notably Windows bash), preferpythonwith apython3fallback for running the CLI as well.
export PYTHONPATH=${{ github.action_path }}:${{ github.action_path }}/vendor
python3 -m ghascompliance \
- Files reviewed: 5/5 changed files
- Comments generated: 0 new
- Review effort level: Lite
Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Review details
Suppressed comments (1)
Previously missed (1) — in code that hasn't changed since the last review.
action.yml:61
- This composite action runs the CLI via
python3 -m ghascompliancein the policy step. On some runners (notably Windows withactions/setup-python),python3may not be available even whenpythonis. Consider invoking the CLI withpythonso the action consistently uses the configured Python across platforms.
- id: policy
shell: bash
run: |
echo "Running Policy as Code..."
export PYTHONPATH=${{ github.action_path }}:${{ github.action_path }}/vendor
- Files reviewed: 5/5 changed files
- Comments generated: 3
- Review effort level: Lite
…ck schema - action.yml: set total_errors to null (not 1) in the fallback JSON emitted when the results file is missing, keeping it consistent with total_violations being null since the real count is unknown. - action.yml: update the results output description to mention the fallback payload contract. - README.md: document the fallback payload schema with an example. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 5ba23ba2-e979-47aa-b538-49f686ab6eb9
Contributor
There was a problem hiding this comment.
Review details
Suppressed comments (2)
Previously missed (1) — in code that hasn't changed since the last review.
action.yml:88
- The results-output step only checks
-fbefore runningcat. If the file exists but is unreadable (permissions, transient I/O errors, etc.),catwill exit non-zero and—because GitHub Actions bash runs with-e—this step can fail, preventing the fallback JSON from being emitted. Consider checking readability (-r) and/or falling back whencatfails so theresultsoutput is always set.
if [ -f "$RESULTS_FILE" ]; then
cat "$RESULTS_FILE"
else
printf '%s\n' '{"schema_version":1,"total_violations":null,"total_errors":null,"checks":{},"error":"Results file was not found; the run may have failed before writing results"}'
README.md:70
- The quick-start YAML snippet just above this section still says “Advance Security …” (missing the “d”), while the rest of the README uses “Advanced Security …”. This inconsistency can propagate the typo into users’ workflows.
#### Structured results
- Files reviewed: 5/5 changed files
- Comments generated: 0 new
- Review effort level: Lite
| run: echo '${{ fromJSON(steps.policy.outputs.results).total_violations }}' | ||
| ``` | ||
|
|
||
| The JSON schema is: |
| shell: bash | ||
| run: | | ||
| echo "Running Policy as Code..." | ||
| export PYTHONPATH=${{ github.action_path }}:${{ github.action_path }}/vendor |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds structured Policy as Code results for downstream workflow steps and external integrations, while retaining existing workflow summaries.
Action output
resultsas JSON through composite Action outputs.Result file
.compliance/results.jsonby default.outputinput and CLI--outputoption for custom locations.Schema
{ "schema_version": 1, "total_violations": 2, "checks": { "code_scanning": 1, "dependabot": 1 } }