Ruby: Configure the GitHub Actions workflow

This documentation is part of the Deploy with GitHub Actions guide. You can view the complete guide here: How to deploy your Ruby code using GitHub Actions.

👋 Welcome to the Stackhero documentation!

Stackhero provides a ready-to-use Ruby cloud solution that delivers numerous advantages, including:

  • Deploy your application in just a few seconds with a simple git push.
  • Use your own domain name and take advantage of automatic configuration of HTTPS certificates for enhanced security.
  • Benefit from automatic backups, one-click updates, and clear, transparent, and predictable pricing.
  • Enjoy optimal performance and enhanced security thanks to a private, dedicated VM.

Save time and make your life easier: it only takes 5 minutes to try Stackhero's Ruby cloud hosting solution!

On your local machine, in your Git repository, create a folder called .github/workflows. Inside this folder, create 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 of branches that will trigger the deploy action following a git push.
    # Don't forget to create an environment corresponding to the branch name in GitHub (in "Settings"/"Environments").
    # Then add the corresponding secret "STACKHERO_SSH_PRIVATE_KEY" and variable "STACKHERO_ENDPOINT" in this 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:
        # The secret "STACKHERO_SSH_PRIVATE_KEY" and the variable "STACKHERO_ENDPOINT" should be defined in the corresponding branch environment on GitHub under "Settings"/"Environments".
        ssh_private_key: ${{ secrets.STACKHERO_SSH_PRIVATE_KEY }}
        endpoint: ${{ vars.STACKHERO_ENDPOINT }}

After creating the workflow file, you can commit your changes.

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

Next, create a production branch.

git checkout -b production

Finally, push your changes to GitHub.

git push --set-upstream origin production

This last git push will upload your code to the production branch on GitHub. GitHub Actions will then automatically start and deploy your code to your Stackhero instance.

To see your workflow in action, go to your project's GitHub page and click Actions. GitHub Actions that deployed to productionGitHub Actions that deployed to production

Congratulations, you have just set up continuous deployment to production with GitHub Actions.