Files
python-common-app/.gitea/workflows/ci.yml
EremeevRA 31afed45c0
All checks were successful
CI/CD / test-backend (pull_request) Successful in 7s
CI/CD / test-frontend (pull_request) Successful in 8s
CI/CD / create-archives (pull_request) Successful in 26s
CI/CD Pipeline / Overall Status ✅ All checks passed successfully
CI/CD / pr-status (pull_request) Successful in 1s
CI/CD / comment-on-failure (pull_request) Has been skipped
CI/CD / cleanup (pull_request) Successful in 1s
Update CI workflow to use actions/upload-artifact@v3 for artifact uploads
2026-03-24 12:23:44 +03:00

177 lines
6.1 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: CI/CD
on:
pull_request:
types: [opened, synchronize, reopened]
branches:
- main
- test
workflow_dispatch:
jobs:
test-backend:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: |
cd api
pip install -r requirements.txt
- name: Verify build
run: |
python -c "from api.main import app"
- name: Run tests
run: |
pytest -q
test-frontend:
needs: test-backend
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: |
cd web
npm ci
- name: Build frontend
run: |
cd web
npm run build
create-archives:
needs: [test-backend, test-frontend]
runs-on: ubuntu-latest
if: always() && !cancelled()
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Create archives
run: |
echo "Creating api.zip..."
zip -r api.zip api/ -x "*.pyc" "*__pycache__*" "*.git*" "*.pytest_cache*" || echo "Warning: zip command failed for api"
echo "Creating web.zip..."
zip -r web.zip web/ -x "node_modules/*" ".git*" "dist/*" "*.log" || echo "Warning: zip command failed for web"
# Проверяем, что файлы созданы
ls -la api.zip web.zip
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: build-artifacts-${{ github.run_id }}
path: |
api.zip
web.zip
retention-days: 7
if-no-files-found: error # добавим, чтобы явно указывать, что файлы обязательны
# Явный статус для PR
pr-status:
needs: [test-backend, test-frontend]
runs-on: ubuntu-latest
if: always() && github.event_name == 'pull_request'
steps:
- name: Check status and update PR
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Определяем общий статус проверок
if [[ "${{ needs.test-backend.result }}" == "success" ]] && \
[[ "${{ needs.test-frontend.result }}" == "success" ]]; then
STATE="success"
DESCRIPTION="✅ All checks passed successfully"
EXIT_CODE=0
else
STATE="failure"
DESCRIPTION="❌ Some checks failed"
EXIT_CODE=1
fi
# Формируем URL для API статусов
REPO="${{ github.repository }}"
SHA="${{ github.event.pull_request.head.sha }}"
API_URL="${{ github.api_url }}/repos/${REPO}/statuses/${SHA}"
# Отправляем статус в Gitea
curl -X POST "$API_URL" \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Content-Type: application/json" \
-d "{
\"state\": \"$STATE\",
\"context\": \"CI/CD Pipeline / Overall Status\",
\"description\": \"$DESCRIPTION\",
\"target_url\": \"${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}\"
}"
echo "Status $STATE sent for commit $SHA"
# Выходим с соответствующим кодом, чтобы блокировать PR при неудаче
exit $EXIT_CODE
# Опционально: добавляем комментарий в PR при неудаче
comment-on-failure:
needs: [test-backend, test-frontend, pr-status]
runs-on: ubuntu-latest
if: failure() && github.event_name == 'pull_request'
steps:
- name: Add failure comment to PR
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Определяем какие проверки не прошли
BACKEND_STATUS="${{ needs.test-backend.result }}"
FRONTEND_STATUS="${{ needs.test-frontend.result }}"
COMMENT="## ❌ Проверки не пройдены!
### Результаты проверок:
| Проверка | Статус |
|----------|--------|
| **Backend tests** | $( [ "$BACKEND_STATUS" = "success" ] && echo "✅ Успешно" || echo "❌ Ошибка" ) |
| **Frontend build** | $( [ "$FRONTEND_STATUS" = "success" ] && echo "✅ Успешно" || echo "❌ Ошибка" ) |
### Детали:
- **Ветка**: ${{ github.head_ref }}
- **Коммит**: \`${{ github.event.pull_request.head.sha }}\`
- **Запуск**: [Смотреть детали](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
Пожалуйста, исправьте ошибки перед слиянием. 🚨"
# Находим PR номер
PR_NUMBER=$(jq --raw-output .number "$GITHUB_EVENT_PATH")
# Добавляем комментарий
curl -X POST "${{ github.api_url }}/repos/${{ github.repository }}/issues/${PR_NUMBER}/comments" \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"body\": $(echo "$COMMENT" | jq -Rs .)}"
echo "Comment added to PR #$PR_NUMBER"
# Опционально: удаляем старые артефакты
cleanup:
needs: [create-archives, pr-status]
runs-on: ubuntu-latest
if: always()
steps:
- name: Clean up old artifacts
run: |
echo "Cleaning up temporary files"
# Здесь можно добавить логику очистки, если нужно