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'ами
This commit is contained in:
@@ -14,11 +14,12 @@ variables:
|
||||
DOCKER_TLS_CERTDIR: ''
|
||||
|
||||
stages:
|
||||
- stage: Test
|
||||
displayName: 'Test Stage'
|
||||
# Стадия 1: Lint проверка
|
||||
- stage: Lint
|
||||
displayName: '🔍 Lint Check'
|
||||
jobs:
|
||||
- job: TestJob
|
||||
displayName: 'Run Tests'
|
||||
- job: LintJob
|
||||
displayName: 'Run Lint'
|
||||
steps:
|
||||
- task: UsePythonVersion@0
|
||||
inputs:
|
||||
@@ -27,27 +28,140 @@ stages:
|
||||
|
||||
- script: |
|
||||
pip install --upgrade pip
|
||||
pip install molecule[docker] ansible-lint
|
||||
pip install ansible ansible-lint
|
||||
ansible-galaxy collection install -r requirements.yml
|
||||
displayName: 'Install Dependencies'
|
||||
|
||||
- script: |
|
||||
ansible-lint molecule/universal/
|
||||
echo "🔍 Проверка синтаксиса ролей..."
|
||||
make role lint
|
||||
displayName: 'Run Ansible Lint'
|
||||
|
||||
- task: PublishBuildArtifacts@1
|
||||
inputs:
|
||||
pathToPublish: '.ansible-lint'
|
||||
artifactName: 'lint-results'
|
||||
condition: always()
|
||||
|
||||
# Стадия 2: Тестирование
|
||||
- stage: Test
|
||||
displayName: '🧪 Role Testing'
|
||||
dependsOn: Lint
|
||||
condition: succeeded()
|
||||
jobs:
|
||||
- job: TestJob
|
||||
displayName: 'Run Tests'
|
||||
strategy:
|
||||
matrix:
|
||||
minimal:
|
||||
preset: minimal
|
||||
default:
|
||||
preset: default
|
||||
performance:
|
||||
preset: performance
|
||||
steps:
|
||||
- task: UsePythonVersion@0
|
||||
inputs:
|
||||
versionSpec: '3.11'
|
||||
displayName: 'Use Python 3.11'
|
||||
|
||||
- script: |
|
||||
cd molecule/universal
|
||||
molecule test -s universal
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y docker.io make
|
||||
sudo systemctl start docker
|
||||
sudo usermod -aG docker $USER
|
||||
displayName: 'Install System Dependencies'
|
||||
|
||||
- script: |
|
||||
pip install --upgrade pip
|
||||
pip install ansible ansible-lint
|
||||
ansible-galaxy collection install -r requirements.yml
|
||||
displayName: 'Install Python Dependencies'
|
||||
|
||||
- script: |
|
||||
make docker setup-builder
|
||||
make docker build
|
||||
displayName: 'Setup Docker and Build Images'
|
||||
|
||||
- script: |
|
||||
echo "🧪 Тестирование с preset: $(preset)"
|
||||
make role test $(preset)
|
||||
displayName: 'Run Molecule Tests'
|
||||
env:
|
||||
PRESET: $(preset)
|
||||
|
||||
- task: PublishTestResults@2
|
||||
inputs:
|
||||
testResultsFiles: 'molecule/universal/.molecule/reports/junit.xml'
|
||||
testRunTitle: 'Molecule Test Results'
|
||||
testResultsFiles: 'molecule/default/.molecule/reports/junit.xml'
|
||||
testRunTitle: 'Molecule Test Results - $(preset)'
|
||||
condition: always()
|
||||
|
||||
- task: PublishBuildArtifacts@1
|
||||
inputs:
|
||||
pathToPublish: 'molecule/universal/.molecule'
|
||||
artifactName: 'molecule-reports'
|
||||
pathToPublish: 'molecule/default/.molecule'
|
||||
artifactName: 'test-results-$(preset)'
|
||||
condition: always()
|
||||
|
||||
# Стадия 3: Деплой (только для main ветки)
|
||||
- stage: Deploy
|
||||
displayName: '🚀 Deploy Check'
|
||||
dependsOn: [Lint, Test]
|
||||
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
|
||||
jobs:
|
||||
- job: DeployJob
|
||||
displayName: 'Check Deployment'
|
||||
steps:
|
||||
- task: UsePythonVersion@0
|
||||
inputs:
|
||||
versionSpec: '3.11'
|
||||
displayName: 'Use Python 3.11'
|
||||
|
||||
- script: |
|
||||
pip install --upgrade pip
|
||||
pip install ansible ansible-lint
|
||||
ansible-galaxy collection install -r requirements.yml
|
||||
displayName: 'Install Dependencies'
|
||||
|
||||
- script: |
|
||||
mkdir -p inventory
|
||||
cat > inventory/hosts.ini << EOF
|
||||
[test_servers]
|
||||
localhost ansible_connection=local
|
||||
|
||||
[all:vars]
|
||||
ansible_python_interpreter=python3
|
||||
EOF
|
||||
displayName: 'Create Inventory File'
|
||||
|
||||
- script: |
|
||||
echo "🚀 Проверка развертывания (dry-run)..."
|
||||
make role deploy
|
||||
displayName: 'Run Deployment Check'
|
||||
|
||||
- task: PublishBuildArtifacts@1
|
||||
inputs:
|
||||
pathToPublish: 'deployment.log'
|
||||
artifactName: 'deployment-results'
|
||||
condition: always()
|
||||
|
||||
# Уведомления
|
||||
- stage: Notify
|
||||
displayName: '📢 Notifications'
|
||||
dependsOn: [Lint, Test, Deploy]
|
||||
condition: always()
|
||||
jobs:
|
||||
- job: NotifyJob
|
||||
displayName: 'Send Notifications'
|
||||
steps:
|
||||
- script: |
|
||||
echo "🔍 Lint: $(Lint.result)"
|
||||
echo "🧪 Test: $(Test.result)"
|
||||
echo "🚀 Deploy: $(Deploy.result)"
|
||||
|
||||
if [ "$(Lint.result)" = "Succeeded" ] && [ "$(Test.result)" = "Succeeded" ]; then
|
||||
echo "✅ Все проверки пройдены успешно!"
|
||||
else
|
||||
echo "❌ Проверки не пройдены!"
|
||||
exit 1
|
||||
fi
|
||||
displayName: 'Check Results and Notify'
|
||||
|
||||
Reference in New Issue
Block a user