From b5b0da7d8385c1450594483b2bc8d331a66453a9 Mon Sep 17 00:00:00 2001 From: "ana.alves" Date: Wed, 17 Dec 2025 10:35:14 -0300 Subject: [PATCH 01/25] ajusta logica do bloqueio de merge do codenarc para quebrar apenas em p1 no diff --- entrypoint.sh | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 89e231d..3cd72f3 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,11 +1,11 @@ #!/bin/sh set -e -trap 'rm -f result.txt >/dev/null 2>&1' EXIT + +trap 'rm -f result.txt reviewdog_output.txt >/dev/null 2>&1' EXIT run_codenarc() { report="${INPUT_REPORT:-compact:stdout}" includes_arg="" - if [ -n "$INPUT_SOURCE_FILES" ]; then includes_arg="-includes=${INPUT_SOURCE_FILES}" fi @@ -21,28 +21,41 @@ run_codenarc() { run_reviewdog() { echo "📤 Enviando resultados para reviewdog..." - < result.txt reviewdog -efm="%f:%l:%m" -efm="%f:%r:%m" \ + < result.txt reviewdog \ + -efm="%f:%l:%m" -efm="%f:%r:%m" \ -name="codenarc" \ -reporter="${INPUT_REPORTER:-github-pr-check}" \ -filter-mode="${INPUT_FILTER_MODE}" \ -fail-on-error="${INPUT_FAIL_ON_ERROR}" \ -level="${INPUT_LEVEL}" \ - ${INPUT_REVIEWDOG_FLAGS} + ${INPUT_REVIEWDOG_FLAGS} \ + -tee > reviewdog_output.txt } check_blocking_rules() { echo "🔎 Verificando violacoes bloqueantes (priority 1)..." - p1_count=$(grep -Eo "p1=[0-9]+" result.txt | cut -d'=' -f2 | head -1) - p1_count=${p1_count:-0} + p1_total=$(grep -Eo "p1=[0-9]+" result.txt | cut -d'=' -f2 | head -1) + p1_total=${p1_total:-0} + + p1_commented=0 + if [ -f "reviewdog_output.txt" ]; then + p1_commented=$(grep -cE "Priority[[:space:]]*1|priority[[:space:]]*1|P1" reviewdog_output.txt 2>/dev/null || echo 0) + fi + + echo "📊 Resumo CodeNarc → total_p1=${p1_total}, commented_p1=${p1_commented}" - echo "📊 Resumo CodeNarc → priority 1=${p1_count}" + echo "📑 Amostra do reviewdog_output.txt:" + head -n 20 reviewdog_output.txt || true - if [ "$p1_count" -gt 0 ]; then - echo "⛔ Foram encontradas violacoes bloqueantes (priority 1)." - echo "💡 Corrija as violacoes ou use o bypass autorizado pelo coordenador." + if [ "$p1_commented" -gt 0 ]; then + echo "⛔ Reviewdog comentou ${p1_commented} violacao(oes) P1 nas linhas alteradas!" + echo "💡 Corrija as violacoes P1 ou use o bypass autorizado pelo coordenador." + exit 1 + elif [ "$p1_total" -gt 0 ]; then + echo "⚠️ Existem ${p1_total} violacao(oes) P1 no arquivo, mas nao nas linhas alteradas (não bloqueia o merge)." else - echo "✅ Nenhuma violacao bloqueante (priority 1) encontrada." + echo "✅ Nenhuma violacao P1 encontrada." fi } From f141e8819139b213c09a0bdb0aff2f8a63943372 Mon Sep 17 00:00:00 2001 From: "ana.alves" Date: Wed, 17 Dec 2025 11:01:35 -0300 Subject: [PATCH 02/25] ajusta logica do bloqueio de merge do codenarc para quebrar apenas em p1 no diff --- entrypoint.sh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 3cd72f3..3de1cd6 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -34,17 +34,20 @@ run_reviewdog() { check_blocking_rules() { echo "🔎 Verificando violacoes bloqueantes (priority 1)..." - p1_total=$(grep -Eo "p1=[0-9]+" result.txt | cut -d'=' -f2 | head -1) p1_total=${p1_total:-0} p1_commented=0 if [ -f "reviewdog_output.txt" ]; then - p1_commented=$(grep -cE "Priority[[:space:]]*1|priority[[:space:]]*1|P1" reviewdog_output.txt 2>/dev/null || echo 0) + p1_commented=$(grep -cE "Priority[[:space:]]*1|priority[[:space:]]*1|P1" reviewdog_output.txt 2>/dev/null) fi - echo "📊 Resumo CodeNarc → total_p1=${p1_total}, commented_p1=${p1_commented}" + p1_total=${p1_total//[^0-9]/} + p1_total=${p1_total:-0} + p1_commented=${p1_commented//[^0-9]/} + p1_commented=${p1_commented:-0} + echo "📊 Resumo CodeNarc → total_p1=${p1_total}, commented_p1=${p1_commented}" echo "📑 Amostra do reviewdog_output.txt:" head -n 20 reviewdog_output.txt || true @@ -53,7 +56,7 @@ check_blocking_rules() { echo "💡 Corrija as violacoes P1 ou use o bypass autorizado pelo coordenador." exit 1 elif [ "$p1_total" -gt 0 ]; then - echo "⚠️ Existem ${p1_total} violacao(oes) P1 no arquivo, mas nao nas linhas alteradas (não bloqueia o merge)." + echo "⚠️ Existem ${p1_total} violacao(oes) P1 no arquivo, mas nao nas linhas alteradas (nao bloqueia o merge)." else echo "✅ Nenhuma violacao P1 encontrada." fi From 065bfdff28b3c99e5de9bc0c33f7d7db6a6db5b4 Mon Sep 17 00:00:00 2001 From: "ana.alves" Date: Wed, 17 Dec 2025 12:06:41 -0300 Subject: [PATCH 03/25] ajusta logica do bloqueio de merge do codenarc para quebrar apenas em p1 no diff --- entrypoint.sh | 59 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 3de1cd6..edb7fbf 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,7 +1,7 @@ #!/bin/sh set -e -trap 'rm -f result.txt reviewdog_output.txt >/dev/null 2>&1' EXIT +trap 'rm -f result.txt reviewdog_output.txt /tmp/diff.txt >/dev/null 2>&1' EXIT run_codenarc() { report="${INPUT_REPORT:-compact:stdout}" @@ -32,33 +32,55 @@ run_reviewdog() { -tee > reviewdog_output.txt } +generate_diff() { + echo "🔎 Gerando diff entre commits..." + if [ -n "$GITHUB_BASE_SHA" ] && [ -n "$GITHUB_HEAD_SHA" ]; then + echo " Base: $GITHUB_BASE_SHA" + echo " Head: $GITHUB_HEAD_SHA" + git fetch origin $GITHUB_BASE_SHA --depth=1 2>/dev/null || true + git fetch origin $GITHUB_HEAD_SHA --depth=1 2>/dev/null || true + git diff -U0 "$GITHUB_BASE_SHA" "$GITHUB_HEAD_SHA" > /tmp/diff.txt || true + else + echo "⚠️ Refs base/head nao encontradas, usando HEAD~1..." + git diff -U0 HEAD~1 > /tmp/diff.txt || true + fi +} + check_blocking_rules() { echo "🔎 Verificando violacoes bloqueantes (priority 1)..." p1_total=$(grep -Eo "p1=[0-9]+" result.txt | cut -d'=' -f2 | head -1) p1_total=${p1_total:-0} + echo "📊 Total de P1 encontradas pelo CodeNarc: ${p1_total}" - p1_commented=0 - if [ -f "reviewdog_output.txt" ]; then - p1_commented=$(grep -cE "Priority[[:space:]]*1|priority[[:space:]]*1|P1" reviewdog_output.txt 2>/dev/null) - fi + [ "$p1_total" -eq 0 ] && echo "✅ Nenhuma violacao P1 detectada." && return 0 - p1_total=${p1_total//[^0-9]/} - p1_total=${p1_total:-0} - p1_commented=${p1_commented//[^0-9]/} - p1_commented=${p1_commented:-0} + echo "🔍 Cruzando violacoes P1 com linhas alteradas..." + found=0 - echo "📊 Resumo CodeNarc → total_p1=${p1_total}, commented_p1=${p1_commented}" - echo "📑 Amostra do reviewdog_output.txt:" - head -n 20 reviewdog_output.txt || true + grep -E ':[0-9]+:' result.txt | while IFS=: read -r file line rest; do + [ -z "$file" ] && continue + if grep -q "$file" /tmp/diff.txt; then + if awk -v f="$file" -v l="$line" ' + $0 ~ ("diff --git a/"f) {infile=1} + infile && /^@@/ { + split($0,a," "); + if (match(a[3],/\+([0-9]+),?([0-9]+)?/,b)) { + start=b[1]; size=b[2]==""?1:b[2]; + if (l >= start && l < start+size) { print "match"; exit } + } + }' /tmp/diff.txt | grep -q match; then + echo "🚨 Violacao P1 no diff: $file:$line" + found=1 + fi + fi + done - if [ "$p1_commented" -gt 0 ]; then - echo "⛔ Reviewdog comentou ${p1_commented} violacao(oes) P1 nas linhas alteradas!" - echo "💡 Corrija as violacoes P1 ou use o bypass autorizado pelo coordenador." + if [ "$found" -eq 1 ]; then + echo "⛔ Foram encontradas violacoes P1 em linhas alteradas." + echo "💡 Corrija as violacoes ou utilize o bypass autorizado." exit 1 - elif [ "$p1_total" -gt 0 ]; then - echo "⚠️ Existem ${p1_total} violacao(oes) P1 no arquivo, mas nao nas linhas alteradas (nao bloqueia o merge)." else - echo "✅ Nenhuma violacao P1 encontrada." + echo "⚠️ Existem violacoes P1 no arquivo, mas fora das linhas alteradas (nao bloqueia o merge)." fi } @@ -71,6 +93,7 @@ export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}" run_codenarc run_reviewdog +generate_diff check_blocking_rules echo "🏁 Finalizado com sucesso." From 66b641ba05ed76a295f93f7a79c821970309b117 Mon Sep 17 00:00:00 2001 From: "ana.alves" Date: Wed, 17 Dec 2025 12:17:37 -0300 Subject: [PATCH 04/25] ajusta logica do bloqueio de merge do codenarc para quebrar apenas em p1 no diff --- entrypoint.sh | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index edb7fbf..9af90dc 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -9,7 +9,6 @@ run_codenarc() { if [ -n "$INPUT_SOURCE_FILES" ]; then includes_arg="-includes=${INPUT_SOURCE_FILES}" fi - echo "🔍 Executando CodeNarc..." java -jar /lib/codenarc-all.jar \ -report="$report" \ @@ -50,8 +49,8 @@ check_blocking_rules() { echo "🔎 Verificando violacoes bloqueantes (priority 1)..." p1_total=$(grep -Eo "p1=[0-9]+" result.txt | cut -d'=' -f2 | head -1) p1_total=${p1_total:-0} - echo "📊 Total de P1 encontradas pelo CodeNarc: ${p1_total}" + echo "📊 Total de P1 encontradas pelo CodeNarc: ${p1_total}" [ "$p1_total" -eq 0 ] && echo "✅ Nenhuma violacao P1 detectada." && return 0 echo "🔍 Cruzando violacoes P1 com linhas alteradas..." @@ -60,15 +59,18 @@ check_blocking_rules() { grep -E ':[0-9]+:' result.txt | while IFS=: read -r file line rest; do [ -z "$file" ] && continue if grep -q "$file" /tmp/diff.txt; then - if awk -v f="$file" -v l="$line" ' - $0 ~ ("diff --git a/"f) {infile=1} - infile && /^@@/ { - split($0,a," "); - if (match(a[3],/\+([0-9]+),?([0-9]+)?/,b)) { - start=b[1]; size=b[2]==""?1:b[2]; - if (l >= start && l < start+size) { print "match"; exit } + match=$(awk -v f="$file" -v l="$line" ' + BEGIN { in_file=0; hit=0 } + $0 ~ ("diff --git a/"f) { in_file=1 } + in_file && /^@@/ { + if (match($0, /\+([0-9]+)(,([0-9]+))?/, m)) { + start = m[1]; len = (m[3]=="" ? 1 : m[3]) + if (l >= start && l < start+len) { hit=1; exit } } - }' /tmp/diff.txt | grep -q match; then + } + END { if (hit==1) print "hit" } + ' /tmp/diff.txt) + if [ "$match" = "hit" ]; then echo "🚨 Violacao P1 no diff: $file:$line" found=1 fi From df19d661c47f64c4a76180c51701e3d0249b2921 Mon Sep 17 00:00:00 2001 From: "ana.alves" Date: Wed, 17 Dec 2025 12:21:22 -0300 Subject: [PATCH 05/25] ajusta logica do bloqueio de merge do codenarc para quebrar apenas em p1 no diff --- entrypoint.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/entrypoint.sh b/entrypoint.sh index 9af90dc..3bf2e81 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -43,6 +43,9 @@ generate_diff() { echo "⚠️ Refs base/head nao encontradas, usando HEAD~1..." git diff -U0 HEAD~1 > /tmp/diff.txt || true fi + + echo "📦 Conteudo completo do diff:" + cat /tmp/diff.txt } check_blocking_rules() { From d7f5d71c9398a214ce30576f550e5402b3e0e573 Mon Sep 17 00:00:00 2001 From: "ana.alves" Date: Wed, 17 Dec 2025 14:03:44 -0300 Subject: [PATCH 06/25] ajusta logica do bloqueio de merge do codenarc para quebrar apenas em p1 no diff --- entrypoint.sh | 60 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 20 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 3bf2e81..ad0bd56 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -43,49 +43,69 @@ generate_diff() { echo "⚠️ Refs base/head nao encontradas, usando HEAD~1..." git diff -U0 HEAD~1 > /tmp/diff.txt || true fi - - echo "📦 Conteudo completo do diff:" - cat /tmp/diff.txt } check_blocking_rules() { echo "🔎 Verificando violacoes bloqueantes (priority 1)..." p1_total=$(grep -Eo "p1=[0-9]+" result.txt | cut -d'=' -f2 | head -1) p1_total=${p1_total:-0} - echo "📊 Total de P1 encontradas pelo CodeNarc: ${p1_total}" [ "$p1_total" -eq 0 ] && echo "✅ Nenhuma violacao P1 detectada." && return 0 echo "🔍 Cruzando violacoes P1 com linhas alteradas..." found=0 + allowed_files="" + if [ -n "$INPUT_SOURCE_FILES" ]; then + allowed_files=$(echo "$INPUT_SOURCE_FILES" | tr ',' '\n' | sed 's/\*\*/.*/g') + echo "🧩 Filtrando apenas arquivos em INPUT_SOURCE_FILES:" + echo "$allowed_files" + fi + grep -E ':[0-9]+:' result.txt | while IFS=: read -r file line rest; do [ -z "$file" ] && continue - if grep -q "$file" /tmp/diff.txt; then - match=$(awk -v f="$file" -v l="$line" ' - BEGIN { in_file=0; hit=0 } - $0 ~ ("diff --git a/"f) { in_file=1 } - in_file && /^@@/ { - if (match($0, /\+([0-9]+)(,([0-9]+))?/, m)) { - start = m[1]; len = (m[3]=="" ? 1 : m[3]) - if (l >= start && l < start+len) { hit=1; exit } + + if [ -n "$allowed_files" ]; then + matched=0 + for pattern in $allowed_files; do + if echo "$file" | grep -Eq "$pattern"; then + matched=1 + break + fi + done + [ "$matched" -eq 0 ] && continue + fi + + file_escaped=$(printf '%s\n' "$file" | sed 's/[\/&]/\\&/g') + + match=$(awk -v f="$file_escaped" -v l="$line" ' + BEGIN { in_file=0; hit=0 } + $0 ~ ("diff --git a/" f) { in_file=1 } + in_file && /^@@/ { + if (match($0, /\+([0-9]+)(,([0-9]+))?/, m)) { + start = m[1] + len = (m[3]=="" ? 1 : m[3]) + if (l >= start && l < start+len) { + hit=1 + exit } } - END { if (hit==1) print "hit" } - ' /tmp/diff.txt) - if [ "$match" = "hit" ]; then - echo "🚨 Violacao P1 no diff: $file:$line" - found=1 - fi + } + END { if (hit==1) print "hit" } + ' /tmp/diff.txt) + + if [ "$match" = "hit" ]; then + echo "🚨 Violacao P1 no diff: $file:$line" + found=1 fi done if [ "$found" -eq 1 ]; then - echo "⛔ Foram encontradas violacoes P1 em linhas alteradas." + echo "⛔ Foram encontradas violacoes P1 em linhas alteradas (arquivos filtrados)." echo "💡 Corrija as violacoes ou utilize o bypass autorizado." exit 1 else - echo "⚠️ Existem violacoes P1 no arquivo, mas fora das linhas alteradas (nao bloqueia o merge)." + echo "⚠️ Existem violacoes P1 no arquivo, mas fora das linhas alteradas ou fora dos arquivos analisados (nao bloqueia o merge)." fi } From 5a4b61c4f0529760d05b1171223afa3ec2b7a1f9 Mon Sep 17 00:00:00 2001 From: "ana.alves" Date: Wed, 17 Dec 2025 14:14:56 -0300 Subject: [PATCH 07/25] ajusta logica do bloqueio de merge do codenarc para quebrar apenas em p1 no diff --- entrypoint.sh | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index ad0bd56..97476a4 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -47,8 +47,10 @@ generate_diff() { check_blocking_rules() { echo "🔎 Verificando violacoes bloqueantes (priority 1)..." + p1_total=$(grep -Eo "p1=[0-9]+" result.txt | cut -d'=' -f2 | head -1) p1_total=${p1_total:-0} + echo "📊 Total de P1 encontradas pelo CodeNarc: ${p1_total}" [ "$p1_total" -eq 0 ] && echo "✅ Nenhuma violacao P1 detectada." && return 0 @@ -76,23 +78,23 @@ check_blocking_rules() { [ "$matched" -eq 0 ] && continue fi - file_escaped=$(printf '%s\n' "$file" | sed 's/[\/&]/\\&/g') + if [ -n "$GITHUB_BASE_SHA" ] && [ -n "$GITHUB_HEAD_SHA" ]; then + git diff --no-color -U0 "$GITHUB_BASE_SHA" "$GITHUB_HEAD_SHA" -- "$file" > /tmp/file_diff.txt 2>/dev/null || true + else + git diff --no-color -U0 HEAD~1 -- "$file" > /tmp/file_diff.txt 2>/dev/null || true + fi - match=$(awk -v f="$file_escaped" -v l="$line" ' - BEGIN { in_file=0; hit=0 } - $0 ~ ("diff --git a/" f) { in_file=1 } - in_file && /^@@/ { + match=$(awk -v l="$line" ' + /^@@/ { if (match($0, /\+([0-9]+)(,([0-9]+))?/, m)) { start = m[1] len = (m[3]=="" ? 1 : m[3]) if (l >= start && l < start+len) { - hit=1 - exit + print "hit"; exit } } } - END { if (hit==1) print "hit" } - ' /tmp/diff.txt) + ' /tmp/file_diff.txt) if [ "$match" = "hit" ]; then echo "🚨 Violacao P1 no diff: $file:$line" @@ -105,7 +107,7 @@ check_blocking_rules() { echo "💡 Corrija as violacoes ou utilize o bypass autorizado." exit 1 else - echo "⚠️ Existem violacoes P1 no arquivo, mas fora das linhas alteradas ou fora dos arquivos analisados (nao bloqueia o merge)." + echo "⚠️ Existem violacoes P1, mas fora das linhas alteradas ou fora dos arquivos analisados (nao bloqueia o merge)." fi } From 1ce8e7eebba6689117710ffda06057f891f50a8f Mon Sep 17 00:00:00 2001 From: "ana.alves" Date: Wed, 17 Dec 2025 14:21:48 -0300 Subject: [PATCH 08/25] ajusta logica do bloqueio de merge do codenarc para quebrar apenas em p1 no diff --- entrypoint.sh | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 97476a4..2af4bcb 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -84,17 +84,26 @@ check_blocking_rules() { git diff --no-color -U0 HEAD~1 -- "$file" > /tmp/file_diff.txt 2>/dev/null || true fi - match=$(awk -v l="$line" ' - /^@@/ { - if (match($0, /\+([0-9]+)(,([0-9]+))?/, m)) { - start = m[1] - len = (m[3]=="" ? 1 : m[3]) - if (l >= start && l < start+len) { - print "hit"; exit - } - } - } - ' /tmp/file_diff.txt) + match="" + if grep -q "^@@" /tmp/file_diff.txt; then + while read -r diff_line; do + if echo "$diff_line" | grep -q "^@@"; then + range=$(echo "$diff_line" | sed 's/.*+\([0-9,]*\).*/\1/') + if echo "$range" | grep -q ","; then + start=$(echo "$range" | cut -d',' -f1) + count=$(echo "$range" | cut -d',' -f2) + else + start="$range" + count=1 + fi + + if [ "$line" -ge "$start" ] && [ "$line" -lt "$((start + count))" ]; then + match="hit" + break + fi + fi + done < /tmp/file_diff.txt + fi if [ "$match" = "hit" ]; then echo "🚨 Violacao P1 no diff: $file:$line" From 6e8a0a26a35f4560df4314252368d0ee89e1d468 Mon Sep 17 00:00:00 2001 From: "ana.alves" Date: Wed, 17 Dec 2025 14:26:21 -0300 Subject: [PATCH 09/25] ajusta logica do bloqueio de merge do codenarc para quebrar apenas em p1 no diff --- entrypoint.sh | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 2af4bcb..8002067 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,7 +1,6 @@ #!/bin/sh set -e - -trap 'rm -f result.txt reviewdog_output.txt /tmp/diff.txt >/dev/null 2>&1' EXIT +trap 'rm -f result.txt reviewdog_output.txt /tmp/diff.txt /tmp/file_diff.txt /tmp/found_violations.txt >/dev/null 2>&1' EXIT run_codenarc() { report="${INPUT_REPORT:-compact:stdout}" @@ -16,6 +15,10 @@ run_codenarc() { -basedir="." \ $includes_arg \ > result.txt + + echo "📋 Resultado do CodeNarc:" + cat result.txt + echo "📋 Fim do resultado CodeNarc" } run_reviewdog() { @@ -64,18 +67,25 @@ check_blocking_rules() { echo "$allowed_files" fi + echo "0" > /tmp/found_violations.txt + grep -E ':[0-9]+:' result.txt | while IFS=: read -r file line rest; do [ -z "$file" ] && continue + echo "🔍 Analisando violacao: $file:$line" if [ -n "$allowed_files" ]; then matched=0 for pattern in $allowed_files; do if echo "$file" | grep -Eq "$pattern"; then matched=1 + echo "✅ Arquivo $file corresponde ao padrão $pattern" break fi done - [ "$matched" -eq 0 ] && continue + if [ "$matched" -eq 0 ]; then + echo "⏭️ Arquivo $file não corresponde aos padrões permitidos" + continue + fi fi if [ -n "$GITHUB_BASE_SHA" ] && [ -n "$GITHUB_HEAD_SHA" ]; then @@ -84,11 +94,18 @@ check_blocking_rules() { git diff --no-color -U0 HEAD~1 -- "$file" > /tmp/file_diff.txt 2>/dev/null || true fi + echo "📄 Diff do arquivo $file:" + cat /tmp/file_diff.txt + echo "📄 Fim do diff" + match="" if grep -q "^@@" /tmp/file_diff.txt; then while read -r diff_line; do if echo "$diff_line" | grep -q "^@@"; then + echo "🔍 Processando linha de diff: $diff_line" range=$(echo "$diff_line" | sed 's/.*+\([0-9,]*\).*/\1/') + echo "📍 Range extraído: $range" + if echo "$range" | grep -q ","; then start=$(echo "$range" | cut -d',' -f1) count=$(echo "$range" | cut -d',' -f2) @@ -97,8 +114,10 @@ check_blocking_rules() { count=1 fi + echo "📊 Verificando se linha $line está entre $start e $((start + count - 1))" if [ "$line" -ge "$start" ] && [ "$line" -lt "$((start + count))" ]; then match="hit" + echo "🎯 MATCH! Linha $line está no range alterado" break fi fi @@ -107,10 +126,13 @@ check_blocking_rules() { if [ "$match" = "hit" ]; then echo "🚨 Violacao P1 no diff: $file:$line" - found=1 + echo "1" > /tmp/found_violations.txt fi done + + found=$(cat /tmp/found_violations.txt) + echo "🔍 Resultado final: found=$found" if [ "$found" -eq 1 ]; then echo "⛔ Foram encontradas violacoes P1 em linhas alteradas (arquivos filtrados)." echo "💡 Corrija as violacoes ou utilize o bypass autorizado." From 693b302594274c09d7326c5213b3406ab00af888 Mon Sep 17 00:00:00 2001 From: "ana.alves" Date: Wed, 17 Dec 2025 14:35:42 -0300 Subject: [PATCH 10/25] ajusta logica do bloqueio de merge do codenarc para quebrar apenas em p1 no diff --- entrypoint.sh | 191 +++++++++++++++++++++++++------------------------- 1 file changed, 95 insertions(+), 96 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 8002067..6784363 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,144 +1,144 @@ #!/bin/sh set -e -trap 'rm -f result.txt reviewdog_output.txt /tmp/diff.txt /tmp/file_diff.txt /tmp/found_violations.txt >/dev/null 2>&1' EXIT +trap 'cleanup_temp_files' EXIT + +CODENARC_RESULT="result.txt" +VIOLATIONS_FLAG="/tmp/found_violations.txt" +FILE_DIFF="/tmp/file_diff.txt" + +cleanup_temp_files() { + rm -f "$CODENARC_RESULT" "$VIOLATIONS_FLAG" "$FILE_DIFF" >/dev/null 2>&1 +} run_codenarc() { report="${INPUT_REPORT:-compact:stdout}" includes_arg="" + if [ -n "$INPUT_SOURCE_FILES" ]; then includes_arg="-includes=${INPUT_SOURCE_FILES}" fi + echo "🔍 Executando CodeNarc..." java -jar /lib/codenarc-all.jar \ -report="$report" \ -rulesetfiles="${INPUT_RULESETFILES}" \ -basedir="." \ $includes_arg \ - > result.txt - - echo "📋 Resultado do CodeNarc:" - cat result.txt - echo "📋 Fim do resultado CodeNarc" + > "$CODENARC_RESULT" } run_reviewdog() { echo "📤 Enviando resultados para reviewdog..." - < result.txt reviewdog \ + < "$CODENARC_RESULT" reviewdog \ -efm="%f:%l:%m" -efm="%f:%r:%m" \ -name="codenarc" \ -reporter="${INPUT_REPORTER:-github-pr-check}" \ -filter-mode="${INPUT_FILTER_MODE}" \ -fail-on-error="${INPUT_FAIL_ON_ERROR}" \ -level="${INPUT_LEVEL}" \ - ${INPUT_REVIEWDOG_FLAGS} \ - -tee > reviewdog_output.txt + ${INPUT_REVIEWDOG_FLAGS} } -generate_diff() { - echo "🔎 Gerando diff entre commits..." +generate_git_diff() { if [ -n "$GITHUB_BASE_SHA" ] && [ -n "$GITHUB_HEAD_SHA" ]; then - echo " Base: $GITHUB_BASE_SHA" - echo " Head: $GITHUB_HEAD_SHA" - git fetch origin $GITHUB_BASE_SHA --depth=1 2>/dev/null || true - git fetch origin $GITHUB_HEAD_SHA --depth=1 2>/dev/null || true - git diff -U0 "$GITHUB_BASE_SHA" "$GITHUB_HEAD_SHA" > /tmp/diff.txt || true + git fetch origin "$GITHUB_BASE_SHA" --depth=1 2>/dev/null || true + git fetch origin "$GITHUB_HEAD_SHA" --depth=1 2>/dev/null || true + git diff -U0 "$GITHUB_BASE_SHA" "$GITHUB_HEAD_SHA" -- "$1" 2>/dev/null || true else - echo "⚠️ Refs base/head nao encontradas, usando HEAD~1..." - git diff -U0 HEAD~1 > /tmp/diff.txt || true + git diff -U0 HEAD~1 -- "$1" 2>/dev/null || true fi } -check_blocking_rules() { - echo "🔎 Verificando violacoes bloqueantes (priority 1)..." - - p1_total=$(grep -Eo "p1=[0-9]+" result.txt | cut -d'=' -f2 | head -1) - p1_total=${p1_total:-0} +get_p1_violations_count() { + grep -Eo "p1=[0-9]+" "$CODENARC_RESULT" | cut -d'=' -f2 | head -1 | grep -o '[0-9]*' || echo "0" +} - echo "📊 Total de P1 encontradas pelo CodeNarc: ${p1_total}" - [ "$p1_total" -eq 0 ] && echo "✅ Nenhuma violacao P1 detectada." && return 0 +parse_allowed_file_patterns() { + [ -n "$INPUT_SOURCE_FILES" ] && echo "$INPUT_SOURCE_FILES" | tr ',' '\n' | sed 's/\*\*/.*/g' +} - echo "🔍 Cruzando violacoes P1 com linhas alteradas..." - found=0 +file_matches_patterns() { + file="$1" + patterns="$2" + + [ -z "$patterns" ] && return 0 + + echo "$patterns" | while read -r pattern; do + if echo "$file" | grep -Eq "$pattern"; then + return 0 + fi + done + return 1 +} - allowed_files="" - if [ -n "$INPUT_SOURCE_FILES" ]; then - allowed_files=$(echo "$INPUT_SOURCE_FILES" | tr ',' '\n' | sed 's/\*\*/.*/g') - echo "🧩 Filtrando apenas arquivos em INPUT_SOURCE_FILES:" - echo "$allowed_files" +parse_diff_range() { + range=$(echo "$1" | sed 's/.*+\([0-9,]*\).*/\1/') + + if echo "$range" | grep -q ","; then + echo "$(echo "$range" | cut -d',' -f1) $(echo "$range" | cut -d',' -f2)" + else + echo "$range 1" fi +} - echo "0" > /tmp/found_violations.txt +line_is_in_changed_range() { + target_line="$1" + file="$2" - grep -E ':[0-9]+:' result.txt | while IFS=: read -r file line rest; do - [ -z "$file" ] && continue - echo "🔍 Analisando violacao: $file:$line" - - if [ -n "$allowed_files" ]; then - matched=0 - for pattern in $allowed_files; do - if echo "$file" | grep -Eq "$pattern"; then - matched=1 - echo "✅ Arquivo $file corresponde ao padrão $pattern" - break - fi - done - if [ "$matched" -eq 0 ]; then - echo "⏭️ Arquivo $file não corresponde aos padrões permitidos" - continue + generate_git_diff "$file" > "$FILE_DIFF" + + while read -r diff_line; do + if echo "$diff_line" | grep -q "^@@"; then + range_info=$(parse_diff_range "$diff_line") + start=$(echo "$range_info" | cut -d' ' -f1) + count=$(echo "$range_info" | cut -d' ' -f2) + + if [ "$target_line" -ge "$start" ] && [ "$target_line" -lt "$((start + count))" ]; then + return 0 fi fi + done < "$FILE_DIFF" + + return 1 +} - if [ -n "$GITHUB_BASE_SHA" ] && [ -n "$GITHUB_HEAD_SHA" ]; then - git diff --no-color -U0 "$GITHUB_BASE_SHA" "$GITHUB_HEAD_SHA" -- "$file" > /tmp/file_diff.txt 2>/dev/null || true - else - git diff --no-color -U0 HEAD~1 -- "$file" > /tmp/file_diff.txt 2>/dev/null || true - fi - - echo "📄 Diff do arquivo $file:" - cat /tmp/file_diff.txt - echo "📄 Fim do diff" - - match="" - if grep -q "^@@" /tmp/file_diff.txt; then - while read -r diff_line; do - if echo "$diff_line" | grep -q "^@@"; then - echo "🔍 Processando linha de diff: $diff_line" - range=$(echo "$diff_line" | sed 's/.*+\([0-9,]*\).*/\1/') - echo "📍 Range extraído: $range" - - if echo "$range" | grep -q ","; then - start=$(echo "$range" | cut -d',' -f1) - count=$(echo "$range" | cut -d',' -f2) - else - start="$range" - count=1 - fi - - echo "📊 Verificando se linha $line está entre $start e $((start + count - 1))" - if [ "$line" -ge "$start" ] && [ "$line" -lt "$((start + count))" ]; then - match="hit" - echo "🎯 MATCH! Linha $line está no range alterado" - break - fi - fi - done < /tmp/file_diff.txt +check_blocking_rules() { + + echo "🔎 Verificando violacoes bloqueantes (priority 1)..." + + p1_count=$(get_p1_violations_count) + echo "📊 Total de P1 encontradas: $p1_count" + + [ "$p1_count" -eq 0 ] && echo "✅ Nenhuma violacao P1 detectada." && return 0 + + allowed_patterns=$(parse_allowed_file_patterns) + if [ -n "$allowed_patterns" ]; then + echo "🧩 Analisando apenas arquivos filtrados por INPUT_SOURCE_FILES" + fi + + echo "0" > "$VIOLATIONS_FLAG" + + grep -E ':[0-9]+:' "$CODENARC_RESULT" | while IFS=: read -r file line rest; do + [ -z "$file" ] && continue + + if ! file_matches_patterns "$file" "$allowed_patterns"; then + continue fi - - if [ "$match" = "hit" ]; then - echo "🚨 Violacao P1 no diff: $file:$line" - echo "1" > /tmp/found_violations.txt + + if line_is_in_changed_range "$line" "$file"; then + echo "🚨 Violacao P1 em linha alterada: $file:$line" + echo "1" > "$VIOLATIONS_FLAG" fi done - found=$(cat /tmp/found_violations.txt) - - echo "🔍 Resultado final: found=$found" - if [ "$found" -eq 1 ]; then - echo "⛔ Foram encontradas violacoes P1 em linhas alteradas (arquivos filtrados)." - echo "💡 Corrija as violacoes ou utilize o bypass autorizado." + violations_in_diff=$(cat "$VIOLATIONS_FLAG") + + if [ "$violations_in_diff" -eq 1 ]; then + echo "⛔ Violacoes P1 encontradas em linhas alteradas - bloqueando merge" + echo "💡 Corrija as violacoes ou utilize bypass autorizado" exit 1 else - echo "⚠️ Existem violacoes P1, mas fora das linhas alteradas ou fora dos arquivos analisados (nao bloqueia o merge)." + echo "⚠️ Violacoes P1 existem mas fora das linhas alteradas - merge permitido" fi } @@ -151,7 +151,6 @@ export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}" run_codenarc run_reviewdog -generate_diff check_blocking_rules -echo "🏁 Finalizado com sucesso." +echo "🏁 Concluido com sucesso" From e935b6ca39b820f71b1006853a180c6e19408183 Mon Sep 17 00:00:00 2001 From: "ana.alves" Date: Wed, 17 Dec 2025 14:39:14 -0300 Subject: [PATCH 11/25] ajusta logica do bloqueio de merge do codenarc para quebrar apenas em p1 no diff --- entrypoint.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/entrypoint.sh b/entrypoint.sh index 6784363..7101204 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -85,20 +85,27 @@ line_is_in_changed_range() { target_line="$1" file="$2" + echo "🔍 DEBUG: Verificando se linha $target_line do arquivo $file esta alterada" generate_git_diff "$file" > "$FILE_DIFF" + echo "🔍 DEBUG: Diff gerado:" + cat "$FILE_DIFF" while read -r diff_line; do if echo "$diff_line" | grep -q "^@@"; then + echo "🔍 DEBUG: Processando linha diff: $diff_line" range_info=$(parse_diff_range "$diff_line") start=$(echo "$range_info" | cut -d' ' -f1) count=$(echo "$range_info" | cut -d' ' -f2) + echo "🔍 DEBUG: Range: start=$start count=$count, verificando linha $target_line" if [ "$target_line" -ge "$start" ] && [ "$target_line" -lt "$((start + count))" ]; then + echo "🔍 DEBUG: MATCH! Linha $target_line esta no range $start-$((start + count - 1))" return 0 fi fi done < "$FILE_DIFF" + echo "🔍 DEBUG: Linha $target_line NAO esta em nenhum range alterado" return 1 } @@ -120,14 +127,19 @@ check_blocking_rules() { grep -E ':[0-9]+:' "$CODENARC_RESULT" | while IFS=: read -r file line rest; do [ -z "$file" ] && continue + echo "🔍 DEBUG: Analisando violacao $file:$line" if ! file_matches_patterns "$file" "$allowed_patterns"; then + echo "🔍 DEBUG: Arquivo $file nao corresponde aos padroes" continue fi + echo "🔍 DEBUG: Arquivo $file corresponde aos padroes" if line_is_in_changed_range "$line" "$file"; then echo "🚨 Violacao P1 em linha alterada: $file:$line" echo "1" > "$VIOLATIONS_FLAG" + else + echo "🔍 DEBUG: Linha $line nao esta no range alterado" fi done From c52e66b59e60fb6b124de2e1f32dd871ac90aaf0 Mon Sep 17 00:00:00 2001 From: "ana.alves" Date: Wed, 17 Dec 2025 14:41:53 -0300 Subject: [PATCH 12/25] ajusta logica do bloqueio de merge do codenarc para quebrar apenas em p1 no diff --- entrypoint.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 7101204..865e9f0 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -25,6 +25,10 @@ run_codenarc() { -basedir="." \ $includes_arg \ > "$CODENARC_RESULT" + + echo "🔍 DEBUG: Resultado completo do CodeNarc:" + cat "$CODENARC_RESULT" + echo "🔍 DEBUG: Fim do resultado CodeNarc" } run_reviewdog() { @@ -61,13 +65,19 @@ file_matches_patterns() { file="$1" patterns="$2" - [ -z "$patterns" ] && return 0 + echo "🔍 DEBUG: Verificando arquivo '$file' contra padrões '$patterns'" + + [ -z "$patterns" ] && echo "🔍 DEBUG: Sem padrões, permitindo arquivo" && return 0 - echo "$patterns" | while read -r pattern; do + for pattern in $patterns; do + echo "🔍 DEBUG: Testando padrão '$pattern'" if echo "$file" | grep -Eq "$pattern"; then + echo "🔍 DEBUG: MATCH com padrão '$pattern'" return 0 fi done + + echo "🔍 DEBUG: Nenhum padrão corresponde" return 1 } From dceefdefdefc311b7118b00fe029dd23d2167918 Mon Sep 17 00:00:00 2001 From: "ana.alves" Date: Wed, 17 Dec 2025 14:44:27 -0300 Subject: [PATCH 13/25] removendo logs de debug --- entrypoint.sh | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 865e9f0..a4ed221 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -25,10 +25,6 @@ run_codenarc() { -basedir="." \ $includes_arg \ > "$CODENARC_RESULT" - - echo "🔍 DEBUG: Resultado completo do CodeNarc:" - cat "$CODENARC_RESULT" - echo "🔍 DEBUG: Fim do resultado CodeNarc" } run_reviewdog() { @@ -65,19 +61,14 @@ file_matches_patterns() { file="$1" patterns="$2" - echo "🔍 DEBUG: Verificando arquivo '$file' contra padrões '$patterns'" - - [ -z "$patterns" ] && echo "🔍 DEBUG: Sem padrões, permitindo arquivo" && return 0 + [ -z "$patterns" ] && return 0 for pattern in $patterns; do - echo "🔍 DEBUG: Testando padrão '$pattern'" if echo "$file" | grep -Eq "$pattern"; then - echo "🔍 DEBUG: MATCH com padrão '$pattern'" return 0 fi done - echo "🔍 DEBUG: Nenhum padrão corresponde" return 1 } @@ -95,27 +86,20 @@ line_is_in_changed_range() { target_line="$1" file="$2" - echo "🔍 DEBUG: Verificando se linha $target_line do arquivo $file esta alterada" generate_git_diff "$file" > "$FILE_DIFF" - echo "🔍 DEBUG: Diff gerado:" - cat "$FILE_DIFF" while read -r diff_line; do if echo "$diff_line" | grep -q "^@@"; then - echo "🔍 DEBUG: Processando linha diff: $diff_line" range_info=$(parse_diff_range "$diff_line") start=$(echo "$range_info" | cut -d' ' -f1) count=$(echo "$range_info" | cut -d' ' -f2) - echo "🔍 DEBUG: Range: start=$start count=$count, verificando linha $target_line" if [ "$target_line" -ge "$start" ] && [ "$target_line" -lt "$((start + count))" ]; then - echo "🔍 DEBUG: MATCH! Linha $target_line esta no range $start-$((start + count - 1))" return 0 fi fi done < "$FILE_DIFF" - echo "🔍 DEBUG: Linha $target_line NAO esta em nenhum range alterado" return 1 } @@ -137,19 +121,14 @@ check_blocking_rules() { grep -E ':[0-9]+:' "$CODENARC_RESULT" | while IFS=: read -r file line rest; do [ -z "$file" ] && continue - echo "🔍 DEBUG: Analisando violacao $file:$line" if ! file_matches_patterns "$file" "$allowed_patterns"; then - echo "🔍 DEBUG: Arquivo $file nao corresponde aos padroes" continue fi - echo "🔍 DEBUG: Arquivo $file corresponde aos padroes" if line_is_in_changed_range "$line" "$file"; then echo "🚨 Violacao P1 em linha alterada: $file:$line" echo "1" > "$VIOLATIONS_FLAG" - else - echo "🔍 DEBUG: Linha $line nao esta no range alterado" fi done From 9d388c4b951fb36c3e735b0e720d99841a3a07d8 Mon Sep 17 00:00:00 2001 From: "ana.alves" Date: Wed, 17 Dec 2025 14:56:53 -0300 Subject: [PATCH 14/25] ajusta logica do bloqueio de merge do codenarc para quebrar apenas em p1 no diff --- entrypoint.sh | 62 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 21 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index a4ed221..f1b70c4 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -4,10 +4,11 @@ trap 'cleanup_temp_files' EXIT CODENARC_RESULT="result.txt" VIOLATIONS_FLAG="/tmp/found_violations.txt" -FILE_DIFF="/tmp/file_diff.txt" +ALL_DIFF="/tmp/all_diff.txt" +CHANGED_LINES_CACHE="/tmp/changed_lines.txt" cleanup_temp_files() { - rm -f "$CODENARC_RESULT" "$VIOLATIONS_FLAG" "$FILE_DIFF" >/dev/null 2>&1 + rm -f "$CODENARC_RESULT" "$VIOLATIONS_FLAG" "$ALL_DIFF" "$CHANGED_LINES_CACHE" >/dev/null 2>&1 } run_codenarc() { @@ -39,16 +40,44 @@ run_reviewdog() { ${INPUT_REVIEWDOG_FLAGS} } -generate_git_diff() { +generate_all_diff() { if [ -n "$GITHUB_BASE_SHA" ] && [ -n "$GITHUB_HEAD_SHA" ]; then git fetch origin "$GITHUB_BASE_SHA" --depth=1 2>/dev/null || true git fetch origin "$GITHUB_HEAD_SHA" --depth=1 2>/dev/null || true - git diff -U0 "$GITHUB_BASE_SHA" "$GITHUB_HEAD_SHA" -- "$1" 2>/dev/null || true + git diff -U0 "$GITHUB_BASE_SHA" "$GITHUB_HEAD_SHA" -- '*.groovy' > "$ALL_DIFF" 2>/dev/null || true else - git diff -U0 HEAD~1 -- "$1" 2>/dev/null || true + git diff -U0 HEAD~1 -- '*.groovy' > "$ALL_DIFF" 2>/dev/null || true fi } +build_changed_lines_cache() { + > "$CHANGED_LINES_CACHE" + current_file="" + + while read -r line; do + if echo "$line" | grep -q "^diff --git"; then + current_file=$(echo "$line" | sed 's|^diff --git a/\(.*\) b/.*|\1|') + elif echo "$line" | grep -q "^@@"; then + if [ -n "$current_file" ]; then + range=$(echo "$line" | sed 's/.*+\([0-9,]*\).*/\1/') + if echo "$range" | grep -q ","; then + start=$(echo "$range" | cut -d',' -f1) + count=$(echo "$range" | cut -d',' -f2) + else + start="$range" + count=1 + fi + + i="$start" + while [ "$i" -lt "$((start + count))" ]; do + echo "$current_file:$i" >> "$CHANGED_LINES_CACHE" + i=$((i + 1)) + done + fi + fi + done < "$ALL_DIFF" +} + get_p1_violations_count() { grep -Eo "p1=[0-9]+" "$CODENARC_RESULT" | cut -d'=' -f2 | head -1 | grep -o '[0-9]*' || echo "0" } @@ -86,25 +115,10 @@ line_is_in_changed_range() { target_line="$1" file="$2" - generate_git_diff "$file" > "$FILE_DIFF" - - while read -r diff_line; do - if echo "$diff_line" | grep -q "^@@"; then - range_info=$(parse_diff_range "$diff_line") - start=$(echo "$range_info" | cut -d' ' -f1) - count=$(echo "$range_info" | cut -d' ' -f2) - - if [ "$target_line" -ge "$start" ] && [ "$target_line" -lt "$((start + count))" ]; then - return 0 - fi - fi - done < "$FILE_DIFF" - - return 1 + grep -q "^$file:$target_line$" "$CHANGED_LINES_CACHE" } check_blocking_rules() { - echo "🔎 Verificando violacoes bloqueantes (priority 1)..." p1_count=$(get_p1_violations_count) @@ -112,6 +126,10 @@ check_blocking_rules() { [ "$p1_count" -eq 0 ] && echo "✅ Nenhuma violacao P1 detectada." && return 0 + echo "🔎 Gerando cache de linhas alteradas..." + generate_all_diff + build_changed_lines_cache + allowed_patterns=$(parse_allowed_file_patterns) if [ -n "$allowed_patterns" ]; then echo "🧩 Analisando apenas arquivos filtrados por INPUT_SOURCE_FILES" @@ -122,6 +140,8 @@ check_blocking_rules() { grep -E ':[0-9]+:' "$CODENARC_RESULT" | while IFS=: read -r file line rest; do [ -z "$file" ] && continue + echo "$file" | grep -q '\.groovy$' || continue + if ! file_matches_patterns "$file" "$allowed_patterns"; then continue fi From 08d0ec9506d8abf3dd39f04d6c66d64a804a258b Mon Sep 17 00:00:00 2001 From: "ana.alves" Date: Wed, 17 Dec 2025 15:53:26 -0300 Subject: [PATCH 15/25] exit 1 temporiamente desabilitado --- entrypoint.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index f1b70c4..1067b5b 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -155,9 +155,12 @@ check_blocking_rules() { violations_in_diff=$(cat "$VIOLATIONS_FLAG") if [ "$violations_in_diff" -eq 1 ]; then - echo "⛔ Violacoes P1 encontradas em linhas alteradas - bloqueando merge" - echo "💡 Corrija as violacoes ou utilize bypass autorizado" - exit 1 + # echo "⛔ Violacoes P1 encontradas em linhas alteradas - bloqueando merge" + # echo "💡 Corrija as violacoes ou utilize bypass autorizado" + # exit 1 + + echo "⛔ Violacoes P1 encontradas em linhas alteradas - DEVERIA bloquear merge" + echo "🔧 Exit desabilitado temporariamente para monitoramento" else echo "⚠️ Violacoes P1 existem mas fora das linhas alteradas - merge permitido" fi From 6deceeaebeb408a286b349cb094dd429f2382222 Mon Sep 17 00:00:00 2001 From: "ana.alves" Date: Wed, 17 Dec 2025 15:58:56 -0300 Subject: [PATCH 16/25] ajuste do shellcheck --- entrypoint.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 1067b5b..85f72db 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -51,7 +51,7 @@ generate_all_diff() { } build_changed_lines_cache() { - > "$CHANGED_LINES_CACHE" + true > "$CHANGED_LINES_CACHE" current_file="" while read -r line; do @@ -79,7 +79,8 @@ build_changed_lines_cache() { } get_p1_violations_count() { - grep -Eo "p1=[0-9]+" "$CODENARC_RESULT" | cut -d'=' -f2 | head -1 | grep -o '[0-9]*' || echo "0" + p1_count=$(grep -Eo "p1=[0-9]+" "$CODENARC_RESULT" | cut -d'=' -f2 | head -1) + echo "${p1_count:-0}" } parse_allowed_file_patterns() { From 4d36d7ccb79337b5c6715aa94d10ace6390f1912 Mon Sep 17 00:00:00 2001 From: "ana.alves" Date: Thu, 18 Dec 2025 17:54:58 -0300 Subject: [PATCH 17/25] melhorias --- entrypoint.sh | 71 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 27 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 85f72db..d259d07 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -6,9 +6,11 @@ CODENARC_RESULT="result.txt" VIOLATIONS_FLAG="/tmp/found_violations.txt" ALL_DIFF="/tmp/all_diff.txt" CHANGED_LINES_CACHE="/tmp/changed_lines.txt" +CHANGED_FILES_CACHE="/tmp/changed_files.txt" +TEMP_VIOLATIONS="/tmp/temp_violations.txt" cleanup_temp_files() { - rm -f "$CODENARC_RESULT" "$VIOLATIONS_FLAG" "$ALL_DIFF" "$CHANGED_LINES_CACHE" >/dev/null 2>&1 + rm -f "$CODENARC_RESULT" "$VIOLATIONS_FLAG" "$ALL_DIFF" "$CHANGED_LINES_CACHE" "$CHANGED_FILES_CACHE" "$TEMP_VIOLATIONS" >/dev/null 2>&1 } run_codenarc() { @@ -52,11 +54,17 @@ generate_all_diff() { build_changed_lines_cache() { true > "$CHANGED_LINES_CACHE" + true > "$CHANGED_FILES_CACHE" current_file="" + [ ! -s "$ALL_DIFF" ] && return 0 + while read -r line; do if echo "$line" | grep -q "^diff --git"; then current_file=$(echo "$line" | sed 's|^diff --git a/\(.*\) b/.*|\1|') + if [ -n "$current_file" ]; then + echo "$current_file" >> "$CHANGED_FILES_CACHE" + fi elif echo "$line" | grep -q "^@@"; then if [ -n "$current_file" ]; then range=$(echo "$line" | sed 's/.*+\([0-9,]*\).*/\1/') @@ -67,6 +75,9 @@ build_changed_lines_cache() { start="$range" count=1 fi + + case "$start" in ''|*[!0-9]*) continue ;; esac + case "$count" in ''|*[!0-9]*) continue ;; esac i="$start" while [ "$i" -lt "$((start + count))" ]; do @@ -102,16 +113,6 @@ file_matches_patterns() { return 1 } -parse_diff_range() { - range=$(echo "$1" | sed 's/.*+\([0-9,]*\).*/\1/') - - if echo "$range" | grep -q ","; then - echo "$(echo "$range" | cut -d',' -f1) $(echo "$range" | cut -d',' -f2)" - else - echo "$range 1" - fi -} - line_is_in_changed_range() { target_line="$1" file="$2" @@ -119,15 +120,25 @@ line_is_in_changed_range() { grep -q "^$file:$target_line$" "$CHANGED_LINES_CACHE" } +file_was_changed() { + file="$1" + grep -q "^$file$" "$CHANGED_FILES_CACHE" +} + check_blocking_rules() { - echo "🔎 Verificando violacoes bloqueantes (priority 1)..." + echo "🔎 Verificando violações bloqueantes (priority 1)..." + + [ ! -f "$CODENARC_RESULT" ] && echo "❌ Arquivo de resultado não encontrado" && return 1 p1_count=$(get_p1_violations_count) echo "📊 Total de P1 encontradas: $p1_count" - [ "$p1_count" -eq 0 ] && echo "✅ Nenhuma violacao P1 detectada." && return 0 + if [ "$p1_count" -eq 0 ]; then + echo "✅ Nenhuma P1 detectada → merge permitido (análise de diff desnecessária)" + return 0 + fi - echo "🔎 Gerando cache de linhas alteradas..." + echo "⚠️ P1s detectadas → verificando se estão em linhas alteradas..." generate_all_diff build_changed_lines_cache @@ -138,32 +149,38 @@ check_blocking_rules() { echo "0" > "$VIOLATIONS_FLAG" - grep -E ':[0-9]+:' "$CODENARC_RESULT" | while IFS=: read -r file line rest; do + grep -E ':[0-9]+:|:[0-9]*:' "$CODENARC_RESULT" > "$TEMP_VIOLATIONS" + + [ ! -s "$TEMP_VIOLATIONS" ] && echo "✅ Nenhuma violação encontrada no resultado" && return 0 + + while IFS=: read -r file line rest; do [ -z "$file" ] && continue - echo "$file" | grep -q '\.groovy$' || continue - if ! file_matches_patterns "$file" "$allowed_patterns"; then continue fi - if line_is_in_changed_range "$line" "$file"; then - echo "🚨 Violacao P1 em linha alterada: $file:$line" + if [ -z "$line" ]; then + if file_was_changed "$file"; then + echo "📍 Violação file-based em arquivo alterado: $file" + echo "1" > "$VIOLATIONS_FLAG" + break + fi + elif line_is_in_changed_range "$line" "$file"; then + echo "📍 Violação em linha alterada: $file:$line" echo "1" > "$VIOLATIONS_FLAG" + break fi - done + done < "$TEMP_VIOLATIONS" violations_in_diff=$(cat "$VIOLATIONS_FLAG") if [ "$violations_in_diff" -eq 1 ]; then - # echo "⛔ Violacoes P1 encontradas em linhas alteradas - bloqueando merge" - # echo "💡 Corrija as violacoes ou utilize bypass autorizado" - # exit 1 - - echo "⛔ Violacoes P1 encontradas em linhas alteradas - DEVERIA bloquear merge" + echo "⛔ P1s existem E há violações em linhas alteradas → DEVERIA bloquear merge" echo "🔧 Exit desabilitado temporariamente para monitoramento" + # exit 1 else - echo "⚠️ Violacoes P1 existem mas fora das linhas alteradas - merge permitido" + echo "✅ P1s existem mas FORA das linhas alteradas → merge permitido" fi } @@ -178,4 +195,4 @@ run_codenarc run_reviewdog check_blocking_rules -echo "🏁 Concluido com sucesso" +echo "🏁 Concluído com sucesso" From 0bc41451e7e85d54622003cf15d3dc4c6d225be4 Mon Sep 17 00:00:00 2001 From: "ana.alves" Date: Fri, 19 Dec 2025 11:27:35 -0300 Subject: [PATCH 18/25] validacao --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index d259d07..9b37f70 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -160,7 +160,7 @@ check_blocking_rules() { continue fi - if [ -z "$line" ]; then + if [ -z "$line" ] || [ "$line" = "null" ]; then if file_was_changed "$file"; then echo "📍 Violação file-based em arquivo alterado: $file" echo "1" > "$VIOLATIONS_FLAG" From 645a9a16a1fbe2fa284bfdf889a6ebfef540990e Mon Sep 17 00:00:00 2001 From: "ana.alves" Date: Fri, 19 Dec 2025 13:50:26 -0300 Subject: [PATCH 19/25] testando abordagem hibrida reviewdog --- entrypoint.sh | 190 ++++++++++++++++++++++++++++---------------------- 1 file changed, 108 insertions(+), 82 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 9b37f70..8766223 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,25 +1,27 @@ #!/bin/sh set -e -trap 'cleanup_temp_files' EXIT +# Constants CODENARC_RESULT="result.txt" +LINE_VIOLATIONS="line_violations.txt" +FILE_VIOLATIONS="file_violations.txt" VIOLATIONS_FLAG="/tmp/found_violations.txt" ALL_DIFF="/tmp/all_diff.txt" CHANGED_LINES_CACHE="/tmp/changed_lines.txt" CHANGED_FILES_CACHE="/tmp/changed_files.txt" -TEMP_VIOLATIONS="/tmp/temp_violations.txt" cleanup_temp_files() { - rm -f "$CODENARC_RESULT" "$VIOLATIONS_FLAG" "$ALL_DIFF" "$CHANGED_LINES_CACHE" "$CHANGED_FILES_CACHE" "$TEMP_VIOLATIONS" >/dev/null 2>&1 + rm -f "$CODENARC_RESULT" "$LINE_VIOLATIONS" "$FILE_VIOLATIONS" "$VIOLATIONS_FLAG" \ + "$ALL_DIFF" "$CHANGED_LINES_CACHE" "$CHANGED_FILES_CACHE" >/dev/null 2>&1 } +trap 'cleanup_temp_files' EXIT + run_codenarc() { report="${INPUT_REPORT:-compact:stdout}" includes_arg="" - if [ -n "$INPUT_SOURCE_FILES" ]; then - includes_arg="-includes=${INPUT_SOURCE_FILES}" - fi + [ -n "$INPUT_SOURCE_FILES" ] && includes_arg="-includes=${INPUT_SOURCE_FILES}" echo "🔍 Executando CodeNarc..." java -jar /lib/codenarc-all.jar \ @@ -30,52 +32,98 @@ run_codenarc() { > "$CODENARC_RESULT" } +run_reviewdog_with_config() { + input_file="$1" + efm="$2" + reporter="$3" + name="$4" + filter_mode="$5" + level="$6" + + < "$input_file" reviewdog \ + -efm="$efm" \ + -reporter="$reporter" \ + -name="$name" \ + -filter-mode="$filter_mode" \ + -fail-on-error="false" \ + -level="$level" \ + ${INPUT_REVIEWDOG_FLAGS} || true +} + +separate_violations() { + grep -E ':[0-9]+:' "$CODENARC_RESULT" > "$LINE_VIOLATIONS" || true + grep -E ':null:|::' "$CODENARC_RESULT" > "$FILE_VIOLATIONS" || true +} + run_reviewdog() { echo "📤 Enviando resultados para reviewdog..." - < "$CODENARC_RESULT" reviewdog \ - -efm="%f:%l:%m" -efm="%f:%r:%m" \ - -name="codenarc" \ - -reporter="${INPUT_REPORTER:-github-pr-check}" \ - -filter-mode="${INPUT_FILTER_MODE}" \ - -fail-on-error="${INPUT_FAIL_ON_ERROR}" \ - -level="${INPUT_LEVEL}" \ - ${INPUT_REVIEWDOG_FLAGS} + + separate_violations + + # Violações line-based com reporter configurado + if [ -s "$LINE_VIOLATIONS" ]; then + echo "📤 Enviando violações com linha (${INPUT_REPORTER:-github-pr-check})..." + run_reviewdog_with_config "$LINE_VIOLATIONS" "%f:%l:%m" \ + "${INPUT_REPORTER:-github-pr-check}" "codenarc-lines" \ + "${INPUT_FILTER_MODE}" "${INPUT_LEVEL}" + fi + + # Violações file-based forçando github-pr-check + if [ -s "$FILE_VIOLATIONS" ]; then + echo "📤 Enviando violações file-based (github-pr-check)..." + run_reviewdog_with_config "$FILE_VIOLATIONS" "%f::%m" \ + "github-pr-check" "codenarc-files" "nofilter" "warning" + fi + + # Fallback se não houver violações categorizadas + if [ ! -s "$LINE_VIOLATIONS" ] && [ ! -s "$FILE_VIOLATIONS" ]; then + echo "📝 Executando reviewdog padrão..." + run_reviewdog_with_config "$CODENARC_RESULT" "%f:%l:%m" \ + "${INPUT_REPORTER:-github-pr-check}" "codenarc" \ + "${INPUT_FILTER_MODE}" "${INPUT_LEVEL}" + fi } -generate_all_diff() { +generate_git_diff() { if [ -n "$GITHUB_BASE_SHA" ] && [ -n "$GITHUB_HEAD_SHA" ]; then git fetch origin "$GITHUB_BASE_SHA" --depth=1 2>/dev/null || true git fetch origin "$GITHUB_HEAD_SHA" --depth=1 2>/dev/null || true - git diff -U0 "$GITHUB_BASE_SHA" "$GITHUB_HEAD_SHA" -- '*.groovy' > "$ALL_DIFF" 2>/dev/null || true + git diff -U0 "$GITHUB_BASE_SHA" "$GITHUB_HEAD_SHA" -- '*.groovy' + else + git diff -U0 HEAD~1 -- '*.groovy' + fi +} + +parse_diff_range() { + range="$1" + if echo "$range" | grep -q ","; then + echo "$(echo "$range" | cut -d',' -f1) $(echo "$range" | cut -d',' -f2)" else - git diff -U0 HEAD~1 -- '*.groovy' > "$ALL_DIFF" 2>/dev/null || true + echo "$range 1" fi } build_changed_lines_cache() { true > "$CHANGED_LINES_CACHE" true > "$CHANGED_FILES_CACHE" - current_file="" + generate_git_diff > "$ALL_DIFF" 2>/dev/null || true [ ! -s "$ALL_DIFF" ] && return 0 + current_file="" while read -r line; do - if echo "$line" | grep -q "^diff --git"; then - current_file=$(echo "$line" | sed 's|^diff --git a/\(.*\) b/.*|\1|') - if [ -n "$current_file" ]; then - echo "$current_file" >> "$CHANGED_FILES_CACHE" - fi - elif echo "$line" | grep -q "^@@"; then - if [ -n "$current_file" ]; then + case "$line" in + "diff --git"*) + current_file=$(echo "$line" | sed 's|^diff --git a/\(.*\) b/.*|\1|') + [ -n "$current_file" ] && echo "$current_file" >> "$CHANGED_FILES_CACHE" + ;; + "@@"*) + [ -z "$current_file" ] && continue range=$(echo "$line" | sed 's/.*+\([0-9,]*\).*/\1/') - if echo "$range" | grep -q ","; then - start=$(echo "$range" | cut -d',' -f1) - count=$(echo "$range" | cut -d',' -f2) - else - start="$range" - count=1 - fi - + range_info=$(parse_diff_range "$range") + start=$(echo "$range_info" | cut -d' ' -f1) + count=$(echo "$range_info" | cut -d' ' -f2) + case "$start" in ''|*[!0-9]*) continue ;; esac case "$count" in ''|*[!0-9]*) continue ;; esac @@ -84,17 +132,17 @@ build_changed_lines_cache() { echo "$current_file:$i" >> "$CHANGED_LINES_CACHE" i=$((i + 1)) done - fi - fi + ;; + esac done < "$ALL_DIFF" } -get_p1_violations_count() { +get_p1_count() { p1_count=$(grep -Eo "p1=[0-9]+" "$CODENARC_RESULT" | cut -d'=' -f2 | head -1) echo "${p1_count:-0}" } -parse_allowed_file_patterns() { +get_allowed_patterns() { [ -n "$INPUT_SOURCE_FILES" ] && echo "$INPUT_SOURCE_FILES" | tr ',' '\n' | sed 's/\*\*/.*/g' } @@ -105,77 +153,53 @@ file_matches_patterns() { [ -z "$patterns" ] && return 0 for pattern in $patterns; do - if echo "$file" | grep -Eq "$pattern"; then - return 0 - fi + echo "$file" | grep -Eq "$pattern" && return 0 done - return 1 } -line_is_in_changed_range() { - target_line="$1" - file="$2" - - grep -q "^$file:$target_line$" "$CHANGED_LINES_CACHE" +is_line_changed() { + grep -q "^$2:$1$" "$CHANGED_LINES_CACHE" } -file_was_changed() { - file="$1" - grep -q "^$file$" "$CHANGED_FILES_CACHE" +is_file_changed() { + grep -q "^$1$" "$CHANGED_FILES_CACHE" } check_blocking_rules() { echo "🔎 Verificando violações bloqueantes (priority 1)..." - [ ! -f "$CODENARC_RESULT" ] && echo "❌ Arquivo de resultado não encontrado" && return 1 + [ ! -f "$CODENARC_RESULT" ] && echo "❌ Resultado não encontrado" && return 1 - p1_count=$(get_p1_violations_count) - echo "📊 Total de P1 encontradas: $p1_count" + p1_count=$(get_p1_count) + echo "📊 Total de P1: $p1_count" - if [ "$p1_count" -eq 0 ]; then - echo "✅ Nenhuma P1 detectada → merge permitido (análise de diff desnecessária)" - return 0 - fi + [ "$p1_count" -eq 0 ] && echo "✅ Nenhuma P1 → merge permitido" && return 0 - echo "⚠️ P1s detectadas → verificando se estão em linhas alteradas..." - generate_all_diff + echo "⚠️ Verificando P1s em linhas alteradas..." build_changed_lines_cache - allowed_patterns=$(parse_allowed_file_patterns) - if [ -n "$allowed_patterns" ]; then - echo "🧩 Analisando apenas arquivos filtrados por INPUT_SOURCE_FILES" - fi + allowed_patterns=$(get_allowed_patterns) + [ -n "$allowed_patterns" ] && echo "🧩 Filtrando por INPUT_SOURCE_FILES" echo "0" > "$VIOLATIONS_FLAG" - grep -E ':[0-9]+:|:[0-9]*:' "$CODENARC_RESULT" > "$TEMP_VIOLATIONS" - - [ ! -s "$TEMP_VIOLATIONS" ] && echo "✅ Nenhuma violação encontrada no resultado" && return 0 - - while IFS=: read -r file line rest; do + grep -E ':[0-9]+:|:null:|\|\|' "$CODENARC_RESULT" | while IFS=: read -r file line rest; do [ -z "$file" ] && continue - - if ! file_matches_patterns "$file" "$allowed_patterns"; then - continue - fi + file_matches_patterns "$file" "$allowed_patterns" || continue if [ -z "$line" ] || [ "$line" = "null" ]; then - if file_was_changed "$file"; then + if is_file_changed "$file"; then echo "📍 Violação file-based em arquivo alterado: $file" - echo "1" > "$VIOLATIONS_FLAG" - break + echo "1" > "$VIOLATIONS_FLAG" && break fi - elif line_is_in_changed_range "$line" "$file"; then + elif is_line_changed "$line" "$file"; then echo "📍 Violação em linha alterada: $file:$line" - echo "1" > "$VIOLATIONS_FLAG" - break + echo "1" > "$VIOLATIONS_FLAG" && break fi - done < "$TEMP_VIOLATIONS" - - violations_in_diff=$(cat "$VIOLATIONS_FLAG") + done - if [ "$violations_in_diff" -eq 1 ]; then + if [ "$(cat "$VIOLATIONS_FLAG")" -eq 1 ]; then echo "⛔ P1s existem E há violações em linhas alteradas → DEVERIA bloquear merge" echo "🔧 Exit desabilitado temporariamente para monitoramento" # exit 1 @@ -184,6 +208,7 @@ check_blocking_rules() { fi } +# Setup if [ -n "${GITHUB_WORKSPACE}" ]; then cd "${GITHUB_WORKSPACE}/${INPUT_WORKDIR}" || exit git config --global --add safe.directory "$GITHUB_WORKSPACE" @@ -191,8 +216,9 @@ fi export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}" +# Execute pipeline run_codenarc run_reviewdog check_blocking_rules -echo "🏁 Concluído com sucesso" +echo "🏁 Concluído com sucesso" \ No newline at end of file From b351f1c049e68e74f3d6ccfb0bfe5b00d313e634 Mon Sep 17 00:00:00 2001 From: "ana.alves" Date: Fri, 19 Dec 2025 13:58:49 -0300 Subject: [PATCH 20/25] testando abordagem hibrida reviewdog --- entrypoint.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 8766223..4b0294d 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -52,7 +52,12 @@ run_reviewdog_with_config() { separate_violations() { grep -E ':[0-9]+:' "$CODENARC_RESULT" > "$LINE_VIOLATIONS" || true - grep -E ':null:|::' "$CODENARC_RESULT" > "$FILE_VIOLATIONS" || true + grep -E ':null:' "$CODENARC_RESULT" > "$FILE_VIOLATIONS" || true + + echo "🔍 DEBUG: Line violations encontradas:" + [ -s "$LINE_VIOLATIONS" ] && head -3 "$LINE_VIOLATIONS" || echo "Nenhuma" + echo "🔍 DEBUG: File violations encontradas:" + [ -s "$FILE_VIOLATIONS" ] && head -3 "$FILE_VIOLATIONS" || echo "Nenhuma" } run_reviewdog() { @@ -71,7 +76,7 @@ run_reviewdog() { # Violações file-based forçando github-pr-check if [ -s "$FILE_VIOLATIONS" ]; then echo "📤 Enviando violações file-based (github-pr-check)..." - run_reviewdog_with_config "$FILE_VIOLATIONS" "%f::%m" \ + run_reviewdog_with_config "$FILE_VIOLATIONS" "%f:%l:%m" \ "github-pr-check" "codenarc-files" "nofilter" "warning" fi @@ -184,7 +189,7 @@ check_blocking_rules() { echo "0" > "$VIOLATIONS_FLAG" - grep -E ':[0-9]+:|:null:|\|\|' "$CODENARC_RESULT" | while IFS=: read -r file line rest; do + grep -E ':[0-9]+:|:null:' "$CODENARC_RESULT" | while IFS=: read -r file line rest; do [ -z "$file" ] && continue file_matches_patterns "$file" "$allowed_patterns" || continue From 17ccafa25f658d92a2530050cc4e7d40530fe844 Mon Sep 17 00:00:00 2001 From: "ana.alves" Date: Fri, 19 Dec 2025 14:08:51 -0300 Subject: [PATCH 21/25] testando abordagem hibrida reviewdog --- entrypoint.sh | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 4b0294d..b69a18e 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -12,7 +12,8 @@ CHANGED_FILES_CACHE="/tmp/changed_files.txt" cleanup_temp_files() { rm -f "$CODENARC_RESULT" "$LINE_VIOLATIONS" "$FILE_VIOLATIONS" "$VIOLATIONS_FLAG" \ - "$ALL_DIFF" "$CHANGED_LINES_CACHE" "$CHANGED_FILES_CACHE" >/dev/null 2>&1 + "$ALL_DIFF" "$CHANGED_LINES_CACHE" "$CHANGED_FILES_CACHE" \ + "${FILE_VIOLATIONS}.formatted" >/dev/null 2>&1 } trap 'cleanup_temp_files' EXIT @@ -51,8 +52,16 @@ run_reviewdog_with_config() { } separate_violations() { + echo "🔍 DEBUG: Conteúdo completo do CODENARC_RESULT:" + echo "--- INÍCIO ---" + cat "$CODENARC_RESULT" + echo "--- FIM ---" + + # Capturar violações line-based (formato: arquivo:linha:regra) grep -E ':[0-9]+:' "$CODENARC_RESULT" > "$LINE_VIOLATIONS" || true - grep -E ':null:' "$CODENARC_RESULT" > "$FILE_VIOLATIONS" || true + + # Capturar violações file-based (ambos os formatos: :null: e ||) + grep -E ':null:|\|\|' "$CODENARC_RESULT" > "$FILE_VIOLATIONS" || true echo "🔍 DEBUG: Line violations encontradas:" [ -s "$LINE_VIOLATIONS" ] && head -3 "$LINE_VIOLATIONS" || echo "Nenhuma" @@ -69,15 +78,28 @@ run_reviewdog() { if [ -s "$LINE_VIOLATIONS" ]; then echo "📤 Enviando violações com linha (${INPUT_REPORTER:-github-pr-check})..." run_reviewdog_with_config "$LINE_VIOLATIONS" "%f:%l:%m" \ - "${INPUT_REPORTER:-github-pr-check}" "codenarc-lines" \ + "${INPUT_REPORTER:-github-pr-check}" "codenarc" \ "${INPUT_FILTER_MODE}" "${INPUT_LEVEL}" fi # Violações file-based forçando github-pr-check if [ -s "$FILE_VIOLATIONS" ]; then echo "📤 Enviando violações file-based (github-pr-check)..." - run_reviewdog_with_config "$FILE_VIOLATIONS" "%f:%l:%m" \ - "github-pr-check" "codenarc-files" "nofilter" "warning" + + # Criar arquivo temporário com formato correto para reviewdog + > "${FILE_VIOLATIONS}.formatted" + while read -r violation; do + if echo "$violation" | grep -q '||'; then + # Formato CI: arquivo||regra mensagem -> arquivo::regra mensagem + echo "$violation" | sed 's/||/::/' + else + # Formato local: arquivo:null:regra mensagem -> arquivo::regra mensagem + echo "$violation" | sed 's/:null:/::/' + fi + done < "$FILE_VIOLATIONS" > "${FILE_VIOLATIONS}.formatted" + + run_reviewdog_with_config "${FILE_VIOLATIONS}.formatted" "%f::%m" \ + "github-pr-check" "codenarc" "nofilter" "warning" fi # Fallback se não houver violações categorizadas @@ -189,7 +211,12 @@ check_blocking_rules() { echo "0" > "$VIOLATIONS_FLAG" - grep -E ':[0-9]+:|:null:' "$CODENARC_RESULT" | while IFS=: read -r file line rest; do + grep -E ':[0-9]+:|:null:|\|\|' "$CODENARC_RESULT" | while IFS=: read -r file line rest; do + # Tratar formato || (ambiente CI) + if echo "$file" | grep -q '||'; then + file=$(echo "$file" | cut -d'|' -f1) + line="" + fi [ -z "$file" ] && continue file_matches_patterns "$file" "$allowed_patterns" || continue From 60e2cb6ff75405d9f410669047b18568a0c14b1c Mon Sep 17 00:00:00 2001 From: "ana.alves" Date: Fri, 19 Dec 2025 14:37:53 -0300 Subject: [PATCH 22/25] removendo comentarios de debug --- entrypoint.sh | 47 +++++++++++++++-------------------------------- 1 file changed, 15 insertions(+), 32 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index b69a18e..f2947df 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,7 +1,6 @@ #!/bin/sh set -e -# Constants CODENARC_RESULT="result.txt" LINE_VIOLATIONS="line_violations.txt" FILE_VIOLATIONS="file_violations.txt" @@ -52,21 +51,8 @@ run_reviewdog_with_config() { } separate_violations() { - echo "🔍 DEBUG: Conteúdo completo do CODENARC_RESULT:" - echo "--- INÍCIO ---" - cat "$CODENARC_RESULT" - echo "--- FIM ---" - - # Capturar violações line-based (formato: arquivo:linha:regra) grep -E ':[0-9]+:' "$CODENARC_RESULT" > "$LINE_VIOLATIONS" || true - - # Capturar violações file-based (ambos os formatos: :null: e ||) grep -E ':null:|\|\|' "$CODENARC_RESULT" > "$FILE_VIOLATIONS" || true - - echo "🔍 DEBUG: Line violations encontradas:" - [ -s "$LINE_VIOLATIONS" ] && head -3 "$LINE_VIOLATIONS" || echo "Nenhuma" - echo "🔍 DEBUG: File violations encontradas:" - [ -s "$FILE_VIOLATIONS" ] && head -3 "$FILE_VIOLATIONS" || echo "Nenhuma" } run_reviewdog() { @@ -74,35 +60,35 @@ run_reviewdog() { separate_violations - # Violações line-based com reporter configurado if [ -s "$LINE_VIOLATIONS" ]; then - echo "📤 Enviando violações com linha (${INPUT_REPORTER:-github-pr-check})..." + echo "📤 Enviando violações line-based (${INPUT_REPORTER:-github-pr-check})..." run_reviewdog_with_config "$LINE_VIOLATIONS" "%f:%l:%m" \ "${INPUT_REPORTER:-github-pr-check}" "codenarc" \ "${INPUT_FILTER_MODE}" "${INPUT_LEVEL}" fi - # Violações file-based forçando github-pr-check if [ -s "$FILE_VIOLATIONS" ]; then - echo "📤 Enviando violações file-based (github-pr-check)..." - - # Criar arquivo temporário com formato correto para reviewdog > "${FILE_VIOLATIONS}.formatted" while read -r violation; do if echo "$violation" | grep -q '||'; then - # Formato CI: arquivo||regra mensagem -> arquivo::regra mensagem echo "$violation" | sed 's/||/::/' else - # Formato local: arquivo:null:regra mensagem -> arquivo::regra mensagem echo "$violation" | sed 's/:null:/::/' fi done < "$FILE_VIOLATIONS" > "${FILE_VIOLATIONS}.formatted" - run_reviewdog_with_config "${FILE_VIOLATIONS}.formatted" "%f::%m" \ - "github-pr-check" "codenarc" "nofilter" "warning" + if [ "${INPUT_REPORTER}" = "local" ]; then + echo "📤 Enviando violações file-based (local)..." + run_reviewdog_with_config "${FILE_VIOLATIONS}.formatted" "%f::%m" \ + "local" "codenarc" "nofilter" "${INPUT_LEVEL}" + else + echo "📤 Enviando violações file-based (github-pr-check)..." + run_reviewdog_with_config "${FILE_VIOLATIONS}.formatted" "%f::%m" \ + "github-pr-check" "codenarc" "nofilter" "warning" + fi fi - # Fallback se não houver violações categorizadas + # fallback se nao houver violacoes categorizadas if [ ! -s "$LINE_VIOLATIONS" ] && [ ! -s "$FILE_VIOLATIONS" ]; then echo "📝 Executando reviewdog padrão..." run_reviewdog_with_config "$CODENARC_RESULT" "%f:%l:%m" \ @@ -199,20 +185,19 @@ check_blocking_rules() { [ ! -f "$CODENARC_RESULT" ] && echo "❌ Resultado não encontrado" && return 1 p1_count=$(get_p1_count) - echo "📊 Total de P1: $p1_count" + echo "📊 Total de P1 encontradas: $p1_count" - [ "$p1_count" -eq 0 ] && echo "✅ Nenhuma P1 → merge permitido" && return 0 + [ "$p1_count" -eq 0 ] && echo "✅ Nenhuma P1 detectada → merge permitido" && return 0 echo "⚠️ Verificando P1s em linhas alteradas..." build_changed_lines_cache allowed_patterns=$(get_allowed_patterns) - [ -n "$allowed_patterns" ] && echo "🧩 Filtrando por INPUT_SOURCE_FILES" + [ -n "$allowed_patterns" ] && echo "🧩 Analisando apenas arquivos filtrados por INPUT_SOURCE_FILES" echo "0" > "$VIOLATIONS_FLAG" grep -E ':[0-9]+:|:null:|\|\|' "$CODENARC_RESULT" | while IFS=: read -r file line rest; do - # Tratar formato || (ambiente CI) if echo "$file" | grep -q '||'; then file=$(echo "$file" | cut -d'|' -f1) line="" @@ -236,11 +221,10 @@ check_blocking_rules() { echo "🔧 Exit desabilitado temporariamente para monitoramento" # exit 1 else - echo "✅ P1s existem mas FORA das linhas alteradas → merge permitido" + echo "✅ P1s existem mas fora das linhas alteradas → merge permitido" fi } -# Setup if [ -n "${GITHUB_WORKSPACE}" ]; then cd "${GITHUB_WORKSPACE}/${INPUT_WORKDIR}" || exit git config --global --add safe.directory "$GITHUB_WORKSPACE" @@ -248,7 +232,6 @@ fi export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}" -# Execute pipeline run_codenarc run_reviewdog check_blocking_rules From 298dd8468eb4fb9d3d4647f6b204428417c31556 Mon Sep 17 00:00:00 2001 From: "ana.alves" Date: Fri, 19 Dec 2025 14:51:12 -0300 Subject: [PATCH 23/25] removendo comentarios de debug --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index f2947df..33cb340 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -68,7 +68,7 @@ run_reviewdog() { fi if [ -s "$FILE_VIOLATIONS" ]; then - > "${FILE_VIOLATIONS}.formatted" + true > "${FILE_VIOLATIONS}.formatted" while read -r violation; do if echo "$violation" | grep -q '||'; then echo "$violation" | sed 's/||/::/' From 45b9f68cb80190aaf5d849a44c58663fc96771e5 Mon Sep 17 00:00:00 2001 From: "ana.alves" Date: Fri, 19 Dec 2025 15:23:57 -0300 Subject: [PATCH 24/25] adicionando logs de debug --- entrypoint.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/entrypoint.sh b/entrypoint.sh index 33cb340..db7dfd4 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -51,8 +51,17 @@ run_reviewdog_with_config() { } separate_violations() { + echo "📝 DEBUG: Conteúdo do CODENARC_RESULT:" + cat "$CODENARC_RESULT" + echo "📝 DEBUG: Fim do CODENARC_RESULT" + grep -E ':[0-9]+:' "$CODENARC_RESULT" > "$LINE_VIOLATIONS" || true grep -E ':null:|\|\|' "$CODENARC_RESULT" > "$FILE_VIOLATIONS" || true + + echo "📝 DEBUG: Line violations capturadas:" + [ -s "$LINE_VIOLATIONS" ] && cat "$LINE_VIOLATIONS" || echo "Nenhuma" + echo "📝 DEBUG: File violations capturadas:" + [ -s "$FILE_VIOLATIONS" ] && cat "$FILE_VIOLATIONS" || echo "Nenhuma" } run_reviewdog() { From daf4cb39c966c7355c6c2544751259915f375eb9 Mon Sep 17 00:00:00 2001 From: "ana.alves" Date: Fri, 19 Dec 2025 15:32:46 -0300 Subject: [PATCH 25/25] removendo logs de debug --- entrypoint.sh | 9 --------- 1 file changed, 9 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index db7dfd4..33cb340 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -51,17 +51,8 @@ run_reviewdog_with_config() { } separate_violations() { - echo "📝 DEBUG: Conteúdo do CODENARC_RESULT:" - cat "$CODENARC_RESULT" - echo "📝 DEBUG: Fim do CODENARC_RESULT" - grep -E ':[0-9]+:' "$CODENARC_RESULT" > "$LINE_VIOLATIONS" || true grep -E ':null:|\|\|' "$CODENARC_RESULT" > "$FILE_VIOLATIONS" || true - - echo "📝 DEBUG: Line violations capturadas:" - [ -s "$LINE_VIOLATIONS" ] && cat "$LINE_VIOLATIONS" || echo "Nenhuma" - echo "📝 DEBUG: File violations capturadas:" - [ -s "$FILE_VIOLATIONS" ] && cat "$FILE_VIOLATIONS" || echo "Nenhuma" } run_reviewdog() {