Developers Life is always need a shortcut. In my development journy I was using manual deployment of my own projects. That's very time taking and repetable work for me. Then I go through and search for the internet about CI/CD and I come to know that we can use Github action for automate our build and deploy process.
Before this I done this work in these steps manually:
- First Commit my code to github
- Then make a build in local
- Then finally run deploy command
so, By the help of Github action I skip the last two steps, I just have to only push my code to my github and rest of the work will manage by the Github Actions.
In this blog I am writing a begginer guide to start with Github action implementation in your project.
For making any github action you have to make a folder called .github
in your root directory. Inside that folder make a new folder and named it workflows
. Inside Workflows folder you can define your github action file using .yml extension
.
I make a file: .github/workflows/deploy.yml
name: Gatsby Build and Firebase Deploy
on:
push:
branches:
- main
jobs:
build_and_deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: '16.x'
- name: Install dependencies
run: |
yarn install
- name: Build Gatsby project
run: |
yarn build
- name: Deploy to Firebase Hosting
uses: w9jds/firebase-action@v1.4.0
with:
args: deploy --only hosting --token ${{ secrets.FIREBASE_TOKEN }}
This workflow will trigger whenever there is a push to the
main branch
. It checks out the code, installs the necessary dependencies, builds the Gatsby project, and then deploys the project to Firebase Hosting.
Make sure to replace ${{ secrets.FIREBASE_TOKEN }}
with your own Firebase token, which you can create in the Firebase console. You'll also need to make sure that your Firebase project is properly set up for hosting, and that the necessary Firebase CLI tools are installed.
Top comments (0)