GitHub Action Repository: kodexa-ai/kdx-sync-action
Philosophy: Branch determines deployment. One way to do it. Zero knobs, just config.
Quick Start
Deploy to Kodexa in 4 simple steps:1. Define Branch and Tag Mappings
Createsync-config.yaml in your repository root:
2. Add Secrets
In GitHub repository settings → Secrets and variables → Actions:KODEXA_PROD_API_KEYKODEXA_STAGING_API_KEYKODEXA_DEV_API_KEY
3. Create Workflow
Create.github/workflows/deploy.yml:
4. Push and Deploy
- Push to
main→ production - Push to
feature/new-thing→ dev - Create tag
v1.0.0→ production - Branch or tag determines deployment automatically
Understanding the Action
The kdx-sync-action is a composite GitHub Action that:- Detects your environment (OS and architecture)
- Downloads kdx CLI (latest or pinned version)
- Caches the binary (faster subsequent runs)
- Auto-discovers configuration (sync-config.yaml, metadata directory)
- Runs deployment (kdx sync deploy with appropriate flags)
- Parses results (extracts statistics and sets outputs)
- Install kdx CLI manually
- Handle OS/architecture detection
- Manage binary caching
- Parse deployment output
Action Inputs
All inputs are optional:Example with Inputs
Action Outputs
The action provides deployment statistics:Using Outputs
Complete Workflow Examples
Multi-Environment Deployment
The standard pattern - branch determines everything:sync-config.yaml branch mappings:
No logic in the workflow! All routing is handled by sync-config.yaml.
Pull Request Validation with Preview
Validate changes and comment on PRs:Production with Required Approval
Require manual approval before production deployment:- Go to Settings → Environments
- Create “production” environment
- Add required reviewers
- Optional: Add wait timer
Multi-Target Deployment
Deploy to multiple organizations:Tag-Based Release Workflow
NEW in kdx CLI v0.5.0: Deploy using git tags for release-driven workflows.
- Immutable deployment references (tags don’t move like branches)
- Clear release history in git
- Rollback by creating tag from previous commit
- Integration with GitHub Releases
Manual Deployment Override
NEW in kdx CLI v0.5.0: Manual control with
--branch and --tag flags- Manual deployments without git operations
- Testing deployment mappings
- Rollback to specific version
- Deploying from CI/CD without checkout
Scheduled Synchronization
Keep environments synchronized on a schedule:Built-in Slack Notifications
Send rich deployment summaries to Slack automatically:- 🚀 Deployment status (or 🔍 for dry runs)
- Repository and branch information
- Resource counts (created, updated, unchanged)
- Direct link to the GitHub Actions run
- Create a Slack App at https://api.slack.com/apps
- Add
chat:writeOAuth scope - Install to your workspace
- Copy Bot Token (
xoxb-...) toSLACK_BOT_TOKENsecret - Get channel ID (right-click channel → Copy link → extract ID)
GitHub Job Summary
Add a deployment summary directly to the workflow run:- Resource counts (created, updated, unchanged)
- Repository, branch, commit, and actor details
- Environment breakdown (when available)
Full-Featured Deployment
Combine all notification options:Tag-Based Deployment
Deploy based on git tags instead of branches:tag_mappings in sync-config.yaml:
Manual Deployment with Parameters
Manual trigger with workflow inputs:Migration from v1 to v2
What Changed
v1 (old): Manual environment logic in workflowMigration Steps
1
Move mappings to sync-config.yaml
Create branch mappings in your configuration:
2
Add environments to config
Define environments with API key references:
3
Simplify workflow
Replace complex workflow logic:
4
Update secrets
Replace old secret names with new format:
PROD_URL+PROD_TOKEN→KODEXA_PROD_API_KEYSTAGING_URL+STAGING_TOKEN→KODEXA_STAGING_API_KEY
Key Benefits of v2
- ✅ Simpler workflows - No manual environment detection
- ✅ Configuration-driven - Logic lives in sync-config.yaml
- ✅ Less duplication - One workflow handles all branches
- ✅ Easier maintenance - Change routing in config, not workflow
- ✅ Auto-discovery - Finds sync-config.yaml automatically
Security Best Practices
1. Use GitHub Environment Secrets
Store API keys in environment-specific secrets:- Environment-specific secrets
- Required approval rules
- Wait timers
- Deployment visibility
- Complete audit trails
2. Never Hardcode Credentials
3. Require Approvals for Production
Configure environment protection rules:- Settings → Environments
- Select “production”
- Enable “Required reviewers”
- Add team members
- Optional: Add wait timer
4. Use Branch Protection
Protect critical branches:- Settings → Branches
- Add protection rule for
main - Require pull request reviews
- Require status checks to pass
- Require branch to be up to date
5. Limit Workflow Permissions
Use minimal necessary permissions:6. Validate Before Deploying
Always use dry-run on PRs:Development Workflow
Recommended Git Flow
Step-by-Step Process
1
Create feature branch
2
Make changes
3
Test locally
4
Commit and push
5
Open pull request
- GitHub automatically runs dry-run validation
- Review deployment preview in PR comments
- Request team review
6
Merge and deploy
- After approval, merge PR
- GitHub Actions automatically deploys based on branch
- Monitor workflow logs for results
Advanced: Using Manual kdx CLI
For most GitHub Actions use cases, use kdx-sync-action. Manual CLI is for local development and advanced debugging.
When to Use Manual CLI
- Local development - Testing changes before committing
- Advanced debugging - Need detailed control and output
- Custom CI systems - Not using GitHub Actions
- One-off operations - Manual syncs or migrations
Manual Installation in Workflows
If you need to use kdx CLI directly:Troubleshooting
Binary Download Failed
Issue: “Failed to download kdx from …” Solution: Specify a specific version:Branch Mapping Not Found
Issue: “No branch mapping found for branch ‘feature/xyz’” Solution 1 - Add fallback mapping:Environment Variable Not Set
Issue: “Environment variable KODEXA_PROD_API_KEY not set” Fix: Ensure secret exists and is passed to action:- Settings → Secrets and variables → Actions
- Confirm secret name matches exactly
- Check environment restrictions if using GitHub environments
Authentication Failed
Issue: “Authentication failed” or “Invalid API key” Solutions:- Verify secret value - Regenerate API key if needed
- Check key permissions - Ensure key has deployment access
- Test manually:
Deployment Validation Passed but Deployment Failed
Issue: Dry-run succeeds, but live deployment fails Common causes:- Resource dependencies don’t exist in target environment
- Insufficient API key permissions
- Environment-specific differences
Best Practices
1. Use Dry-Run on Pull Requests
Always validate before merging:2. Use GitHub Environments for Protection
Separate credentials and add approval rules:3. Add Deployment Summaries
Make results visible in workflow summaries:4. Monitor Workflows
Set up notifications for failures:5. Document Your Configuration
Add comments to sync-config.yaml:6. Version Pin for Stability
Pin kdx-version for production workflows:7. Test Branch Mappings Locally
Before committing configuration:GitHub Action Repository Resources
The kodexa-ai/kdx-sync-action repository contains additional resources:- SETUP_GUIDE.md - Detailed setup instructions
- examples/ - Complete workflow templates for common scenarios
- action.yml - Full action definition with all inputs/outputs
Next Steps
Sync Configuration
Learn about sync-config.yaml structure and manifests
Resource Deployments
Complete deployment strategies and patterns
KDX CLI
Local CLI for development and testing
GitHub Action Repository
kdx-sync-action source and documentation
