Automagically Deploy Gastby Site with GitHub Actions
After setting up your Gatsby website and manually deploying it to Firebase as detailed in our previous guide, it’s time to streamline your deployment process. This article will guide you through the steps to set up automatic deployment to Firebase Hosting using GitHub Actions.
May your deploys be smooth, and your build errors few. Keep automating and innovating!
Prerequisites
- A Gatsby website as detailed in Part 1
- GitHub repository for your Gatsby project
- Firebase project set up and configured
Setting Up Firebase Hosting with GitHub
-
Initialize Firebase Hosting for GitHub: In your project directory, run:
firebase init hosting:github
-
Automated Setup: The command will prompt you through setting up GitHub Actions, which includes:
- Creating a service account in Firebase with deployment permissions.
- Encrypting and uploading the service account’s JSON key to your GitHub repository as a secret.
- Writing GitHub workflow YAML configuration files to deploy to Firebase Hosting.
-
Commit and Push: Create a new branch, commit the workflow files, and push to GitHub.
-
Merge to Main: Merge the branch to your main branch.
Conclusion
With these steps, every push to your main branch will trigger an automatic build and deployment of your Gatsby site to Firebase Hosting. This setup not only saves time, it also ensures consistency in your deployment process. Now, you can focus more on development and less on manual deployment tasks.