πŸ’ΈSave up to $132K/month in CI costs!πŸ‘‰ Try Free✨
Skip to main content
← Back to workflows

How to Use GitHub Actions for Heroku Deployment

AkhileshNS-heroku-deploy -
GitHub Action
v3.13.15
973
Contributors
Contributor - AkhileshNSContributor - olavenContributor - morrislaptop

Optimize Your CI/CD Pipeline

Get instant insights into your CI/CD performance and costs. Reduce build times by up to 45% and save on infrastructure costs.

45% Faster Builds
60% Cost Reduction
Usage
name: 'Usage of heroku-deploy GitHub Action'
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: akhileshns/heroku-[email protected]
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: "YOUR APP's NAME"
heroku_email: "YOUR EMAIL"

heroku-deploy logo

Heroku Deploy

A simple github action that dynamically deploys an app to heroku


What is Heroku Deploy Action?​

Deploying applications to Heroku using GitHub Actions can streamline our continuous deployment processes. This guide describes how to set up a GitHub Action that simplifies deploying your application to Heroku by executing shell commands via NodeJS.

How to Deploy Docker Containers to Heroku Using GitHub Actions​

Deploying Docker containers to Heroku via GitHub Actions is an efficient way to automate the deployment process. This method is especially useful when your project involves Docker environments, requiring continuous deployment directly from your GitHub repository to Heroku. Here’s a step-by-step guide to setting up the process.

- uses: akhileshns/heroku-[email protected]
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: "YOUR APP's NAME"
heroku_email: "YOUR EMAIL"
usedocker: true

How to Deploy with Custom Buildpacks on Heroku Using GitHub Actions​

Deploying applications to Heroku with custom buildpacks allows for greater flexibility and control over the build environment. Buildpacks are crucial for defining the build process for applications in various languages on Heroku. Here’s how you can configure your GitHub Actions workflow to deploy an application to Heroku using a custom buildpack.

- uses: akhileshns/heroku-[email protected]
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: "YOUR APP's NAME"
heroku_email: "YOUR EMAIL"
buildpack: "https://github.com/HashNuke/heroku-buildpack-elixir.git"

How to Deploy a Subdirectory to Heroku Using GitHub Actions​

When managing complex applications that consist of multiple parts such as a frontend and a backend, it's often necessary to deploy these components separately. If your application's backend is located in a subdirectory, GitHub Actions allows you to specify the path to the directory that you want to deploy to Heroku. This ensures that only the relevant part of your project is deployed, optimizing deployment processes and resources.

- uses: akhileshns/heroku-[email protected]
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: "YOUR APP's NAME"
heroku_email: "YOUR EMAIL"
appdir: "api"

How to Deploy a Custom Branch to Heroku Using GitHub Actions​

In some development workflows, you may want to deploy from a branch other than the main or master branch, such as a development or staging branch. GitHub Actions provides the flexibility to deploy applications from any branch to Heroku, allowing for continuous deployment across different stages of the development process.

- uses: akhileshns/heroku-[email protected]
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: "YOUR APP's NAME"
heroku_email: "YOUR EMAIL"
branch: "dev"

How to Set a Custom Stack for Your Heroku App Using GitHub Actions​

For those deploying applications that require specific runtime environments, such as Docker containers, Heroku allows you to set a custom stack for your application. If your deployment process involves Docker or other specialized setups, you might need to switch from the default Heroku stack to a different one, like the container stack. Here's how you can configure your GitHub Actions workflow to set a specific stack for your Heroku deployment.

- uses: akhileshns/heroku-[email protected] # This is the action
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: "YOUR APP's NAME" #Must be unique in Heroku
heroku_email: "YOUR EMAIL"
stack: "container"

How to Implement a Health Check in Your Heroku Deployment Using GitHub Actions​

Ensuring that your application is fully operational post-deployment is crucial, especially when automatic deployment processes are involved. To enhance the reliability of deployments on Heroku using GitHub Actions, you can implement a health check that verifies whether the application is up and running correctly after it has been deployed.

- uses: akhileshns/heroku-[email protected]
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: "YOUR APP's NAME"
heroku_email: "YOUR EMAIL"
healthcheck: "https://[YOUR APP's NAME].herokuapp.com/health"

How to Use GitHub Secrets as Environment Variables in Heroku Deployments​

When deploying applications to Heroku, you often need to handle sensitive information such as API keys or configuration details securely. Heroku itself offers a feature called config vars for this purpose. However, to maintain platform independence or to leverage GitHub's encrypted secrets for additional security, you might choose to store these sensitive details in GitHub Secrets and then pass them to your Heroku app during deployment. Here's how you can integrate GitHub Secrets into your Heroku deployments using GitHub Actions.

- uses: akhileshns/heroku-[email protected]
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: "YOUR APP's NAME"
heroku_email: "YOUR EMAIL"
env:
HD_FIREBASE_API_KEY: ${{secrets.FIREBASE_API_KEY}}
HD_RANDOM_DATA: "Hello"