Some checks failed
Ansible Testing / lint (push) Has been cancelled
Ansible Testing / test (default) (push) Has been cancelled
Ansible Testing / test (minimal) (push) Has been cancelled
Ansible Testing / test (performance) (push) Has been cancelled
Ansible Testing / deploy-check (push) Has been cancelled
173 lines
4.5 KiB
YAML
173 lines
4.5 KiB
YAML
# GitHub Actions Workflow для DevOpsLab
|
||
# Автор: Сергей Антропов
|
||
# Сайт: https://devops.org.ru
|
||
|
||
name: DevOpsLab 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
|