Node.js: Configure the GitHub Actions workflow

This documentation is part of the Deploy with GitHub Actions guide. You can view the complete guide here: Learn how to deploy your Node.js code using GitHub Actions.

👋 Welcome to the Stackhero documentation!

Stackhero offers a ready-to-use Node.js cloud solution designed to help you move faster:

  • Deploy to production in seconds with a simple git push. No additional tools or manual configuration needed.
  • Use your own domain and take advantage of automatic HTTPS certificate setup, keeping your application secure with no extra steps.
  • Enjoy automatic backups, one-click updates, and predictable, transparent pricing so you can focus on building features while Stackhero manages the infrastructure.
  • Benefit from dedicated, private infrastructure for optimal performance and enhanced security.

Save time and simplify your operations: you can have your application running on Stackhero's Node.js cloud hosting in just a few minutes.

Inside your Git repository, create a .github/workflows directory if it does not already exist. Then, add a file named deploy-to-stackhero.yml:

# File: .github/workflows/deploy-to-stackhero.yml

name: Deploy to Stackhero
run-name: Deploy branch "${{ github.ref_name }}" to Stackhero

on:
  push:
    # List the branches that trigger the deployment action. Make sure there is an environment in GitHub (under "Settings" > "Environments") for each branch.
    # Then add the corresponding secret STACKHERO_SSH_PRIVATE_KEY and variable STACKHERO_ENDPOINT in that environment.
    branches: [ "production", "staging" ]

jobs:
  Deploy:
    environment: ${{ github.ref_name }}
    runs-on: ubuntu-latest
    steps:
    - uses: stackhero-io/github-actions-deploy-to-stackhero@v1
      with:
        # STACKHERO_SSH_PRIVATE_KEY and STACKHERO_ENDPOINT should be set in the respective GitHub environment.
        ssh_private_key: ${{ secrets.STACKHERO_SSH_PRIVATE_KEY }}
        endpoint: ${{ vars.STACKHERO_ENDPOINT }}

Once you have created the workflow file, you can commit your changes as follows:

git add -A .
git commit -m "Add GitHub Actions to deploy to Stackhero"

To create a production branch, run:

git checkout -b production

Then push your changes to GitHub:

git push --set-upstream origin production

This push sends your code to the production branch and triggers GitHub Actions to deploy your code to the Stackhero service. To check the deployment, open your project on GitHub and click on Actions.

GitHub Actions that deployed to productionGitHub Actions that deployed to production

That's it. Your code is now ready for automatic deployment to production via GitHub Actions.