Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 47 additions & 20 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,34 +1,61 @@
#!/bin/sh
set -e
trap 'rm -f result.txt >/dev/null 2>&1' EXIT

if [ -n "${GITHUB_WORKSPACE}" ] ; then
cd "${GITHUB_WORKSPACE}/${INPUT_WORKDIR}" || exit
git config --global --add safe.directory "$GITHUB_WORKSPACE" || exit
fi
run_codenarc() {
report="${INPUT_REPORT:-compact:stdout}"
includes_arg=""

export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}"
if [ -n "$INPUT_SOURCE_FILES" ]; then
includes_arg="-includes=${INPUT_SOURCE_FILES}"
fi

if [ -n "$INPUT_SOURCE_FILES" ]; then
java -jar /lib/codenarc-all.jar \
-report="${INPUT_REPORT:-compact:stdout}" \
-rulesetfiles="${INPUT_RULESETFILES}" \
-basedir="." \
-includes="${INPUT_SOURCE_FILES}" \
> result.txt
else
echo "🔍 Executando CodeNarc..."
java -jar /lib/codenarc-all.jar \
-report="${INPUT_REPORT:-compact:stdout}" \
-rulesetfiles="${INPUT_RULESETFILES}" \
> result.txt
fi

-report="$report" \
-rulesetfiles="${INPUT_RULESETFILES}" \
-basedir="." \
$includes_arg \
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[shellcheck (suggestion)] reported by reviewdog 🐶

Suggested change
$includes_arg \
"$includes_arg" \

> result.txt
}

< result.txt reviewdog -efm="%f:%l:%m" -efm="%f:%r:%m" \
run_reviewdog() {
echo "📤 Enviando resultados para reviewdog..."
< 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}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[shellcheck (suggestion)] reported by reviewdog 🐶

Suggested change
${INPUT_REVIEWDOG_FLAGS}
"${INPUT_REVIEWDOG_FLAGS}"

}

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}

echo "📊 Resumo CodeNarc → priority 1=${p1_count}"

if [ "$p1_count" -gt 0 ]; then
echo "⛔ Foram encontradas violacoes bloqueantes (priority 1)."
echo "💡 Corrija as violacoes ou use o bypass autorizado pelo coordenador."
exit 1
else
echo "✅ Nenhuma violacao bloqueante (priority 1) encontrada."
fi
}

if [ -n "${GITHUB_WORKSPACE}" ]; then
cd "${GITHUB_WORKSPACE}/${INPUT_WORKDIR}" || exit
git config --global --add safe.directory "$GITHUB_WORKSPACE"
fi

export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}"

run_codenarc
run_reviewdog
check_blocking_rules

rm result.txt
echo "🏁 Finalizado com sucesso."
Loading