Skip to content

Commit d60758f

Browse files
fix: configura autenticacao git no codenarc action para evitar erro 128
1 parent 342147f commit d60758f

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

entrypoint.sh

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,24 +90,20 @@ run_reviewdog() {
9090

9191
generate_git_diff() {
9292
if [ -n "$GITHUB_BASE_SHA" ] && [ -n "$GITHUB_HEAD_SHA" ]; then
93-
if git cat-file -e "$GITHUB_BASE_SHA" 2>/dev/null && git cat-file -e "$GITHUB_HEAD_SHA" 2>/dev/null; then
94-
git diff -U0 "$GITHUB_BASE_SHA" "$GITHUB_HEAD_SHA" -- '*.groovy' 2>&1
95-
else
96-
git fetch origin "$GITHUB_BASE_SHA" --depth=1 2>&1 || true
97-
git fetch origin "$GITHUB_HEAD_SHA" --depth=1 2>&1 || true
98-
git diff -U0 "$GITHUB_BASE_SHA" "$GITHUB_HEAD_SHA" -- '*.groovy' 2>&1
99-
fi
93+
git fetch origin "$GITHUB_BASE_SHA" --depth=1 >/dev/null 2>&1 || true
94+
git fetch origin "$GITHUB_HEAD_SHA" --depth=1 >/dev/null 2>&1 || true
95+
git diff -U0 "$GITHUB_BASE_SHA" "$GITHUB_HEAD_SHA" -- '*.groovy'
10096
else
101-
git diff -U0 HEAD~1 -- '*.groovy' 2>&1
97+
git diff -U0 HEAD~1 -- '*.groovy'
10298
fi
10399
}
104100

105101
build_changed_lines_cache() {
106102
true > "$CHANGED_FILES_CACHE"
107103
true > "$CHANGED_LINES_CACHE"
108104

109-
generate_git_diff > "$ALL_DIFF" 2>&1
110-
[ ! -s "$ALL_DIFF" ] && return 1
105+
generate_git_diff > "$ALL_DIFF" 2>/dev/null || return
106+
[ ! -s "$ALL_DIFF" ] && return
111107

112108
awk '
113109
BEGIN { file = ""; line_num = 0 }
@@ -189,9 +185,12 @@ check_blocking_rules() {
189185

190186
echo ""
191187
echo "⚠️ Analisando se as P1s estão em linhas alteradas..."
192-
193-
if ! build_changed_lines_cache || [ ! -s "$ALL_DIFF" ]; then
194-
echo "❌ Não foi possível gerar diff. Todas as P1s serão consideradas bloqueantes."
188+
build_changed_lines_cache
189+
190+
if [ ! -s "$ALL_DIFF" ]; then
191+
echo ""
192+
echo "⚠️ Diff vazio: Sem informações de linhas alteradas. Todas as P1s são consideradas bloqueantes."
193+
echo "💡 Corrija as violações ou use um bypass autorizado."
195194
exit 1
196195
fi
197196

@@ -228,6 +227,10 @@ if [ -n "${GITHUB_WORKSPACE}" ]; then
228227
git config --global --add safe.directory "$GITHUB_WORKSPACE"
229228
fi
230229

230+
if [ -n "${INPUT_GITHUB_TOKEN}" ]; then
231+
git config --global url."https://x-access-token:${INPUT_GITHUB_TOKEN}@github.com/".insteadOf "https://github.com/"
232+
fi
233+
231234
export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}"
232235

233236
run_codenarc

0 commit comments

Comments
 (0)