Skip to content

Commit

Permalink
Add workflow to deploy to PROD
Browse files Browse the repository at this point in the history
  • Loading branch information
TANguyen1893 authored Mar 20, 2021
1 parent 5efdcfc commit 38eb560
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/treetracker-prod-cdn-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Frontend Prod CI/CD Pipeline

on:
push:
branches:
- master
pull_request:
branches:
- master

env:
project-directory: ./

jobs:
frontend:
name: Build Frontend Project
runs-on: ubuntu-latest
if: |
!contains(github.event.head_commit.message, 'skip-ci')
steps:
- uses: actions/checkout@v2
- name: Use Node.js 12.x
uses: actions/setup-node@v1
with:
node-version: '12.x'
- name: npm clean install
run: npm ci
working-directory: ${{ env.project-directory }}
- name: run ESLint
run: npm run lint
working-directory: ${{ env.project-directory }}
# define the endpoints for PROD in github secrets
- name: build frontend project
run: ${{ secrets.PROD_APP_ENDPOINTS }} npm run build
working-directory: ${{ env.project-directory }}
- uses: actions/upload-artifact@v2
if: github.event_name == 'push' && github.repository == "Greenstand/${{ github.event.repository.name }}"
with:
name: frontend-bundle
path: build
- name: run React tests
run: npm test
working-directory: ${{ env.project-directory }}

deploy:
name: Deploy to PROD CDN
runs-on: ubuntu-latest
needs: frontend
if: |
!contains(github.event.head_commit.message, 'skip-ci') &&
github.event_name == 'push' &&
github.repository == "Greenstand/${{ github.event.repository.name }}"
steps:
- uses: actions/checkout@v2
- name: Download bundled frontend resources
uses: actions/download-artifact@v2
with:
name: frontend-bundle
path: build
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.PROD_AWS_KEY_ID }}
aws-secret-access-key: ${{ secrets.PROD_AWS_SECRET }}
aws-region: us-east-1
- name: Copy front end resources to s3 bucket
run: |
aws s3 sync build s3://${{ secrets.PROD_CDN_S3_BUCKET }} --delete
- name: Invalidate cloudfront caches
run: |
aws cloudfront create-invalidation --distribution-id ${{ secrets.PROD_CDN_DISTRIBUTION_ID }} --paths "/*"

0 comments on commit 38eb560

Please sign in to comment.