Skip to content

Commit

Permalink
Add CI to build and deploy web app.
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomolicari committed Jan 31, 2022
1 parent 00dace8 commit 119c271
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .github/scripts/prepare_production_deployment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
set -e

# Only:
# - Tagged commits
# - Security env variables are available.
echo "🚀 Preparing version $VERSION_TAG for deployment"

if [ -n "$VERSION_TAG" ] && [ -n "$PROD_DEPLOYMENT_HOOK_TOKEN" ] && [ -n "$PROD_DEPLOYMENT_HOOK_URL" ]
then
curl --silent --output /dev/null --write-out "%{http_code}" -X POST \
-F token="$PROD_DEPLOYMENT_HOOK_TOKEN" \
-F ref=master \
-F "variables[TRIGGER_RELEASE_COMMIT_TAG]=$VERSION_TAG" \
$PROD_DEPLOYMENT_HOOK_URL
else
echo >&2 "[ERROR] Deployment to production could not be prepared. Some Environment variables are missing"
exit 100
fi
69 changes: 69 additions & 0 deletions .github/workflows/web-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Deploy

on:
push:
branches: [master]
tags: [v*]

release:
types: [published]

jobs:
deploy:
name: Deployment
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./packages/app

steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

- name: Checkout code
uses: actions/checkout@v2

- name: Set up node
- uses: actions/setup-node@v2
with:
node-version: 16

- name: Cache yarn cache
uses: actions/cache@v2
id: cache-yarn-cache
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}

- name: Install dependencies
run: yarn install

- name: Build website
run: yarn static

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}

# Script to deploy to the dev environment
- name: 'Deploy to S3: Dev'
if: github.ref == 'refs/heads/master'
run: aws s3 sync out s3://${{ secrets.AWS_DEV_BUCKET_NAME }}/current --delete

# Script to upload release files
- name: 'Upload release build files for production'
if: startsWith(github.ref, 'refs/tags/v')
run: aws s3 sync out s3://${{ env.AWS_DEV_BUCKET_NAME }}/releases/${{ github.event.release.tag_name }} --delete

# Script to prepare production deployments
- run: bash ./.github/scripts/prepare_production_deployment.sh
if: success() && startsWith(github.ref, 'refs/tags/v')
env:
PROD_DEPLOYMENT_HOOK_TOKEN: ${{ secrets.PROD_DEPLOYMENT_HOOK_TOKEN }}
PROD_DEPLOYMENT_HOOK_URL: ${{ secrets.PROD_DEPLOYMENT_HOOK_URL }}
VERSION_TAG: ${{ github.event.release.tag_name }}

0 comments on commit 119c271

Please sign in to comment.