Skip to content

05: CI/CD Pipeline

Automate pack compilation, validation, and deployment in CI/CD.

  • Set up GitHub Actions for pack builds
  • Automate validation in CI
  • Deploy packs automatically
  • Handle multi-environment deployments

45 minutes

Terminal window
mkdir cicd-packs
cd cicd-packs
git init
mkdir -p prompts config packs .github/workflows
Terminal window
cat > prompts/assistant.yaml <<'EOF'
apiVersion: promptkit.altairalabs.ai/v1alpha1
kind: PromptConfig
spec:
task_type: assistant
name: AI Assistant
system_prompt: You are a helpful AI assistant.
user_template: ""
template_engine: go
parameters:
temperature: 0.7
max_tokens: 500
EOF
cat > config/arena.yaml <<'EOF'
prompts:
- ../prompts/assistant.yaml
EOF

Create GitHub Actions workflow:

Terminal window
cat > .github/workflows/build-packs.yml <<'EOF'
name: Build and Validate Packs
on:
push:
branches: [main, develop]
pull_request:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.22'
- name: Install packc
run: go install github.com/AltairaLabs/PromptKit/tools/packc@latest
- name: Compile packs
run: |
mkdir -p packs
packc compile \
--config config/arena.yaml \
--output packs/assistant.pack.json \
--id assistant
- name: Validate packs
run: packc validate packs/assistant.pack.json
- name: Upload packs
uses: actions/upload-artifact@v3
with:
name: compiled-packs
path: packs/*.pack.json
retention-days: 30
EOF
Terminal window
cat > .github/workflows/multi-env.yml <<'EOF'
name: Multi-Environment Build
on:
push:
branches:
- develop # Dev environment
- staging # Staging environment
- main # Production environment
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.22'
- name: Install packc
run: go install github.com/AltairaLabs/PromptKit/tools/packc@latest
- name: Determine environment
id: env
run: |
if [[ "$" == "refs/heads/main" ]]; then
echo "environment=prod" >> $GITHUB_OUTPUT
elif [[ "$" == "refs/heads/staging" ]]; then
echo "environment=staging" >> $GITHUB_OUTPUT
else
echo "environment=dev" >> $GITHUB_OUTPUT
fi
- name: Compile pack
run: |
mkdir -p packs/$
packc compile \
--config config/arena.yaml \
--output packs/$/assistant.pack.json \
--id assistant-$
- name: Validate pack
run: packc validate packs/$/assistant.pack.json
- name: Deploy to $
run: |
echo "Deploying to $"
# Add your deployment command here
# aws s3 cp packs/$/assistant.pack.json s3://bucket/
EOF
Terminal window
cat > .github/workflows/release.yml <<'EOF'
name: Release Packs
on:
push:
tags:
- 'v*.*.*'
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.22'
- name: Install packc
run: go install github.com/AltairaLabs/PromptKit/tools/packc@latest
- name: Get version
id: version
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: Compile production pack
run: |
mkdir -p packs/prod
packc compile \
--config config/arena.yaml \
--output packs/prod/assistant-v$.pack.json \
--id assistant
- name: Validate pack
run: packc validate packs/prod/assistant-v$.pack.json
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
files: packs/prod/*.pack.json
body: |
## Pack Release v$
Compiled production packs.
### Installation
```bash
# Download pack
curl -L https://github.com/$/releases/download/v$/assistant-v$.pack.json -o assistant.pack.json
```
EOF

Commit and push:

Terminal window
git add .
git commit -m "Add CI/CD workflows"
git remote add origin https://github.com/yourusername/cicd-packs.git
git push -u origin main

Watch the workflow run on GitHub Actions.

Update README.md:

Terminal window
cat > README.md <<'EOF'
# CI/CD Packs
![Build Status](https://github.com/yourusername/cicd-packs/workflows/Build%20and%20Validate%20Packs/badge.svg)
Automated pack compilation and deployment.
## Workflows
- **Build and Validate** - Runs on every push/PR
- **Multi-Environment** - Deploys based on branch
- **Release** - Creates versioned releases on tags
## Usage
```bash
# Development
git push origin develop
# Staging
git push origin staging
# Production
git tag v1.0.0
git push origin v1.0.0

EOF

## Step 8: Local Testing
Test workflows locally with act:
```bash
# Install act
brew install act # macOS
# or
curl https://raw.githubusercontent.com/nektos/act/master/install.sh | sudo bash
# Test build workflow
act -j build
# Test with specific event
act push -j build
  • ✅ Set up GitHub Actions workflows
  • ✅ Automated pack compilation
  • ✅ Multi-environment deployments
  • ✅ Release automation
  • ✅ Status badges
- name: Cache Go modules
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: $-go-$
strategy:
matrix:
environment: [dev, staging, prod]

Configure branch protection to require passing builds before merge.

Only deploy from specific branches:

if: github.ref == 'refs/heads/main'
jobs:
build-dev:
# ...
build-staging:
# ...
build-prod:
needs: [build-dev, build-staging] # Sequential
- name: Deploy
if: github.ref == 'refs/heads/main'
run: ./deploy.sh
environment:
name: production
# Requires manual approval in GitHub
- name: Add to PATH
run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
- name: Set permissions
run: chmod +x scripts/*.sh
- name: Show validation errors
if: failure()
run: packc validate packs/*.pack.json || true

Congratulations! You’ve completed all PackC tutorials. Continue with:

You now have:

  • Fully automated pack builds
  • Multi-environment deployments
  • Versioned releases
  • Production-ready CI/CD

Excellent work completing all tutorials! 🎉🚀