Skip to content

Merge pull request #1466 from culturecreates/develop #181

Merge pull request #1466 from culturecreates/develop

Merge pull request #1466 from culturecreates/develop #181

name: Production build and deploy to S3
on:
push:
branches:
- main
jobs:
trigger-cypress-tests:
uses: ./.github/workflows/run-cypress-tests.yml
with:
environment: 'production'
grep: ''
grepTags: '@essential'
CYPRESS_ADMIN_EN_EMAIL: ${{ vars.CYPRESS_ADMIN_EN_EMAIL }}
CYPRESS_ADMIN_FR_EMAIL: ${{ vars.CYPRESS_ADMIN_FR_EMAIL }}
CYPRESS_GUEST_EN_EMAIL: ${{ vars.CYPRESS_GUEST_EN_EMAIL }}
CYPRESS_GUEST_FR_EMAIL: ${{ vars.CYPRESS_GUEST_FR_EMAIL }}
secrets:
DOCKER_PAT: ${{ secrets.DOCKER_PAT }}
CYPRESS_PASSWORD: ${{ secrets.CYPRESS_PASSWORD }}
S3_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }}
S3_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }}
build-and-deploy:
env:
AWS_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }}
AWS_REGION: ca-central-1
WEBHOSTING_BUCKET_NAME: cms.footlight.io
runs-on: ubuntu-latest
container:
image: sleavely/node-awscli:14.x
steps:
- name: checkout
uses: actions/checkout@v2
- name: setup node
run: npm install
# Append additional environment variables to .env.staging
- name: Add extra env variables
run: |
echo "" >> .env.production
echo "REACT_APP_GOOGLE_MAPS_API_KEY=${{ secrets.GOOGLE_MAPS_API_KEY }}" >> .env.production
echo "REACT_APP_GOOGLE_MAPS_ID=${{ secrets.GOOGLE_MAPS_ID }}" >> .env.production
- name: build
run: npm run build:production
# Upload to S3
- name: sync s3
run: aws s3 sync ./build s3://${{env.WEBHOSTING_BUCKET_NAME}}/ --acl public-read --delete --exclude index.html
- name: set cache-control on index.html
run: aws s3 cp ./build/index.html s3://${{env.WEBHOSTING_BUCKET_NAME}}/index.html --metadata-directive REPLACE --cache-control max-age=0,s-maxage=86400 --acl public-read --content-type text/html
# Invalidate CloudFront (this action)
- name: Invalidate CloudFront
uses: chetan/invalidate-cloudfront-action@v2
env:
DISTRIBUTION: E3S97I9K4Q2UXB
PATHS: "/*"
- name: Send Email on Success
if: success()
run: |
curl -X "POST" \
'https://api.sendgrid.com/v3/mail/send' \
-H 'Authorization:Bearer ${{ secrets.SENDGRID_API_KEY }}' \
-H 'Content-Type:application/json' \
-d '{
"personalizations":[
{
"to":[
{"email":"${{ vars.SENDGRID_TO_EMAIL }}"},
{"email":"${{ vars.SUPPORT_EMAIL}}"}
]
}
],
"from":{"email":"${{ vars.SENDGRID_FROM_EMAIL }}"},
"subject":"Footlight CMS Deployment",
"content":[
{
"type":"text/html",
"value":"${{ vars.NEW_RELEASE_HTML_PAGE }}"
}
]
}'