Skip to content

Commit 0a7cbf1

Browse files
authored
Merge pull request #72 from Particular/nuget-audit-cve-output-gating
Update NuGet audit CVE handling
2 parents e123c0f + 6556da3 commit 0a7cbf1

2 files changed

Lines changed: 18 additions & 17 deletions

File tree

.github/workflows/nuget-audit.yml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,20 @@ jobs:
2020
global-json-file: global.json
2121
- name: .NET Restore
2222
id: restore
23-
shell: bash
23+
shell: bash
2424
run: |
25-
mkdir ${{ github.workspace }}/results
26-
touch ${{ github.workspace }}/results/dotnetrestore.log
27-
set +e +o pipefail
28-
CVECOUNT=$(dotnet restore src | tee ${{ github.workspace }}/results/dotnetrestore.log | grep -c -e "NU190[1-4]")
29-
set -e -o pipefail
30-
while read -r line; do
31-
echo "$line"
32-
done < ${{ github.workspace }}/results/dotnetrestore.log
33-
exit $CVECOUNT
34-
- name: Upload results on failure
35-
if: ${{ failure() }}
25+
mkdir -p ${{ github.workspace }}/results
26+
27+
dotnet restore src > "${{ github.workspace }}/results/dotnetrestore.log" 2>&1 || true
28+
cat "${{ github.workspace }}/results/dotnetrestore.log"
29+
30+
CVECOUNT=$(awk '/NU190[1-4]/ { count++ } END { print count + 0 }' "${{ github.workspace }}/results/dotnetrestore.log")
31+
32+
echo "cvecount=${CVECOUNT}" >> "$GITHUB_OUTPUT"
33+
34+
echo "Found $CVECOUNT CVEs"
35+
- name: Upload results when CVEs detected
36+
if: ${{ steps.restore.outputs.cvecount > 0 }}
3637
shell: bash
3738
working-directory: ./src
3839
run: |
@@ -44,8 +45,8 @@ jobs:
4445
-F "restoreDataFile=@${{ github.workspace }}/results/restoreData.json" \
4546
-H "x-functions-key: ${{ secrets.FUNCTIONS_AUTHKEY }}" \
4647
${{ secrets.PROCESSNUGETAUDITRESULTS_URL }}
47-
- name: Archive files on failure
48-
if: ${{ failure() }}
48+
- name: Archive files when CVEs detected
49+
if: ${{ steps.restore.outputs.cvecount > 0 }}
4950
uses: actions/upload-artifact@v7
5051
with:
5152
name: files

docs/nuget-audit.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ The workflow detects if `dotnet restore` reports any of the following warning co
2323
- NU1903
2424
- NU1904
2525

26-
If so it will exit with a number equal to the number of warning codes detected (total, not distinct), causing it to fail the workflow if any are detected.
26+
If so it records a `cvecount` step output equal to the number of warning codes detected (total, not distinct). The follow-up upload and archive steps run when that output is greater than zero.
2727

2828
### Restore data file
2929

30-
If the workflow has failed because [CVEs have been detected](#cve-detection-mechanism), the workflow gathers information for further processing by [Internal Automation](https://github.com/Particular/InternalAutomation):
30+
If [CVEs have been detected](#cve-detection-mechanism), the workflow gathers information for further processing by [Internal Automation](https://github.com/Particular/InternalAutomation):
3131

3232
- The GitHub repository ID that called this shared workflow
3333
- The name of the repository branch that called this shared workflow
@@ -40,4 +40,4 @@ The workflow uploads this data via a curl command to the `ProcessNuGetAuditResul
4040

4141
### Archives
4242

43-
The workflow archives the files created as well as a log file that outputs the results of the `dotnet restore`.
43+
The workflow archives the files created as well as a log file that outputs the results of the `dotnet restore`.

0 commit comments

Comments
 (0)