> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/continuous-delivery/troubleshooting-and-resources/resources/new-user/migrate-github-action-to-harness.md). Agents can also search and read this documentation through its [MCP server](https://developer.harness.io/~gitbook/mcp).

# Migrate GitHub Actions to Harness deployments

A step-by-step tutorial on how you can migrate from GitHub Actions to Harness CD.

Migrating from GitHub Actions to Harness Continuous Delivery (CD) gives you access to Harness deployment strategies and streamlined CD pipelines.

This is a step-by-step tutorial on how you can migrate from GitHub Actions to Harness CD.

## What you will learn from this topic

* How to [migrate from GitHub Actions to Harness CD](#high-level-guidance) in eleven steps.
* How to [map GitHub Actions YAML to Harness pipeline YAML](#analyzing-the-github-actions-yaml-and-mapping-it-to-harness-pipeline-yaml).
* Understand [the differences between GitHub Actions and Harness CD](#comparison) pipelines.

## Before you begin

Before you begin, make sure you have the following:

* **Harness account:** Ensure you have access to a Harness account. If not, create one.

## High-level guidance <a href="#high-level-guidance" id="high-level-guidance"></a>

### Step 1: Preparation <a href="#step-1-preparation" id="step-1-preparation"></a>

Complete the following for this step:

* Review and document your current GitHub Actions workflows and configurations.
* Identify and list all the required environment variables, secrets, and deployment scripts.

### Step 2: Harness Delegate installation <a href="#step-2-harness-delegate-installation" id="step-2-harness-delegate-installation"></a>

Complete the following for this step:

* Download and install the Harness Delegate to your Kubernetes cluster or a VM within your network.
* The delegate connects your Harness account to your infrastructure.

### Step 3: Project configuration <a href="#step-3-project-configuration" id="step-3-project-configuration"></a>

Complete the following for this step:

* In the Harness platform, navigate to **Projects** and create a new project.
* Set up your environment and infrastructure definitions in Harness. This includes specifying your Kubernetes clusters and any other necessary infrastructure.

### Step 4: Pipeline creation <a href="#step-4-pipeline-creation" id="step-4-pipeline-creation"></a>

Complete the following for this step:

* Under your project, create a new pipeline.
* Design your pipeline using the Harness visual editor, mirroring the steps from your GitHub Actions pipeline such as building, testing, and deploying.

### Step 5: Pipeline translation <a href="#step-5-pipeline-translation" id="step-5-pipeline-translation"></a>

Complete the following for this step:

* Manually translate each step of your GitHub Actions pipeline into corresponding steps in your Harness workflow.
* Harness has native steps for common tasks, and you can use shell script steps for custom actions.

### Step 6: Secrets management <a href="#step-6-secrets-management" id="step-6-secrets-management"></a>

Complete the following for this step:

* Import or add your secrets (for example, Docker Hub credentials and SSH keys) into the Harness Secrets Manager.
* Update your workflow steps to use these secrets where necessary.

### Step 7: Trigger setup <a href="#step-7-trigger-setup" id="step-7-trigger-setup"></a>

Complete the following for this step:

* Set up triggers in Harness to initiate the workflow. This can be based on different conditions like new commits to your GitHub repository.
* This replaces the event triggers you had in GitHub Actions.

### Step 8: Testing <a href="#step-8-testing" id="step-8-testing"></a>

Complete the following for this step:

* Run your new Harness workflows in a non-production environment to ensure they operate as expected.
* Debug and refine your Harness workflows as necessary.

### Step 9: Deployment <a href="#step-9-deployment" id="step-9-deployment"></a>

Complete the following for this step:

* When you are satisfied, update your deployment configurations to point to your production environment.
* Run your Harness workflows to deploy to production.

### Step 10: Monitoring and optimization <a href="#step-10-monitoring-and-optimization" id="step-10-monitoring-and-optimization"></a>

Complete the following for this step:

* Set up monitoring and alerting within Harness to stay informed about the state of your deployments.
* Use Harness Continuous Verification to automatically verify deployments and rollback when necessary.

### Step 11: Documentation and training <a href="#step-11-documentation-and-training" id="step-11-documentation-and-training"></a>

Complete the following for this step:

* Document your new Harness CD setup and train your team on the new process.
* Ensure everyone is comfortable with Harness and knows how to use it for deployments.

## Map GitHub Actions YAML to Harness pipeline YAML <a href="#analyzing-the-github-actions-yaml-and-mapping-it-to-harness-pipeline-yaml" id="analyzing-the-github-actions-yaml-and-mapping-it-to-harness-pipeline-yaml"></a>

This migration process requires a thorough understanding of both GitHub Actions and Harness CD. Use the Harness documentation, support channels, and community forums to assist with the migration.

In GitHub Actions, you create pipelines using a YAML file within your repository. In Harness, configurations are typically done via the UI, but you can export them as YAML.

The following simple example shows the differences.

**GitHub Actions:**

The following is a simple Kubernetes deployment GitHub Actions pipeline:

```yaml
name: Deploy to Kubernetes

on:
  push:
    branches:
      - main

env:
  KUBECONFIG_FILE: kubeconfig.yaml

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout code
      uses: actions/checkout@v2
      
    - name: Set up Kubectl
      uses: azure/setup-kubectl@v1
      with:
        version: '1.20.0'
        
    - name: Configure kubeconfig
      run: echo "${{ secrets.KUBECONFIG }}" > $KUBECONFIG_FILE
    
    - name: Deploy to Kubernetes
      run: |
        kubectl apply -f deployment.yaml
        kubectl rollout status deployment/my-deployment
```

**Harness CD:**

In Harness, configurations are done through the UI, API, or YAML.

The following is a simplified representation of how a Kubernetes deployment might look in YAML in Harness:

```yaml
pipeline:
  name: Kubernetes Deployment
  identifier: Kubernetes_Deployment
  projectIdentifier: <PROJECT_ID>
  orgIdentifier: <ORGANIZATION_ID>
  tags: {}
  stages:
    - stage:
        type: Deployment
        spec:
          deploymentType: Kubernetes
          service:
            serviceRef: nginx
          environment:
            environmentRef: dev
            deployToAll: false
            infrastructureDefinitions:
              - identifier: devk8s
          execution:
            steps:
              - step:
                  name: Rollout Deployment
                  identifier: rolloutDeployment
                  type: K8sRollingDeploy
                  timeout: 10m
                  spec:
                    skipDryRun: false
                    pruningEnabled: false
              - step:
                  type: K8sDelete
                  name: Clean up
                  identifier: Clean_up
                  spec:
                    deleteResources:
                      type: ReleaseName
                      spec:
                        deleteNamespace: false
                  timeout: 10m
            rollbackSteps:
              - step:
                  name: Rollback Rollout Deployment
                  identifier: rollbackRolloutDeployment
                  type: K8sRollingRollback
                  timeout: 10m
                  spec:
                    pruningEnabled: false
        failureStrategies:
          - onFailure:
              errors:
                - AllErrors
              action:
                type: StageRollback
        name: Deploy
        identifier: Deploy
        tags: {}
```

## Comparison <a href="#comparison" id="comparison"></a>

The following list compares the two approaches:

1. Triggering:
   * In GitHub Actions, the workflow is triggered by a push to the main branch, specified under `on`.
   * In Harness, similarly, the trigger is defined with an `onPush` trigger.
2. Environment setup:
   * In GitHub Actions, you need to set up kubectl and kubeconfig in the workflow.
   * In Harness, environment setup is handled outside the pipeline in the environment and infrastructure configurations.
3. Deployment:
   * In GitHub Actions, the deployment steps are defined inline using `run` and shell commands.
   * In Harness, the deployment steps are defined using built-in step types like `KubectlApply`, which abstracts away some of the lower-level details.
4. Clarity and abstraction:
   * Harness YAML is more high-level and abstracted, aimed at simplifying the deployment process.
   * GitHub Actions YAML is more verbose and requires manual setup of environment and deployment commands.
5. Configuration management:
   * In GitHub Actions, kubeconfig and other secrets are managed within the workflow file.
   * In Harness, secrets and configurations are managed centrally outside the pipeline, providing better organization and security.

The migration from GitHub Actions to Harness would involve translating detailed command-line operations into higher-level Harness pipeline steps and configuring environments and secrets within the Harness platform.

{% @harness-feedback/feedback %}
