test #5
@@ -35,51 +35,140 @@ jobs:
|
|||||||
cd api
|
cd api
|
||||||
pytest tests/
|
pytest tests/
|
||||||
|
|
||||||
# test-frontend:
|
test-frontend:
|
||||||
# needs: test-backend
|
needs: test-backend
|
||||||
# runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
# steps:
|
steps:
|
||||||
# - name: Checkout code
|
- name: Checkout code
|
||||||
# uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
# - name: Set up Node.js
|
- name: Set up Node.js
|
||||||
# uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
# with:
|
with:
|
||||||
# node-version: '20'
|
node-version: '20'
|
||||||
|
|
||||||
# - name: Install dependencies
|
- name: Install dependencies
|
||||||
# run: |
|
run: |
|
||||||
# cd web
|
cd web
|
||||||
# npm ci
|
npm ci
|
||||||
|
|
||||||
# - name: Build frontend
|
- name: Build frontend
|
||||||
# run: |
|
run: |
|
||||||
# cd web
|
cd web
|
||||||
# npm run build
|
npm run build
|
||||||
|
|
||||||
create-archives:
|
create-archives:
|
||||||
needs: [test-backend, test-frontend]
|
needs: [test-backend, test-frontend]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: success()
|
if: always() && !cancelled()
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Create archives
|
- name: Create archives
|
||||||
run: |
|
run: |
|
||||||
# Создаём архивы с исключением ненужных файлов
|
|
||||||
zip -r api.zip api/ -x "*.pyc" "*__pycache__*" "*.git*" "*.pytest_cache*"
|
zip -r api.zip api/ -x "*.pyc" "*__pycache__*" "*.git*" "*.pytest_cache*"
|
||||||
zip -r web.zip web/ -x "node_modules/*" ".git*" "dist/*" "*.log"
|
zip -r web.zip web/ -x "node_modules/*" ".git*" "dist/*" "*.log"
|
||||||
|
|
||||||
# Создаём общий архив
|
|
||||||
zip -r full-build.zip api/ web/ -x "*/node_modules/*" "*__pycache__*" "*.pyc" "*.git*"
|
|
||||||
|
|
||||||
- name: Upload artifacts
|
- name: Upload artifacts
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: build-artifacts
|
name: build-artifacts-${{ github.run_id }}
|
||||||
path: |
|
path: |
|
||||||
api.zip
|
api.zip
|
||||||
web.zip
|
web.zip
|
||||||
full-build.zip
|
retention-days: 7
|
||||||
retention-days: 30 # сколько дней хранить артефакты
|
|
||||||
|
# Явный статус для 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"
|
||||||
|
# Здесь можно добавить логику очистки, если нужно
|
||||||
Reference in New Issue
Block a user