I am pretty new to CI/CD, and I am using Firebase WebHosting to host my React app with GitHub Actions. I am able to create two workflows, one for every pull request and the other for merging into development.
But the thing that I want to achieve is when I merge into my staging branch then it should be live on my staging server and when I merge into master it should be live on my production server.
Right now I am able to do only one, either I can deploy it to staging or to production. I have two seperate projects on Firebase as well (project-stg and project-prod) where I wish to deploy staging on project-stg and production on project-prod.
name: Deploy to Firebase Hosting on merge
'on':
push:
branches:
- master
jobs:
build_and_deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: npm ci && npm run build
- uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: '${{ secrets.GITHUB_TOKEN }}'
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_PROJECT_PROD }}'
channelId: live
projectId: project-prod
name: Deploy to Firebase Hosting on merge
'on':
push:
branches:
- staging
jobs:
build_and_deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: npm ci && npm run build
- uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: '${{ secrets.GITHUB_TOKEN }}'
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_PROJECT_STG }}'
channelId: live
projectId: project-stg
How can I have these two workflow in a single file, as I suppose I cannot have two firebase-hosting-merge.yml files in my .github/workflow
The filename doesn't matter. It's just the default name that Firebase creates files as. You can have two workflows that are firebase-hosting-merge-staging.yml
and firebase-hosting-merge-production.yml
.