GitHub Actions for GenAI
Automate CI/CD pipelines for training, testing, and deploying AI models
What is GitHub Actions?
GitHub Actions is a CI/CD platform that automates build, test, and deployment pipelines directly from your GitHub repository. For GenAI projects, it enables automated model training, testing, validation, and deployment workflows triggered by code changes, schedules, or manual triggers.
Key Innovation: GitHub Actions integrates natively with GitHub repositories, providing free compute minutes, matrix builds for testing across environments, and seamless secrets management for API keys.
Free minutes/month
Marketplace Actions
Self-hosted Runners
Workflow Triggers
Core Concepts
Workflow Components
YAML config file in .github/workflows/
Set of steps running on same runner
Individual task (run command/action)
Reusable unit from Marketplace
Basic Workflow Structure
Minimal CI Workflow
# .github/workflows/ci.yml
name: CI Pipeline
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
- name: Install dependencies
run: |
pip install -r requirements.txt
- name: Run tests
run: |
pytest tests/ -v --cov=src
GenAI Workflow Examples
Model Training Pipeline
# .github/workflows/train.yml
name: Train Model
on:
workflow_dispatch: # Manual trigger
inputs:
model_type:
description: 'Model architecture'
required: true
default: 'bert-base'
epochs:
description: 'Number of epochs'
required: true
default: '10'
jobs:
train:
runs-on: self-hosted # GPU runner
steps:
- uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Download training data
run: aws s3 cp s3://my-bucket/data/ ./data/ --recursive
- name: Train model
env:
WANDB_API_KEY: ${{ secrets.WANDB_API_KEY }}
run: |
python train.py \
--model ${{ inputs.model_type }} \
--epochs ${{ inputs.epochs }} \
--output ./models/
- name: Upload model artifacts
uses: actions/upload-artifact@v4
with:
name: trained-model
path: ./models/
Deploy to Cloud Run
# .github/workflows/deploy.yml
name: Deploy to Cloud Run
on:
push:
branches: [main]
env:
PROJECT_ID: my-gcp-project
SERVICE: genai-api
REGION: us-central1
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2
- name: Build and push Docker image
run: |
gcloud builds submit \
--tag gcr.io/$PROJECT_ID/$SERVICE
- name: Deploy to Cloud Run
run: |
gcloud run deploy $SERVICE \
--image gcr.io/$PROJECT_ID/$SERVICE \
--platform managed \
--region $REGION \
--allow-unauthenticated
Workflow Triggers
π push
Trigger on commits to specific branches
on:
push:
branches: [main, dev]
π pull_request
Trigger on PR events (opened, sync)
on:
pull_request:
types: [opened, synchronize]
β° schedule
Cron-based scheduled runs
on:
schedule:
- cron: '0 6 * * 1' # Mon 6AM
π― workflow_dispatch
Manual trigger with inputs
on:
workflow_dispatch:
inputs:
environment:
type: choice
options: [dev, prod]
Secrets & Environment Variables
Security: Never hardcode API keys or credentials. Use GitHub Secrets (Settings β
Secrets β Actions) and reference them as ${{ secrets.SECRET_NAME }}
Common Secrets for GenAI
| Secret Name | Purpose |
|---|---|
| OPENAI_API_KEY | OpenAI API access |
| GCP_SA_KEY | Google Cloud Service Account JSON |
| AWS_ACCESS_KEY_ID | AWS authentication |
| WANDB_API_KEY | Weights & Biases experiment tracking |
| DOCKER_PASSWORD | Docker Hub registry access |
Matrix Builds
Run tests across multiple Python versions, operating systems, or model configurations in parallel.
jobs:
test:
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11']
os: [ubuntu-latest, macos-latest]
model: [gpt-4, claude-3]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Test with ${{ matrix.model }}
env:
MODEL_NAME: ${{ matrix.model }}
run: pytest tests/
Best Practices
Tip: Use actions/cache to cache pip packages,
model weights, and dependencies between runs for faster builds.
- Pin action versions: Use
@v4not@latestfor reproducibility - Use caching: Cache pip, npm, model downloads to speed up workflows
- Timeout limits: Set
timeout-minutesto prevent runaway jobs - Concurrency groups: Cancel redundant runs on same branch
- Reusable workflows: Extract common patterns to separate workflow files
- Self-hosted runners: Use GPU runners for model training jobs
- Split jobs: Separate test, build, deploy for parallel execution
- Environment protection: Require approvals for production deploys
Popular Actions for GenAI
actions/checkout@v4
Clone repository code
actions/setup-python@v5
Install Python with caching
docker/build-push-action@v5
Build and push Docker images
google-github-actions/auth@v2
Authenticate to Google Cloud
aws-actions/configure-aws-credentials@v4
AWS authentication
actions/upload-artifact@v4
Store build outputs
Learn More
Essential Resources
Related Topics
Test Your Knowledge
Score 8/10 or higher to pass
You need to be logged in to take this quiz.
Login to Continue