Skip to content

Commit 0b20c6c

Browse files
feat: bloquear merge em violacoes bloqueantes do codenarc no grails 4
1 parent ec2147b commit 0b20c6c

File tree

1 file changed

+59
-21
lines changed

1 file changed

+59
-21
lines changed

entrypoint.sh

Lines changed: 59 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,72 @@
11
#!/bin/sh
22
set -e
3+
trap 'rm -f result.txt >/dev/null 2>&1' EXIT
34

4-
if [ -n "${GITHUB_WORKSPACE}" ] ; then
5-
cd "${GITHUB_WORKSPACE}/${INPUT_WORKDIR}" || exit
6-
git config --global --add safe.directory "$GITHUB_WORKSPACE" || exit
7-
fi
5+
# --- auxiliares -------------------------------------------------------
86

9-
export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}"
7+
run_codenarc() {
8+
local report="${INPUT_REPORT:-compact:stdout}"
9+
local includes_arg=""
10+
11+
if [ -n "$INPUT_SOURCE_FILES" ]; then
12+
includes_arg="-includes=${INPUT_SOURCE_FILES}"
13+
fi
1014

11-
if [ -n "$INPUT_SOURCE_FILES" ]; then
15+
echo "🔍 Executando CodeNarc..."
1216
java -jar /lib/codenarc-all.jar \
13-
-report="${INPUT_REPORT:-compact:stdout}" \
17+
-report="$report" \
1418
-rulesetfiles="${INPUT_RULESETFILES}" \
1519
-basedir="." \
16-
-includes="${INPUT_SOURCE_FILES}" \
17-
> result.txt
18-
else
19-
java -jar /lib/codenarc-all.jar \
20-
-report="${INPUT_REPORT:-compact:stdout}" \
21-
-rulesetfiles="${INPUT_RULESETFILES}" \
20+
$includes_arg \
2221
> result.txt
22+
}
23+
24+
run_reviewdog() {
25+
echo "📤 Enviando resultados para reviewdog..."
26+
< result.txt reviewdog -efm="%f:%l:%m" -efm="%f:%r:%m" \
27+
-name="codenarc" \
28+
-reporter="${INPUT_REPORTER:-github-pr-check}" \
29+
-filter-mode="${INPUT_FILTER_MODE}" \
30+
-fail-on-error="${INPUT_FAIL_ON_ERROR}" \
31+
-level="${INPUT_LEVEL}" \
32+
${INPUT_REVIEWDOG_FLAGS}
33+
}
34+
35+
check_blocking_rules() {
36+
if [ "${INPUT_GRAILS_VERSION}" = "4" ]; then
37+
echo "🔎 Verificando violacoes bloqueantes (priority 1 ou 2)..."
38+
39+
local p1_count=$(grep -Eo "p1=[0-9]+" result.txt | cut -d'=' -f2 | tail -1)
40+
local p2_count=$(grep -Eo "p2=[0-9]+" result.txt | cut -d'=' -f2 | tail -1)
41+
42+
p1_count=${p1_count:-0}
43+
p2_count=${p2_count:-0}
44+
45+
echo "📊 Resumo CodeNarc -> p1=${p1_count}, p2=${p2_count}"
46+
47+
if [ "$p1_count" -gt 0 ] || [ "$p2_count" -gt 0 ]; then
48+
echo "⛔ Encontradas violacoes bloqueantes (priority 1 ou 2)."
49+
echo "💡 Corrija as violacoes ou faca bypass autorizado."
50+
exit 1
51+
else
52+
echo "✅ Nenhuma violacao bloqueante encontrada."
53+
fi
54+
else
55+
echo "ℹ️ Modo Grails 2 detectado (sem bloqueio automatico)."
56+
fi
57+
}
58+
59+
# --- principal -------------------------------------------------------
60+
61+
if [ -n "${GITHUB_WORKSPACE}" ] ; then
62+
cd "${GITHUB_WORKSPACE}/${INPUT_WORKDIR}" || exit
63+
git config --global --add safe.directory "$GITHUB_WORKSPACE"
2364
fi
2465

66+
export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}"
2567

26-
< result.txt reviewdog -efm="%f:%l:%m" -efm="%f:%r:%m" \
27-
-name="codenarc" \
28-
-reporter="${INPUT_REPORTER:-github-pr-check}" \
29-
-filter-mode="${INPUT_FILTER_MODE}" \
30-
-fail-on-error="${INPUT_FAIL_ON_ERROR}" \
31-
-level="${INPUT_LEVEL}" \
32-
${INPUT_REVIEWDOG_FLAGS}
68+
run_codenarc
69+
run_reviewdog
70+
check_blocking_rules
3371

34-
rm result.txt
72+
echo "🏁 Finalizado com sucesso."

0 commit comments

Comments
 (0)