Skip to content

Commit

Permalink
fix-semgrep
Browse files Browse the repository at this point in the history
  • Loading branch information
JosueUPT committed Dec 12, 2024
1 parent 83eedee commit 25edef8
Showing 1 changed file with 50 additions and 102 deletions.
152 changes: 50 additions & 102 deletions .github/workflows/php-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,46 @@ jobs:
- name: Update Semgrep HTML Report
run: |
mkdir -p public/semgrep
echo '<!DOCTYPE html>
# Primero creamos las variables con los datos
TOTAL_FILES=$(cat temp_results/total_files)
TOTAL_LINES=$(cat temp_results/total_lines)
SAFE_PERCENTAGE=$(cat temp_results/safe_percentage)
CURRENT_DATE=$(date "+%Y-%m-%d %H:%M:%S")
# Generamos el contenido de los hallazgos
FINDINGS_CONTENT=""
for file in temp_results/*.txt; do
[[ $(basename "$file") == "total_files" ]] && continue
[[ $(basename "$file") == "total_lines" ]] && continue
[[ $(basename "$file") == "safe_percentage" ]] && continue
filename=$(head -n 1 "$file" | cut -d "=" -f2 | tr -d " ")
lines=$(sed -n "2p" "$file")
functions=$(sed -n "/=== FUNCIONES ===/,/=== PATRONES ===/p" "$file" | grep -v "===")
patterns=$(tail -n 5 "$file")
FINDINGS_CONTENT+="<div class=\"finding\">"
FINDINGS_CONTENT+="<div class=\"file-header\">$filename</div>"
FINDINGS_CONTENT+="<div class=\"issue\">"
FINDINGS_CONTENT+="<div class=\"issue-title\">Análisis de Seguridad</div>"
FINDINGS_CONTENT+="<div class=\"details\">"
FINDINGS_CONTENT+="<ul>"
FINDINGS_CONTENT+="<li>Líneas totales: $lines</li>"
FINDINGS_CONTENT+="<li>$patterns</li>"
FINDINGS_CONTENT+="</ul>"
FINDINGS_CONTENT+="<h4>Funciones detectadas:</h4>"
FINDINGS_CONTENT+="<div class=\"code-snippet\">"
FINDINGS_CONTENT+="$functions"
FINDINGS_CONTENT+="</div>"
FINDINGS_CONTENT+="</div>"
FINDINGS_CONTENT+="</div>"
FINDINGS_CONTENT+="</div>"
done
# Ahora generamos el HTML usando las variables
cat > public/semgrep/index.html << EOL
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
Expand All @@ -465,71 +504,7 @@ jobs:
margin: 40px;
background-color: #f5f5f5;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
background-color: white;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
.finding {
margin: 20px 0;
padding: 15px;
border: 1px solid #ddd;
border-radius: 5px;
background-color: #fff;
}
.file-header {
font-size: 1.2em;
font-weight: bold;
color: #333;
margin-bottom: 10px;
padding-bottom: 5px;
border-bottom: 2px solid #eee;
}
.issue {
margin: 10px 0;
padding: 10px;
background-color: #f8f9fa;
border-left: 4px solid #dc3545;
}
.issue-title {
font-weight: bold;
color: #dc3545;
}
.code-snippet {
font-family: monospace;
background-color: #f8f9fa;
padding: 10px;
border-radius: 4px;
margin: 10px 0;
white-space: pre-wrap;
}
.details {
margin-top: 5px;
font-size: 0.9em;
color: #666;
}
.summary {
margin: 20px 0;
padding: 15px;
background-color: #f8f9fa;
border-radius: 5px;
}
.stats {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 20px;
margin: 20px 0;
}
.stat-card {
background: white;
padding: 15px;
border-radius: 5px;
text-align: center;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
/* ... resto de estilos ... */
</style>
</head>
<body>
Expand All @@ -541,61 +516,34 @@ jobs:
<div class="stats">
<div class="stat-card">
<h3>Archivos Analizados</h3>
<p>'$(cat temp_results/total_files)' archivos</p>
<p>${TOTAL_FILES} archivos</p>
</div>
<div class="stat-card">
<h3>Total Líneas</h3>
<p>'$(cat temp_results/total_lines)' líneas</p>
<p>${TOTAL_LINES} líneas</p>
</div>
<div class="stat-card">
<h3>Código Seguro</h3>
<p>'$(cat temp_results/safe_percentage)'%</p>
<p>${SAFE_PERCENTAGE}%</p>
</div>
</div>
</div>
<h2>Hallazgos por Archivo</h2>
'"$(for file in temp_results/*.txt; do
[[ $(basename "$file") == "total_files" ]] && continue
[[ $(basename "$file") == "total_lines" ]] && continue
[[ $(basename "$file") == "safe_percentage" ]] && continue
filename=$(head -n 1 "$file" | cut -d "=" -f2 | tr -d " ")
lines=$(sed -n "2p" "$file")
functions=$(sed -n "/=== FUNCIONES ===/,/=== PATRONES ===/p" "$file" | grep -v "===")
patterns=$(tail -n 5 "$file")
echo "<div class=\"finding\">"
echo "<div class=\"file-header\">$filename</div>"
echo "<div class=\"issue\">"
echo "<div class=\"issue-title\">Análisis de Seguridad</div>"
echo "<div class=\"details\">"
echo "<ul>"
echo "<li>Líneas totales: $lines</li>"
echo "<li>$patterns</li>"
echo "</ul>"
echo "<h4>Funciones detectadas:</h4>"
echo "<div class=\"code-snippet\">"
echo "$functions"
echo "</div>"
echo "</div>"
echo "</div>"
echo "</div>"
done)"'
${FINDINGS_CONTENT}
<div class="summary">
<h2>Notas Adicionales</h2>
<ul>
<li>Análisis completado: '$(date "+%Y-%m-%d %H:%M:%S")'</li>
<li>Total archivos analizados: '$(cat temp_results/total_files)'</li>
<li>Total líneas de código: '$(cat temp_results/total_lines)'</li>
<li>Análisis completado: ${CURRENT_DATE}</li>
<li>Total archivos analizados: ${TOTAL_FILES}</li>
<li>Total líneas de código: ${TOTAL_LINES}</li>
</ul>
</div>
</div>
</body>
</html>' > public/semgrep/index.html
</html>
EOL
# Limpiar archivos temporales
rm -rf temp_results
Expand Down

0 comments on commit 25edef8

Please sign in to comment.