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 .hx file 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:

  1. In your GitHub repository, go to Settings > Secrets and variables > Actions
  2. Click New repository secret
  3. Name: HYPHEN_API_KEY
  4. Value: Your Hyphen API key from the Hyphen App
  5. 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:

InputRequiredDescriptionDefault
apiKeyYesYour Hyphen API key-
versionNoSpecific CLI version to installLatest
hyphen-devNoUse development environmentfalse

Example with Specific CLI Version

- name: Setup Hyphen CLI
  uses: Hyphen/setup-hx-action@v1
  with:
    apiKey: ${{ secrets.HYPHEN_API_KEY }}
    version: 0.10.1

How It Works

When you run hx deploy <deployment-policy-id> in your GitHub Actions workflow:

  1. The Hyphen CLI builds your Docker image (Hyphen Code generates a Dockerfile automatically if none exists)
  2. The image is pushed to your project's container registry (configured during setup)
  3. The application is deployed to your cloud provider according to the deployment policy configuration
  4. Build, release, and verification steps are executed

For details on the build process, including Hyphen Code's Dockerfile auto-generation, see Builds.

Next Steps