Build and Deploy to Netlify #19
Workflow file for this run
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: 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' src/config/config.json) | |
echo "Github ref: $GITHUB_REF" | |
echo "Old BUILD_VERSION: $OLD_VERSION" | |
- name: Set Prod/Canary Environment Variables 🚀 | |
if: startsWith(github.ref, 'refs/tags/master') || startsWith(github.ref, 'refs/tags/canary') | |
run: | | |
echo "Setting prod branch secrets..." | |
echo "REACT_APP_TINY_MCE_KEY=${{ secrets.REACT_APP_TINY_MCE_KEY }}" >> $GITHUB_ENV | |
echo "REACT_APP_PROD_FIREBASE_API_KEY=${{ secrets.REACT_APP_PROD_FIREBASE_API_KEY }}" >> $GITHUB_ENV | |
- name: Set Dev Environment Variables 🚀 | |
if: startsWith(github.ref, 'refs/tags/development') | |
run: | | |
echo "Setting Development branch secrets..." | |
echo "Using repository secrets for $BRANCH branch..." | |
echo "REACT_APP_TINY_MCE_KEY=${{ secrets.REACT_APP_TINY_MCE_KEY }}" >> $GITHUB_ENV | |
echo "REACT_APP_LOCAL_FIREBASE_API_KEY=${{ secrets.REACT_APP_LOCAL_FIREBASE_API_KEY }}" >> $GITHUB_ENV | |
- name: Install dependencies | |
run: | | |
npm i --legacy-peer-deps | |
- name: Build App 🏗 | |
run: | | |
make build | |
- name: Deploying to Prod 🚀 | |
if: startsWith(github.ref, 'refs/tags/master') | |
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: startsWith(github.ref, 'refs/tags/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: startsWith(github.ref, 'refs/tags/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' < src/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="User Portal 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 | |