generated from admin/template
164 lines
6.1 KiB
Plaintext
164 lines
6.1 KiB
Plaintext
name: Detekt + Push
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
- master
|
|
workflow_dispatch:
|
|
|
|
permissions:
|
|
contents: write
|
|
|
|
jobs:
|
|
detekt-and-push:
|
|
name: Detekt and push
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
token: ${{ secrets.GITEA_TOKEN }}
|
|
|
|
- name: Set up JDK 17
|
|
uses: actions/setup-java@v4
|
|
with:
|
|
java-version: '17'
|
|
distribution: 'temurin'
|
|
|
|
- name: Download Detekt CLI
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
curl -fsSL -o detekt-cli.jar \
|
|
https://github.com/detekt/detekt/releases/download/v1.23.6/detekt-cli-1.23.6-all.jar
|
|
|
|
- name: Run Detekt
|
|
id: detekt
|
|
shell: bash
|
|
run: |
|
|
set +e
|
|
|
|
java -jar detekt-cli.jar \
|
|
--input . \
|
|
--base-path . \
|
|
--report txt:detekt-report.txt \
|
|
--report checkstyle:detekt-checkstyle.xml \
|
|
> detekt-console-output.txt 2>&1
|
|
|
|
DETEKT_EXIT_CODE=$?
|
|
echo "$DETEKT_EXIT_CODE" > detekt-exit-code.txt
|
|
|
|
# Если Detekt нашёл нарушения, он вернёт ненулевой код
|
|
if [ "$DETEKT_EXIT_CODE" -ne 0 ]; then
|
|
echo "Detekt нашёл нарушения."
|
|
exit 1
|
|
fi
|
|
|
|
echo "Нарушений не найдено."
|
|
exit 0
|
|
|
|
- name: Show readable Detekt report
|
|
if: failure() && steps.detekt.outcome == 'failure'
|
|
shell: bash
|
|
run: |
|
|
set +e
|
|
|
|
echo ""
|
|
echo "╔══════════════════════════════════════════════════════════════╗"
|
|
echo "║ DETEKT CODE REVIEW ║"
|
|
echo "╚══════════════════════════════════════════════════════════════╝"
|
|
echo ""
|
|
|
|
if [ ! -s detekt-report.txt ]; then
|
|
echo "✅ Нарушений не найдено."
|
|
exit 0
|
|
fi
|
|
|
|
TOTAL=$(grep -cve '^[[:space:]]*$' detekt-report.txt || true)
|
|
|
|
echo "📊 Всего нарушений: $TOTAL"
|
|
echo ""
|
|
|
|
echo "┌──────────────────────────────────────────────────────────────┐"
|
|
echo "│ Нарушения по правилам │"
|
|
echo "└──────────────────────────────────────────────────────────────┘"
|
|
|
|
awk '
|
|
{
|
|
rule=$1
|
|
count[rule]++
|
|
}
|
|
END {
|
|
for (rule in count) {
|
|
print count[rule], rule
|
|
}
|
|
}
|
|
' detekt-report.txt \
|
|
| sort -rn \
|
|
| awk '{printf " %4s %s\n", $1, $2}'
|
|
|
|
echo ""
|
|
echo "┌──────────────────────────────────────────────────────────────┐"
|
|
echo "│ Все найденные проблемы │"
|
|
echo "└──────────────────────────────────────────────────────────────┘"
|
|
echo ""
|
|
|
|
while IFS= read -r line; do
|
|
[ -z "$line" ] && continue
|
|
|
|
rule=$(echo "$line" | awk '{print $1}')
|
|
location=$(echo "$line" | sed -nE 's/.* at (.*):([0-9]+):([0-9]+).*/\1:\2:\3/p')
|
|
message=$(echo "$line" | sed -E 's/^[^ ]+ - //')
|
|
|
|
if [ -n "$location" ]; then
|
|
file=$(echo "$location" | cut -d: -f1)
|
|
line_number=$(echo "$location" | cut -d: -f2)
|
|
column_number=$(echo "$location" | cut -d: -f3)
|
|
|
|
file_clean=$(echo "$file" | sed -E 's|^(/)?workspace/[^/]+/[^/]+/||')
|
|
file_clean=$(echo "$file_clean" | sed 's|^/||')
|
|
|
|
repo_url="${{ gitea.server_url }}/${{ gitea.repository }}"
|
|
sha="${{ gitea.sha }}"
|
|
file_url="$repo_url/src/commit/$sha/$file_clean#L$line_number"
|
|
|
|
echo "🔴 [$rule]"
|
|
echo " 📍 $file_clean:$line_number:$column_number"
|
|
echo " 🔗 $file_url"
|
|
echo " 💬 $message"
|
|
else
|
|
echo "🔴 $line"
|
|
fi
|
|
|
|
echo ""
|
|
done < detekt-report.txt
|
|
|
|
echo "══════════════════════════════════════════════════════════════"
|
|
echo "❌ Нарушения найдены. Пуш не выполнен."
|
|
echo "══════════════════════════════════════════════════════════════"
|
|
|
|
- name: Push changes
|
|
if: success()
|
|
shell: bash
|
|
run: |
|
|
# Здесь ваш текущий пуш
|
|
# Например:
|
|
# git config user.name "CI"
|
|
# git config user.email "ci@example.com"
|
|
# git add .
|
|
# git commit -m "CI: update"
|
|
# git push
|
|
|
|
echo "Нарушений нет, выполняем пуш..."
|
|
# Раскомментируйте и адаптируйте под ваш сценарий:
|
|
#
|
|
# git config user.name "Gitea CI"
|
|
# git config user.email "ci@gitea.local"
|
|
#
|
|
# git add .
|
|
# git commit -m "CI: auto update" || echo "Nothing to commit"
|
|
# git push |