05: CI/CD Pipeline
Automate pack compilation, validation, and deployment in CI/CD.
Learning Objectives
Section titled “Learning Objectives”- Set up GitHub Actions for pack builds
- Automate validation in CI
- Deploy packs automatically
- Handle multi-environment deployments
Time Required
Section titled “Time Required”45 minutes
Prerequisites
Section titled “Prerequisites”- Completed Tutorial 4: Pack Management
- GitHub account
- Git repository
Step 1: Initialize Repository
Section titled “Step 1: Initialize Repository”mkdir cicd-packscd cicd-packsgit initmkdir -p prompts config packs .github/workflowsStep 2: Create Prompt and Config
Section titled “Step 2: Create Prompt and Config”cat > prompts/assistant.yaml <<'EOF'apiVersion: promptkit.altairalabs.ai/v1alpha1kind: PromptConfigspec: 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: 500EOF
cat > config/arena.yaml <<'EOF'prompts: - ../prompts/assistant.yamlEOFStep 3: Basic CI Workflow
Section titled “Step 3: Basic CI Workflow”Create GitHub Actions workflow:
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: 30EOFStep 4: Multi-Environment Workflow
Section titled “Step 4: Multi-Environment Workflow”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/EOFStep 5: Release Workflow
Section titled “Step 5: Release Workflow”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 ```EOFStep 6: Test Workflow
Section titled “Step 6: Test Workflow”Commit and push:
git add .git commit -m "Add CI/CD workflows"git remote add origin https://github.com/yourusername/cicd-packs.gitgit push -u origin mainWatch the workflow run on GitHub Actions.
Step 7: Add Status Badges
Section titled “Step 7: Add Status Badges”Update README.md:
cat > README.md <<'EOF'# CI/CD Packs

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# Developmentgit push origin develop
# Staginggit push origin staging
# Productiongit tag v1.0.0git push origin v1.0.0EOF
## Step 8: Local Testing
Test workflows locally with act:
```bash# Install actbrew install act # macOS# orcurl https://raw.githubusercontent.com/nektos/act/master/install.sh | sudo bash
# Test build workflowact -j build
# Test with specific eventact push -j buildWhat You Learned
Section titled “What You Learned”- ✅ Set up GitHub Actions workflows
- ✅ Automated pack compilation
- ✅ Multi-environment deployments
- ✅ Release automation
- ✅ Status badges
Best Practices
Section titled “Best Practices”1. Cache Dependencies
Section titled “1. Cache Dependencies”- name: Cache Go modules uses: actions/cache@v3 with: path: ~/go/pkg/mod key: $-go-$2. Matrix Builds
Section titled “2. Matrix Builds”strategy: matrix: environment: [dev, staging, prod]3. Required Status Checks
Section titled “3. Required Status Checks”Configure branch protection to require passing builds before merge.
4. Automated Deployments
Section titled “4. Automated Deployments”Only deploy from specific branches:
if: github.ref == 'refs/heads/main'Advanced Patterns
Section titled “Advanced Patterns”Parallel Builds
Section titled “Parallel Builds”jobs: build-dev: # ... build-staging: # ... build-prod: needs: [build-dev, build-staging] # SequentialConditional Steps
Section titled “Conditional Steps”- name: Deploy if: github.ref == 'refs/heads/main' run: ./deploy.shManual Approvals
Section titled “Manual Approvals”environment: name: production # Requires manual approval in GitHubTroubleshooting
Section titled “Troubleshooting”packc not found
Section titled “packc not found”- name: Add to PATH run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATHPermission denied
Section titled “Permission denied”- name: Set permissions run: chmod +x scripts/*.shValidation fails
Section titled “Validation fails”- name: Show validation errors if: failure() run: packc validate packs/*.pack.json || trueNext Steps
Section titled “Next Steps”Congratulations! You’ve completed all PackC tutorials. Continue with:
- PackC Explanation - Deep dive into pack concepts
- SDK Integration - Use packs in applications
- Arena Testing - Test prompts interactively
Summary
Section titled “Summary”You now have:
- Fully automated pack builds
- Multi-environment deployments
- Versioned releases
- Production-ready CI/CD
Excellent work completing all tutorials! 🎉🚀