Skip to content

Auto commit: 2024-12-03 01:35:17 #31

Auto commit: 2024-12-03 01:35:17

Auto commit: 2024-12-03 01:35:17 #31

name: Monitor Changes, Lint, and Send Notifications
on:
push:
branches: [ dev ] # Adjust this to the branch you want to monitor
workflow_dispatch:
jobs:
lint_and_notify:
runs-on: ubuntu-24.04
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Get Commit Details
id: commit_details
run: |
# Escape special characters in commit message
message=$(git log -1 --pretty=%B | sed 's/"/\\"/g')
author=$(git log -1 --pretty=%an | sed 's/"/\\"/g')
echo "message=$message" >> $GITHUB_OUTPUT
echo "author=$author" >> $GITHUB_OUTPUT
- name: Check for changes
id: check_changes
run: |
rm -f changes.txt
# Fetch both branches
git fetch origin main dev || true
# Compare changes between dev and main branches
git diff --name-only origin/main origin/dev > changes.txt
echo "files_changed=$(cat changes.txt)" >> $GITHUB_OUTPUT
- name: Install flake8
run: |
python -m pip install --upgrade pip
pip install flake8
- name: Run flake8
id: flake8
run: |
# Check if files exist before running flake8
files_to_lint=(
"scripts/auto_commit.py"
"pl_models.py"
"test.py"
"train.py"
"models/unet_fft.py"
"xrd_transformer.py"
"model.py"
"datasets/train.py"
"datasets/test.py"
)
existing_files=()
for file in "${files_to_lint[@]}"; do
if [ -f "$file" ]; then
existing_files+=("$file")
fi
done
if [ ${#existing_files[@]} -eq 0 ]; then
echo "lint_results=No Python files found to lint" >> $GITHUB_OUTPUT
else
flake8_output=$(flake8 "${existing_files[@]}" || true)
echo "$flake8_output" > flake8_output.txt
lint_results=$(head -n 5 flake8_output.txt | sed ':a;N;$!ba;s/\n/%0A/g' | sed 's/"/\\"/g')
echo "lint_results=$lint_results" >> $GITHUB_OUTPUT
fi
- name: Send Telegram Notification
if: always()
uses: appleboy/telegram-action@master
with:
to: ${{ secrets.TELEGRAM_CHAT_ID }}
token: ${{ secrets.TELEGRAM_BOT_TOKEN }}
message: |
🔄 Новые изменения обнаружены!
Сообщение коммита: ${{ steps.commit_details.outputs.message || 'Нет сообщения' }}
Автор: ${{ steps.commit_details.outputs.author || 'Неизвестный автор' }}
Измененные файлы:
${{ steps.check_changes.outputs.files_changed || 'Нет измененных файлов' }}
Репозиторий: ${{ github.repository }}
Ссылка: ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}
⚠️ Результаты линтинга:
${{ steps.flake8.outputs.lint_results || 'Нет замечаний линтера' }}