Update sp-tech-interview.mdx #426
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 to production' | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Setup Node.js | |
uses: actions/setup-node@v1 | |
with: | |
node-version: 14.x | |
- name: Install yarn | |
run: npm install -g yarn | |
- name: Install dependencies | |
run: yarn install --frozen-lockfile | |
- name: Type checking | |
run: yarn typecheck | |
- name: Build website | |
run: yarn build | |
- name: Upload build artifacts to GitHub | |
uses: actions/upload-artifact@v2 | |
with: | |
name: build-artifact | |
path: build | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
# Once github action supports nested composite actions (anything `uses` is a composite action) | |
# Therefore we cannot reuse the code as a separate composite action until it supports it, | |
# current the deploy logic is in this file twice because of it | |
## https://github.com/actions/runner/issues/862 | |
- uses: actions/checkout@v2 | |
- name: Configure AWS credentials for S3 sync | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }} | |
aws-region: us-west-2 | |
- name: Download build artifact from Github | |
uses: actions/download-artifact@v1 | |
with: | |
name: build-artifact | |
path: build/ | |
- name: Sync with S3 | |
shell: bash | |
run: | | |
cd build | |
aws s3 sync . "s3://${{ secrets.AWS_BUCKET_NAME }}" --delete | |
- name: Invalidate Cloudfront | |
shell: bash | |
run: | | |
export DIST_ID=$(aws cloudfront list-distributions --query "DistributionList.Items[?Aliases.Items[?@=='${{ secrets.AWS_BUCKET_NAME }}']].Id | [0]" | tr -d '"') | |
aws cloudfront create-invalidation --distribution-id ${DIST_ID} --paths "/*" |