Skip to content

Workflow file for this run

name: Build and Deploy to Netlify
on:
release:
types: [published]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
environment:
name: Production
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Read old BUILD_VERSION from config.json
run: |
OLD_VERSION=$(jq -r '.BUILD_VERSION' app/config/config.json)
echo "Github ref: $GITHUB_REF"
echo "Old BUILD_VERSION: $OLD_VERSION"
- name: Update IS_PROD, IS_CANARY, and IS_LOCAL based on tag reference
run: |
CONFIG_PATH="app/config/config.json"
# Read the config.json file
CONFIG=$(<"$CONFIG_PATH")
# Set initial values for flags
IS_PROD=$(jq -r '.IS_PROD' <<< "$CONFIG")
IS_LOCAL=$(jq -r '.IS_LOCAL' <<< "$CONFIG")
IS_CANARY=$(jq -r '.IS_CANARY' <<< "$CONFIG")
echo "Current IS_PROD: $IS_PROD"
echo "Current IS_LOCAL: $IS_LOCAL"
echo "Current IS_CANARY: $IS_CANARY"
git config --global user.email "[email protected]"
git config --global user.name "Version Update Bot"
# Check if the tag contains 'master', 'main', or 'production'
if [[ "$GITHUB_REF" == *"master"* || "$GITHUB_REF" == *"main"* || "$GITHUB_REF" == *"production"* ]]; then
echo "Setting IS_PROD to true"
UPDATED_CONFIG=$(echo "$CONFIG" | jq '.IS_PROD = true')
# Check if the tag contains 'canary'
elif [[ "$GITHUB_REF" == *"canary"* ]]; then
echo "Setting IS_CANARY to true"
UPDATED_CONFIG=$(echo "$CONFIG" | jq '.IS_CANARY = true')
# Check if the tag contains 'dev' or 'development'
elif [[ "$GITHUB_REF" == *"dev"* || "$GITHUB_REF" == *"development"* ]]; then
echo "Setting IS_PROD, IS_LOCAL, and IS_CANARY to false"
UPDATED_CONFIG=$(echo "$CONFIG" | jq '.IS_PROD = false | .IS_LOCAL = false | .IS_CANARY = false')
else
echo "No matching tag found, keeping flags unchanged"
UPDATED_CONFIG="$CONFIG"
fi
# Save the updated config.json file
echo "$UPDATED_CONFIG" > "$CONFIG_PATH"
# Check if there are any changes before committing
if [[ $(git status --porcelain) ]]; then
git add "$CONFIG_PATH"
git commit -m "Update environment flags based on tag reference"
git push --force origin HEAD:$GITHUB_REF
else
echo "No changes to commit"
fi
- name: Set Prod/Canary Environment Variables 🚀
if: contains(github.ref, 'master') || contains(github.ref, 'prod') || contains(github.ref, 'production') || contains(github.ref, 'canary')
run: |
echo "Setting prod branch secrets..."
echo "REACT_APP_SENTRY_DSN=${{ secrets.PROD_REACT_APP_SENTRY_DSN }}" >> $GITHUB_ENV
echo "REACT_APP_TINY_MCE_KEY=${{ secrets.REACT_APP_TINY_MCE_KEY }}" >> $GITHUB_ENV
echo "REACT_APP_FIREBASE_API_KEY=${{ secrets.PROD_REACT_APP_FIREBASE_API_KEY }}" >> $GITHUB_ENV
echo "REACT_APP_FIREBASE_DATABASE_URL=${{ secrets.PROD_REACT_APP_FIREBASE_DATABASE_URL }}" >> $GITHUB_ENV
echo "REACT_APP_FIREBASE_STORAGE_BUCKET=${{ secrets.PROD_REACT_APP_FIREBASE_STORAGE_BUCKET }}" >> $GITHUB_ENV
echo "REACT_APP_FIREBASE_MESSAGING_SENDER_ID=${{ secrets.PROD_REACT_APP_FIREBASE_MESSAGING_SENDER_ID }}" >> $GITHUB_ENV
echo "REACT_APP_FIREBASE_APP_ID=${{ secrets.PROD_REACT_APP_FIREBASE_APP_ID }}" >> $GITHUB_ENV
echo "REACT_APP_FIREBASE_MEASUREMENT_ID=${{ secrets.PROD_REACT_APP_FIREBASE_MEASUREMENT_ID }}" >> $GITHUB_ENV
echo "REACT_APP_FIREBASE_PROJECT_ID=${{ secrets.PROD_REACT_APP_FIREBASE_PROJECT_ID }}" >> $GITHUB_ENV
echo "REACT_APP_FIREBASE_AUTH_DOMAIN=${{ secrets.PROD_REACT_APP_FIREBASE_AUTH_DOMAIN }}" >> $GITHUB_ENV
- name: Set Dev Environment Variables 🚀
if: contains(github.ref, 'dev') || contains(github.ref, 'development')
run: |
echo "Setting Development branch secrets..."
echo "Using repository secrets for $BRANCH branch..."
echo "REACT_APP_SENTRY_DSN=${{ secrets.REACT_APP_SENTRY_DSN }}" >> $GITHUB_ENV
echo "REACT_APP_TINY_MCE_KEY=${{ secrets.REACT_APP_TINY_MCE_KEY }}" >> $GITHUB_ENV
echo "REACT_APP_FIREBASE_API_KEY=${{ secrets.REACT_APP_FIREBASE_API_KEY }}" >> $GITHUB_ENV
echo "REACT_APP_FIREBASE_DATABASE_URL=${{ secrets.REACT_APP_FIREBASE_DATABASE_URL }}" >> $GITHUB_ENV
echo "REACT_APP_FIREBASE_MESSAGING_SENDER_ID=${{ secrets.REACT_APP_FIREBASE_MESSAGING_SENDER_ID }}" >> $GITHUB_ENV
echo "REACT_APP_FIREBASE_APP_ID=${{ secrets.REACT_APP_FIREBASE_APP_ID }}" >> $GITHUB_ENV
echo "REACT_APP_FIREBASE_PROJECT_ID=${{ secrets.REACT_APP_FIREBASE_PROJECT_ID }}" >> $GITHUB_ENV
echo "REACT_APP_FIREBASE_AUTH_DOMAIN=${{ secrets.REACT_APP_FIREBASE_AUTH_DOMAIN }}" >> $GITHUB_ENV
- name: Install dependencies
run: |
npm i --legacy-peer-deps
- name: Build App 🏗
run: |
make build
- name: Deploying to Prod 🚀
if: contains(github.ref, 'master') || contains(github.ref, 'prod') || contains(github.ref, 'production')
uses: data-intuitive/netlify-deploy-site@v1
with:
auth: ${{ secrets.NETLIFY_AUTH_TOKEN }}
dir: 'build'
site: ${{ secrets.NETLIFY_PROD_SITE_ID }}
prod: true
message: 'Deploying ${{ github.ref }}'
- name: Deploying to Canary 🚀
if: contains(github.ref, 'canary')
uses: data-intuitive/netlify-deploy-site@v1
with:
auth: ${{ secrets.NETLIFY_AUTH_TOKEN }}
dir: 'build'
site: ${{ secrets.NETLIFY_CANARY_SITE_ID }}
prod: true
message: 'Deploying ${{ github.ref }}'
- name: Deploying to Dev 🚀
if: contains(github.ref, 'dev') || contains(github.ref, 'development')
uses: data-intuitive/netlify-deploy-site@v1
with:
auth: ${{ secrets.NETLIFY_AUTH_TOKEN }}
dir: 'build'
site: ${{ secrets.NETLIFY_DEV_SITE_ID }}
prod: true
message: 'Deploying ${{ github.ref }}'
- name: Report status to Slack
if: always()
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
run: |
BRANCH_NAME=$(echo $GITHUB_REF | awk -F'/' '{print $3}')
BUILD_VERSION=$(jq -r '.BUILD_VERSION' < app/config/config.json)
MESSAGE="Workflow in $BRANCH_NAME with build version : $BUILD_VERSION has completed with status: *${{ job.status }}*"
STATUS_EMOJI=":white_check_mark:" # Use appropriate emoji for success status
if [[ "${{ job.status }}" != "success" ]]; then
STATUS_EMOJI=":x:" # Use appropriate emoji for failure status
fi
MESSAGE="Frontend Admin deployment workflow in $BRANCH_NAME with build number $BUILD_VERSION has completed with status: $STATUS_EMOJI ${{ job.status }}"
PAYLOAD="{\"text\": \"$MESSAGE\"}"
curl -X POST -H 'Content-type: application/json' --data "$PAYLOAD" $SLACK_WEBHOOK_URL