Skip to content

Commit 17a5afb

Browse files
authored
chore: socket (#21096)
.
2 parents 909206a + 4938ff8 commit 17a5afb

2 files changed

Lines changed: 25 additions & 19 deletions

File tree

scripts/socket-fix-ci.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ REPO="${GITHUB_REPOSITORY:-AztecProtocol/aztec-packages}"
1515
echo "Installing socket CLI..."
1616
npm install -g socket
1717

18+
# --- Configure socket org (enables server-side bulk analysis) ---
19+
export SOCKET_CLI_ORG_SLUG=AztecProtocol
20+
1821
# --- Configure git ---
1922
git config user.name AztecBot
2023
git config user.email tech@aztecprotocol.com

scripts/socket-fix.sh

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ log "Workspaces: $WORKSPACES"
9797
# Build an associative array: GHSA_ID -> "workspace1 workspace2 ..."
9898
declare -A GHSA_WORKSPACES
9999
declare -A GHSA_SEVERITY
100+
GHSA_COUNT=0
100101

101102
for workspace in $WORKSPACES; do
102103
log "========================================="
@@ -105,11 +106,10 @@ for workspace in $WORKSPACES; do
105106

106107
output_file="/tmp/socket-fix-${workspace}-discovery.json"
107108

108-
# CI= unsets the CI env var so socket CLI runs in interactive mode (avoids CI-only behavior)
109-
if ! CI= socket fix --all --no-apply-fixes --output-file "$output_file" "$workspace/" 2>&1; then
110-
warn "socket fix dry run failed in $workspace, skipping"
111-
continue
112-
fi
109+
# CI= unsets the CI env var so socket CLI runs in interactive mode (avoids CI-only behavior).
110+
# Don't skip the workspace on non-zero exit — socket may still have written partial results.
111+
CI= socket fix --all --no-apply-fixes --output-file "$output_file" "$workspace/" 2>&1 || \
112+
warn "socket fix dry run returned non-zero in $workspace, attempting to parse output anyway"
113113

114114
# Extract GHSA IDs from the structured JSON output (keys of the "fixes" object)
115115
ghsa_ids=$(jq -r '.fixes | keys[]' "$output_file" 2>/dev/null | sort -u || true)
@@ -127,6 +127,7 @@ for workspace in $WORKSPACES; do
127127
warn "Could not determine severity for $ghsa_id, treating as unknown"
128128
fi
129129
GHSA_SEVERITY[$ghsa_id]="$sev"
130+
GHSA_COUNT=$((GHSA_COUNT + 1))
130131
fi
131132

132133
# Track which workspaces this GHSA affects
@@ -142,26 +143,28 @@ done
142143
QUALIFYING_GHSAS=()
143144
SKIPPED_GHSAS=()
144145

145-
for ghsa_id in "${!GHSA_SEVERITY[@]}"; do
146-
sev="${GHSA_SEVERITY[$ghsa_id]}"
147-
sev_num=$(severity_to_num "$sev")
146+
if [[ $GHSA_COUNT -gt 0 ]]; then
147+
for ghsa_id in "${!GHSA_SEVERITY[@]}"; do
148+
sev="${GHSA_SEVERITY[$ghsa_id]}"
149+
sev_num=$(severity_to_num "$sev")
148150

149-
if [[ "$sev_num" -ge "$MIN_SEVERITY" ]]; then
150-
QUALIFYING_GHSAS+=("$ghsa_id")
151-
else
152-
SKIPPED_GHSAS+=("$ghsa_id($sev)")
153-
fi
154-
done
151+
if [[ "$sev_num" -ge "$MIN_SEVERITY" ]]; then
152+
QUALIFYING_GHSAS+=("$ghsa_id")
153+
else
154+
SKIPPED_GHSAS+=("$ghsa_id($sev)")
155+
fi
156+
done
157+
fi
155158

156159
# --- Summary of discovered vulnerabilities ---
157160
log "========================================="
158161
log "Discovery complete"
159162
log "========================================="
160-
log "Total GHSAs found: ${#GHSA_SEVERITY[@]}"
163+
log "Total GHSAs found: $GHSA_COUNT"
161164
log "Qualifying (>= $SEVERITY): ${#QUALIFYING_GHSAS[@]}"
162165
log "Skipped (below threshold): ${#SKIPPED_GHSAS[@]}"
163166

164-
if [[ ${#GHSA_SEVERITY[@]} -gt 0 ]]; then
167+
if [[ $GHSA_COUNT -gt 0 ]]; then
165168
log ""
166169
log "Vulnerability report:"
167170
for ghsa_id in "${!GHSA_SEVERITY[@]}"; do
@@ -185,7 +188,7 @@ if [[ "$DRY_RUN" == true ]]; then
185188
gh_output "skipped" "${SKIPPED_GHSAS[*]:-}"
186189
gh_output "qualifying_ids" "${QUALIFYING_GHSAS[*]:-}"
187190
gh_output "remaining_count" "${#QUALIFYING_GHSAS[@]}"
188-
gh_output "total_found" "${#GHSA_SEVERITY[@]}"
191+
gh_output "total_found" "$GHSA_COUNT"
189192
gh_output "qualifying_count" "${#QUALIFYING_GHSAS[@]}"
190193
exit 0
191194
fi
@@ -198,7 +201,7 @@ if [[ ${#QUALIFYING_GHSAS[@]} -eq 0 ]]; then
198201
gh_output "skipped" "${SKIPPED_GHSAS[*]:-}"
199202
gh_output "qualifying_ids" ""
200203
gh_output "remaining_count" "0"
201-
gh_output "total_found" "${#GHSA_SEVERITY[@]}"
204+
gh_output "total_found" "$GHSA_COUNT"
202205
gh_output "qualifying_count" "0"
203206
exit 0
204207
fi
@@ -264,5 +267,5 @@ gh_output "failed" "${FAILED[*]:-}"
264267
gh_output "skipped" "${SKIPPED_GHSAS[*]:-}"
265268
gh_output "qualifying_ids" "${QUALIFYING_GHSAS[*]:-}"
266269
gh_output "remaining_count" "${#FAILED[@]}"
267-
gh_output "total_found" "${#GHSA_SEVERITY[@]}"
270+
gh_output "total_found" "$GHSA_COUNT"
268271
gh_output "qualifying_count" "${#QUALIFYING_GHSAS[@]}"

0 commit comments

Comments
 (0)