-
Notifications
You must be signed in to change notification settings - Fork 0
151 lines (138 loc) · 5.62 KB
/
Copy pathcheck-vulns.yml
File metadata and controls
151 lines (138 loc) · 5.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
name: Reusable flow to check for vulns in dependencies of a Nsolid branch
on:
workflow_call:
inputs:
nsolidStream:
type: string
default: 'main'
secrets:
NVD_API_KEY:
required: true
workflow_dispatch:
inputs:
nsolidStream:
type: string
default: 'main'
permissions:
contents: read
issues: write
jobs:
check-vulns:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set_matrix.outputs.matrix }}
steps:
- name: Setup Python 3.11
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Verify Node.js and npm installation
run: |
echo "Node.js version:"
node --version
echo "npm version:"
npm --version
echo "Python version:"
python3 --version
- name: Checkout current repository
uses: actions/checkout@v4
- name: Debug directory structure
run: |
echo "Current directory:"
pwd
echo "Directory contents:"
ls -la
echo "dep_checker directory exists:"
ls -la dep_checker/ || echo "dep_checker directory not found"
- name: Installing pre-reqs
working-directory: ./dep_checker
run: pip install -r requirements.txt
- name: Checkout Nsolid repo
uses: actions/checkout@v4
with:
repository: nodesource/nsolid
path: nsolid
ref: ${{ inputs.nsolidStream }}
- name: Run the check
working-directory: ./dep_checker
run: |
(
set -o pipefail
python3 main.py --json-output --include-npm --npm-timeout 600 --gh-token ${{ secrets.GITHUB_TOKEN }} --nvd-key=${{ secrets.NVD_API_KEY }} ../nsolid ${{ inputs.nsolidStream }} 2>&1 | tee result.log
)
cat result.log
- name: build matrix
id: set_matrix
if: ${{ failure() }}
working-directory: ./dep_checker
run: |
# Extract vulnerabilities JSON from the log
vulnerabilities_json=$(grep -o '{.*}' result.log | tail -1)
echo "Raw vulnerabilities JSON: $vulnerabilities_json"
# Use the matrix formatter to build the complete matrix with labels
matrix=$(python3 ../.github/workflows/format_matrix.py "$vulnerabilities_json" "${{ inputs.nsolidStream }}")
echo "Formatted matrix: $matrix"
echo "matrix=$matrix" >> $GITHUB_OUTPUT
create-issues:
needs: check-vulns
if: ${{ always() }}
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJson(needs.check-vulns.outputs.matrix) }}
max-parallel: 1
steps:
- uses: actions/checkout@v4
- name: Debug matrix data
run: |
echo "Matrix vulnerability data:"
echo "ID: ${{ matrix.vulnerabilities.id }}"
echo "Dependency: ${{ matrix.vulnerabilities.dependency }}"
echo "Source: ${{ matrix.vulnerabilities.source }}"
echo "Labels: ${{ join(matrix.vulnerabilities.labels, ', ') }}"
echo "ISSUE_LABELS: ${{ join(matrix.vulnerabilities.labels, ',') }}"
- name: Create or update GitHub issue
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Set variables
VULN_ID="${{ matrix.vulnerabilities.id }}"
VULN_URL="${{ matrix.vulnerabilities.url }}"
VULN_DEP_NAME="${{ matrix.vulnerabilities.dependency }}"
VULN_DEP_VERSION="${{ matrix.vulnerabilities.version }}"
VULN_SOURCE="${{ matrix.vulnerabilities.source }}"
VULN_MAIN_DEP_NAME="${{ matrix.vulnerabilities.main_dep_name }}"
VULN_MAIN_DEP_PATH="${{ matrix.vulnerabilities.main_dep_path }}"
NODEJS_STREAM="${{ inputs.nsolidStream }}"
ACTION_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
LABELS="${{ join(matrix.vulnerabilities.labels, ',') }}"
# Create issue title
ISSUE_TITLE="${VULN_ID} (${VULN_DEP_NAME}) found on ${NODEJS_STREAM}"
# Create issue body
ISSUE_BODY="A new vulnerability for ${VULN_DEP_NAME} ${VULN_DEP_VERSION} was found:
Vulnerability ID: ${VULN_ID}
Vulnerability URL: ${VULN_URL}"
# Add npm-specific info if applicable
if [ "${VULN_SOURCE}" = "npm" ] && [ -n "${VULN_MAIN_DEP_NAME}" ]; then
ISSUE_BODY="${ISSUE_BODY}
Main Dependency: ${VULN_MAIN_DEP_NAME}
Main Dependency Path: ${VULN_MAIN_DEP_PATH}"
fi
ISSUE_BODY="${ISSUE_BODY}
Failed run: ${ACTION_URL}"
# Check if issue already exists
EXISTING_ISSUE=$(gh issue list --search "in:title ${ISSUE_TITLE}" --state open --json number,title --jq '.[] | select(.title == "'"${ISSUE_TITLE}"'") | .number')
if [ -n "${EXISTING_ISSUE}" ]; then
echo "Updating existing issue #${EXISTING_ISSUE}: ${ISSUE_TITLE}"
gh issue edit "${EXISTING_ISSUE}" --body "${ISSUE_BODY}"
echo "Updated issue: https://github.com/${{ github.repository }}/issues/${EXISTING_ISSUE}"
else
echo "Creating new issue: ${ISSUE_TITLE}"
# Create issue and capture the URL, then extract issue number
ISSUE_URL=$(gh issue create --title "${ISSUE_TITLE}" --body "${ISSUE_BODY}" --label "${LABELS}")
ISSUE_NUMBER=$(echo "${ISSUE_URL}" | sed 's/.*\/issues\///')
echo "Created issue: ${ISSUE_URL}"
fi