chore: deploy workflow with env vars #50
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy NestJS API to Firebase | |
on: | |
push: | |
branches: | |
- main | |
- dev | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
# permissions: | |
# actions: write | |
# checks: write | |
# contents: write | |
# deployments: write | |
# id-token: write # This is required for requesting the JWT | |
# issues: write | |
# packages: write | |
# pages: write | |
# pull-requests: write | |
# repository-projects: write | |
# security-events: write | |
# statuses: write | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Use Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
- name: Set correct firebase project based on git branch. | |
run: echo "FIREBASE_PROJECT=$(if [ ${{ github.ref }} == 'refs/heads/main' ]; then echo 'prod'; else echo 'dev'; fi)" >> $GITHUB_ENV | |
# - name: Set correct GCP project | |
# run: echo "GCP_PROJECT_FOR_BRANCH=$(if [ ${{ github.ref }} == 'refs/heads/main' ]; then echo 'weatherkids-f85f4'; else echo 'weatherkids-dev-67016'; fi)" >> $GITHUB_ENV | |
- name: Install dependencies. | |
run: npm ci | |
- name: Set env vars | |
run: | | |
if [ ${{ github.ref }} == 'refs/heads/main' ]; then | |
DB='mongodb+srv://gaveshalabsdev:[email protected]/weatherkids' | |
FILE='.env.prod' | |
else | |
DB='mongodb+srv://gaveshalabsdev:[email protected]/weatherkids-dev' | |
FILE='.env.dev' | |
fi | |
echo "DB_FOR_BRANCH=$DB" >> $GITHUB_ENV | |
echo "FILE_FOR_BRANCH=$FILE" >> $GITHUB_ENV | |
- name: Make envfile | |
uses: SpicyPizza/[email protected] | |
with: | |
file_name: ${{ env.FILE_FOR_BRANCH }} | |
envkey_MOBILE_CLIENT_ID: ${{ secrets.MOBILE_CLIENT_ID }} | |
envkey_WEATHERCOM_CLIENT_ID: ${{ secrets.WEATHERCOM_CLIENT_ID }} | |
envkey_MONGO_URL: ${{ env.DB_FOR_BRANCH }} | |
envkey_JWT_SECRET: secret | |
- name: Deploy to firebase cloud functions. | |
uses: w9jds/[email protected] | |
with: | |
args: deploy --only functions --project ${{ env.FIREBASE_PROJECT }} --non-interactive | |
env: | |
GCP_SA_KEY: ${{ secrets.GITHUBDEPLOY_GCP_SERVICE_ACCOUNT }} |