Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add outputs for the changes data #707

Merged
merged 13 commits into from
Mar 20, 2024
36 changes: 35 additions & 1 deletion .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,39 @@ jobs:
steps:
- name: 'Checkout Repository'
uses: actions/checkout@v4
- name: Dependency Review

- name: 'Dependency Review'
uses: actions/dependency-review-action@main
id: review

- name: 'Check comment-content output'
if: always()
env:
COMMENT: ${{ steps.review.outputs.comment-content }}
run: |
test -n "$COMMENT"
echo "$COMMENT"

febuiles marked this conversation as resolved.
Show resolved Hide resolved
- name: 'Check dependency-changes output'
if: always()
env:
DEPENDENCY_CHANGES: ${{ steps.review.outputs.dependency-changes }}
run: echo "$DEPENDENCY_CHANGES" | jq

- name: 'Check vulnerable-changes output'
if: always()
env:
VULNERABLE_CHANGES: ${{ steps.review.outputs.vulnerable-changes }}
run: echo "$VULNERABLE_CHANGES" | jq

- name: 'Check invalid-license-changes output'
if: always()
env:
LICENSE_CHANGES: ${{ steps.review.outputs.invalid-license-changes }}
run: echo "$LICENSE_CHANGES" | jq

- name: 'Check denied-changes output'
if: always()
env:
DENIED_CHANGES: ${{ steps.review.outputs.denied-changes }}
run: echo "$DENIED_CHANGES" | jq
febuiles marked this conversation as resolved.
Show resolved Hide resolved
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,14 @@ The Dependency Review GitHub Action check will only block a pull request from be

## Outputs

`comment-content` is generated with the same content as would be present in a Dependency Review Action comment.
- `comment-content` is generated with the same content as would be present in a Dependency Review Action comment.
- `dependency-changes` holds all dependency changes in a JSON format. The following outputs are subsets of `dependency-changes` filtered based on the configuration:
- `vulnerable-changes` holds information about dependency changes with vulnerable dependencies in a JSON format.
- `invalid-license-changes` holds information about invalid or non-compliant license dependency changes in a JSON format.
- `denied-changes` holds information about denied dependency changes in a JSON format.
laughedelic marked this conversation as resolved.
Show resolved Hide resolved

> [!NOTE]
> Action outputs [have a size limit](https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#outputs-for-docker-container-and-javascript-actions): outputs are Unicode strings, and can be a maximum of 1MB
laughedelic marked this conversation as resolved.
Show resolved Hide resolved

## Getting help

Expand Down
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ inputs:
outputs:
comment-content:
description: Prepared dependency report comment
dependency-changes:
description: All dependency changes (JSON)
vulnerable-changes:
description: Vulnerable dependency changes (JSON)
invalid-license-changes:
description: Invalid license dependency changes (JSON)
denied-changes:
description: Denied dependency changes (JSON)

runs:
using: 'node20'
Expand Down
4 changes: 4 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

19 changes: 14 additions & 5 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ jobs:

## Getting the results of the action in a later step

Using the `comment-content` output you can get the results of the action in a workflow step.
- Using the `comment-content` output you can get the results of the action in a workflow step.
- Using other outputs like `dependency-changes`, `vulnerable-changes`, `invalid-license-changes` and `denied-changes` you can get the results of the action in JSON format and use them in a programmatic way.
laughedelic marked this conversation as resolved.
Show resolved Hide resolved

```yaml
name: 'Dependency Review'
Expand All @@ -190,12 +191,20 @@ jobs:
deny-licenses: LGPL-2.0, BSD-2-Clause
- name: 'Report'
# make sure this step runs even if the previous failed
if: ${{ failure() && steps.review.conclusion == 'failure' }}
if: always()
laughedelic marked this conversation as resolved.
Show resolved Hide resolved
shell: bash
env:
comment: ${{ steps.review.outputs.comment-content }}
run: |
echo "$comment" # do something with the comment
COMMENT: ${{ steps.review.outputs.comment-content }}
run: | # do something with the comment:
echo "$COMMENT"
- name: 'List vulnerable dependencies'
# make sure this step runs even if the previous failed
if: always()
laughedelic marked this conversation as resolved.
Show resolved Hide resolved
shell: bash
env:
VULNERABLE_CHANGES: ${{ steps.review.outputs.vulnerable-changes }}
run: | # do something with the JSON:
echo "$VULNERABLE_CHANGES" | jq '.[].package_url'
```

## Exclude dependencies from the license check
Expand Down
7 changes: 7 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,25 @@ async function run(): Promise<void> {
}

if (config.vulnerability_check) {
core.setOutput('vulnerable-changes', JSON.stringify(vulnerableChanges))
febuiles marked this conversation as resolved.
Show resolved Hide resolved
summary.addChangeVulnerabilitiesToSummary(vulnerableChanges, minSeverity)
printVulnerabilitiesBlock(vulnerableChanges, minSeverity, warnOnly)
}
if (config.license_check) {
core.setOutput(
'invalid-license-changes',
JSON.stringify(invalidLicenseChanges)
)
summary.addLicensesToSummary(invalidLicenseChanges, config)
printLicensesBlock(invalidLicenseChanges, warnOnly)
}
if (config.deny_packages || config.deny_groups) {
core.setOutput('denied-changes', JSON.stringify(deniedChanges))
summary.addDeniedToSummary(deniedChanges)
printDeniedDependencies(deniedChanges, config)
}

core.setOutput('dependency-changes', JSON.stringify(changes))
summary.addScannedDependencies(changes)
printScannedDependencies(changes)
await commentPr(core.summary, config)
Expand Down