Development of an AI system for auto-generation of CI/CD pipelines
AI-powered CI/CD configuration generation — automatically creates GitHub Actions, GitLab CI, and Jenkins Pipeline files based on codebase analysis. The system identifies the tech stack, dependencies, and test frameworks, and generates the optimal configuration.
Codebase analysis
class ProjectAnalyzer:
def analyze(self, repo_path: str) -> ProjectProfile:
profile = ProjectProfile()
# Определение языков
file_counts = Counter()
for f in glob.glob(f"{repo_path}/**/*", recursive=True):
ext = Path(f).suffix
file_counts[ext] += 1
profile.languages = self._infer_languages(file_counts)
# Детектирование фреймворков
profile.frameworks = self._detect_frameworks(repo_path, profile.languages)
# Тест-фреймворки
profile.test_frameworks = self._detect_test_frameworks(repo_path)
# Контейнеризация
profile.has_dockerfile = Path(f"{repo_path}/Dockerfile").exists()
profile.has_docker_compose = Path(f"{repo_path}/docker-compose.yml").exists()
# CI/CD провайдер (если уже настроен)
if Path(f"{repo_path}/.github/workflows").exists():
profile.current_ci = "github_actions"
elif Path(f"{repo_path}/.gitlab-ci.yml").exists():
profile.current_ci = "gitlab_ci"
return profile
def _detect_frameworks(self, path: str, languages: list[str]) -> list[str]:
frameworks = []
if "python" in languages:
if Path(f"{path}/requirements.txt").exists():
reqs = Path(f"{path}/requirements.txt").read_text()
if "django" in reqs.lower(): frameworks.append("django")
if "fastapi" in reqs.lower(): frameworks.append("fastapi")
if "flask" in reqs.lower(): frameworks.append("flask")
if "javascript" in languages or "typescript" in languages:
if Path(f"{path}/package.json").exists():
pkg = json.loads(Path(f"{path}/package.json").read_text())
deps = {**pkg.get("dependencies", {}), **pkg.get("devDependencies", {})}
if "react" in deps: frameworks.append("react")
if "next" in deps: frameworks.append("nextjs")
return frameworks
Generating CI/CD configuration
def generate_cicd_config(profile: ProjectProfile, target_ci: str) -> str:
context = f"""Проект: {profile.languages}
Фреймворки: {profile.frameworks}
Тесты: {profile.test_frameworks}
Dockerfile: {profile.has_dockerfile}
Среды: dev/staging/prod"""
prompt = f"""Сгенерируй {target_ci} конфигурацию для проекта:
{context}
Требования:
- Тесты при каждом push
- Lint/type check
- Build Docker image при merge в main
- Deploy на staging автоматически, на prod — вручную
- Кэширование зависимостей
- Секреты через environment variables"""
return llm.generate(prompt, max_tokens=2000)
Example of generated GitHub Actions
# Типичный результат для FastAPI + pytest + Docker
name: CI/CD Pipeline
on:
push:
branches: [main, develop]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with: {python-version: "3.11"}
- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('requirements*.txt') }}
- run: pip install -r requirements.txt -r requirements-dev.txt
- run: ruff check . && mypy .
- run: pytest --cov=app --cov-report=xml
- uses: codecov/codecov-action@v4
build-and-push:
needs: test
if: github.ref == 'refs/heads/main'
steps:
- uses: docker/build-push-action@v5
with:
push: true
tags: ghcr.io/${{ github.repository }}:${{ github.sha }}
deploy-staging:
needs: build-and-push
environment: staging
steps:
- run: kubectl set image deployment/app app=ghcr.io/${{ github.repository }}:${{ github.sha }}
Iterative improvement
After the first generation, the system requests feedback on what works and what needs to be changed. LLM refines the configuration based on the comments. A change history is stored, allowing you to roll back to a previous version.
Validation of generated configurations
Before use: syntax check (yamllint, actionlint for GitHub Actions), dry run (act for local simulation of GitHub Actions), static security analysis (checkov for detecting unsafe patterns).







