GitHub Actions Deployment
Deploy your application using GitHub Actions and Hyphen
Automate your application deployments using GitHub Actions and the Hyphen CLI. This guide shows you how to set up CI/CD workflows that deploy to development when merging to main, and to production when creating releases.
Prerequisites
Before setting up GitHub Actions deployment, ensure you have:
- Completed the initial Hyphen setup (see Deploy Quickstart)
- Connected your cloud provider to Hyphen
- Created a container registry for your project
- Initialized your app locally with
hx init(the.hxfile should be checked into your repository) - Created deployment policies for your environments (typically separate policies for development and production)
- A Hyphen API key with appropriate permissions for deployment
A Dockerfile will be used if present, and if not, Hyphen Code will generate one automatically. See Builds for more details.
Setting up GitHub Secrets
Add your Hyphen API key to your repository's secrets:
- In your GitHub repository, go to Settings > Secrets and variables > Actions
- Click New repository secret
- Name:
HYPHEN_API_KEY - Value: Your Hyphen API key from the Hyphen App
- Click Add secret
Workflow Example
This workflow deploys to development when a PR is merged to main, and to production when a release is created.
name: Deploy Application
on:
push:
branches:
- main
release:
types: [created]
jobs:
deploy-dev:
name: Deploy to Development
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Hyphen CLI
uses: Hyphen/setup-hx-action@v1
with:
apiKey: ${{ secrets.HYPHEN_API_KEY }}
- name: Run tests
run: |
# Add your test commands here
# npm test
# pytest
echo "Running tests..."
- name: Deploy to Development
run: hx deploy <your-dev-deployment-policy-id>
deploy-prod:
name: Deploy to Production
if: github.event_name == 'release'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Hyphen CLI
uses: Hyphen/setup-hx-action@v1
with:
apiKey: ${{ secrets.HYPHEN_API_KEY }}
- name: Run tests
run: |
# Add your test commands here
# npm test
# pytest
echo "Running tests..."
- name: Deploy to Production
run: hx deploy <your-production-deployment-policy-id>Action Inputs
The Hyphen/setup-hx-action supports the following inputs:
| Input | Required | Description | Default |
|---|---|---|---|
apiKey | Yes | Your Hyphen API key | - |
version | No | Specific CLI version to install | Latest |
hyphen-dev | No | Use development environment | false |
Example with Specific CLI Version
- name: Setup Hyphen CLI
uses: Hyphen/setup-hx-action@v1
with:
apiKey: ${{ secrets.HYPHEN_API_KEY }}
version: 0.10.1How It Works
When you run hx deploy <deployment-policy-id> in your GitHub Actions workflow:
- The Hyphen CLI builds your Docker image (Hyphen Code generates a Dockerfile automatically if none exists)
- The image is pushed to your project's container registry (configured during setup)
- The application is deployed to your cloud provider according to the deployment policy configuration
- Build, release, and verification steps are executed
For details on the build process, including Hyphen Code's Dockerfile auto-generation, see Builds.
Next Steps
- Learn more about Deployment Policies
- Understand the build process including Dockerfile auto-generation
- Manage environment variables in your deployments
- Explore CLI commands
- Set up environment variables and secrets
Updated 1 day ago
