Auto commit: 2024-12-16 06:00:01 #47
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Monitor Changes, Lint, Tests and Send Notifications | |
on: | |
push: | |
branches: [ main, dev ] | |
workflow_dispatch: | |
jobs: | |
lint_tests_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 | |
# Check if dev branch exists | |
if git rev-parse --verify origin/dev >/dev/null 2>&1; then | |
# Compare changes between dev and main branches | |
git diff --name-only origin/main origin/dev > changes.txt | |
changes=$(cat changes.txt | tr '\n' ', ' | sed 's/,$//') | |
else | |
changes="No dev branch" | |
fi | |
echo "files_changed=$changes" >> $GITHUB_OUTPUT | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
pip install flake8 pytest torch torchvision | |
- 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" | |
) | |
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 | |
# Only check for bugs (E9**, F***) and ignore style issues | |
flake8_output=$(flake8 --select=E9,F "${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: Run basic tests | |
id: basic_tests | |
run: | | |
test_output=$(python github_tests.py) | |
echo "test_results<<EOF" >> $GITHUB_OUTPUT | |
echo "$test_output" >> $GITHUB_OUTPUT | |
echo "EOF" >> $GITHUB_OUTPUT | |
- 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 || 'Нет замечаний линтера' }} ✨ | |
🧪 Результаты тестов: | |
${{ steps.basic_tests.outputs.test_results || 'Тесты не были выполнены' }} 🚀 |