| name | github-action |
| description | Generate GitHub Actions CI/CD workflows for Python FastAPI microservices.
Use when: (1) Setting up CI pipelines, (2) Automated testing on PR, (3) Docker image builds,
(4) Kubernetes deployments, (5) Release automation.
Creates workflows with caching, parallel jobs, and environment-based deployments.
NOT for other CI systems (Jenkins, GitLab CI, CircleCI).
|
GitHub Action Generator
Generate CI/CD workflows for OmniChat microservices.
Quick Reference
/github-action ci # CI workflow (test on PR)
/github-action cd # CD workflow (deploy on merge)
/github-action release # Release workflow
/github-action all # Complete CI/CD setup
Generated Structure
.github/
├── workflows/
│ ├── ci.yml # Test and lint on PR
│ ├── cd.yml # Build and deploy
│ └── release.yml # Version and release
└── actions/
└── setup-python/
└── action.yml # Reusable setup action
Implementation
1. CI Workflow
name: CI
on:
pull_request:
branches: [main]
push:
branches: [main]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Lint with ruff
run: |
uv pip install ruff
ruff check .
ruff format --check .
- name: Type check with mypy
run: |
uv pip install mypy
mypy .
test:
runs-on: ubuntu-latest
needs: lint
services:
postgres:
image: postgres:16
env:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: test
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
redis:
image: redis:7
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Install dependencies
run: uv sync
- name: Run tests
env:
DATABASE_URL: postgresql+asyncpg://test:test@localhost:5432/test
REDIS_URL: redis://localhost:6379
run: |
uv run pytest --cov=. --cov-report=xml -v
- name: Upload coverage
uses: codecov/codecov-action@v4
with:
files: coverage.xml
fail_ci_if_error: false
2. CD Workflow
name: CD
on:
push:
branches: [main]
paths:
- "services/**"
- ".github/workflows/cd.yml"
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
changes:
runs-on: ubuntu-latest
outputs:
services: ${{ steps.filter.outputs.changes }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
api-gateway:
- 'services/api-gateway/**'
chat-orchestrator:
- 'services/chat-orchestrator/**'
persistence:
- 'services/persistence/**'
build:
needs: changes
if: ${{ needs.changes.outputs.services != '[]' }}
runs-on: ubuntu-latest
strategy:
matrix:
service: ${{ fromJson(needs.changes.outputs.services) }}
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/${{ matrix.service }}
tags: |
type=sha,prefix=
type=raw,value=latest
- name: Build and push
uses: docker/build-push-action@v5
with:
context: services/${{ matrix.service }}
push: true
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
deploy:
needs: build
runs-on: ubuntu-latest
environment: staging
steps:
- uses: actions/checkout@v4
- name: Set up kubectl
uses: azure/setup-kubectl@v4
- name: Configure kubeconfig
run: |
echo "${{ secrets.KUBE_CONFIG }}" | base64 -d > kubeconfig
echo "KUBECONFIG=$(pwd)/kubeconfig" >> $GITHUB_ENV
- name: Deploy to Kubernetes
run: |
kubectl set image deployment/${{ matrix.service }} \
${{ matrix.service }}=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/${{ matrix.service }}:${{ github.sha }} \
-n omnichat-core
3. Release Workflow
name: Release
on:
push:
tags:
- "v*"
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate changelog
id: changelog
uses: orhun/git-cliff-action@v3
with:
config: cliff.toml
args: --latest --strip header
- name: Create Release
uses: softprops/action-gh-release@v2
with:
body: ${{ steps.changelog.outputs.content }}
draft: false
prerelease: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') }}
- name: Build and push all services
run: |
for service in services/*/; do
name=$(basename $service)
docker build -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/${name}:${{ github.ref_name }} $service
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/${name}:${{ github.ref_name }}
done
Usage
git push origin feature-branch
git checkout main && git merge feature-branch && git push
git tag v1.0.0
git push origin v1.0.0
Secrets Required
| Secret | Purpose |
|---|
GITHUB_TOKEN | Auto-provided, for GHCR |
KUBE_CONFIG | Base64 kubeconfig for deploy |
CODECOV_TOKEN | Optional, for coverage |