Files
DevOpsLab/cicd/github/workflows.yml
Сергей Антропов 787ab06e25 feat: Добавлены 3 стадии в CI/CD пайплайны (lint, test, deploy)
- GitHub Actions: добавлены стадии lint, test, deploy с зависимостями
- Azure DevOps: добавлены стадии lint, test, deploy с зависимостями
- Jenkins: добавлены стадии lint, test, deploy с зависимостями
- GitLab CI: создан новый .gitlab-ci.yml с 3 стадиями

Особенности:
- Деплой происходит только после успешного прохождения lint и test
- Деплой выполняется только для main ветки
- Добавлены уведомления о результатах
- Используются make команды для консистентности
- Параллельное тестирование с разными preset'ами
2025-10-25 19:33:37 +03:00

173 lines
4.5 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.

# GitHub Actions Workflow для AnsibleLab
# Автор: Сергей Антропов
# Сайт: https://devops.org.ru
name: AnsibleLab CI/CD Pipeline
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
jobs:
# Стадия 1: Lint проверка
lint:
name: 🔍 Lint Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
pip install --upgrade pip
pip install ansible ansible-lint
ansible-galaxy collection install -r requirements.yml
- name: Run Ansible Lint
run: |
echo "🔍 Проверка синтаксиса ролей..."
make role lint
- name: Upload lint results
uses: actions/upload-artifact@v3
if: always()
with:
name: lint-results
path: |
.ansible-lint
lint-report.txt
# Стадия 2: Тестирование
test:
name: 🧪 Role Testing
runs-on: ubuntu-latest
needs: lint
strategy:
matrix:
preset: [minimal, default, performance]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y docker.io make
sudo systemctl start docker
sudo usermod -aG docker $USER
- name: Install Python dependencies
run: |
pip install --upgrade pip
pip install ansible ansible-lint
ansible-galaxy collection install -r requirements.yml
- name: Setup Docker builder
run: |
make docker setup-builder
- name: Build Docker images
run: |
make docker build
- name: Run Molecule tests
run: |
echo "🧪 Тестирование с preset: ${{ matrix.preset }}"
make role test ${{ matrix.preset }}
- name: Upload test results
uses: actions/upload-artifact@v3
if: always()
with:
name: test-results-${{ matrix.preset }}
path: |
molecule/default/.molecule/
test-report-${{ matrix.preset }}.txt
# Стадия 3: Деплой (только для main ветки)
deploy:
name: 🚀 Deploy Check
runs-on: ubuntu-latest
needs: [lint, test]
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
pip install --upgrade pip
pip install ansible ansible-lint
ansible-galaxy collection install -r requirements.yml
- name: Create inventory file
run: |
mkdir -p inventory
cat > inventory/hosts.ini << EOF
[test_servers]
localhost ansible_connection=local
[all:vars]
ansible_python_interpreter=python3
EOF
- name: Run deployment check
run: |
echo "🚀 Проверка развертывания (dry-run)..."
make role deploy
- name: Upload deployment results
uses: actions/upload-artifact@v3
if: always()
with:
name: deployment-results
path: |
deployment.log
deployment-report.txt
# Уведомления
notify:
name: 📢 Notifications
runs-on: ubuntu-latest
needs: [lint, test, deploy]
if: always()
steps:
- name: Notify on success
if: needs.lint.result == 'success' && needs.test.result == 'success'
run: |
echo "✅ Все проверки пройдены успешно!"
echo "🔍 Lint: ${{ needs.lint.result }}"
echo "🧪 Test: ${{ needs.test.result }}"
echo "🚀 Deploy: ${{ needs.deploy.result }}"
- name: Notify on failure
if: needs.lint.result == 'failure' || needs.test.result == 'failure'
run: |
echo "❌ Проверки не пройдены!"
echo "🔍 Lint: ${{ needs.lint.result }}"
echo "🧪 Test: ${{ needs.test.result }}"
echo "🚀 Deploy: ${{ needs.deploy.result }}"
exit 1