Skip to content

Commit

Permalink
Add github action for S3 deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
Uxio0 committed May 23, 2023
1 parent a984c8e commit 6cc74ea
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 21 deletions.
77 changes: 56 additions & 21 deletions .github/workflows/node.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,68 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
push:
branches: [ "main" ]
branches:
- master
- develop
pull_request:
branches: [ "main" ]
release:
types: [ released ]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
node-version: [18.x]

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
- run: yarn install
- run: yarn build --if-present
- run: npx prettier --check src/
- run: npx eslint src/
# - run: yarn ci
- run: yarn test
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
- run: yarn install
- run: yarn build --if-present
- run: npx prettier --check src/
- run: npx eslint src/
# - run: yarn ci
- run: yarn test

release:
if: github.ref == 'refs/heads/master' || (github.event_name == 'release' && github.event.action == 'released')
runs-on: ubuntu-latest
needs: [build]
steps:
- uses: actions/checkout@v3
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
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 }}
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18.x
cache: 'yarn'
- name: Build React App
run: yarn install && yarn build
- name: Deploy to Staging S3 bucket
if: github.ref == 'refs/heads/master'
run: aws s3 sync ./build/ "s3://$BUCKET_NAME" --delete
env:
BUCKET_NAME: ${{ secrets.AWS_STAGING_BUCKET_NAME }}
- name: Upload release build files for production
if: (github.event_name == 'release' && github.event.action == 'released')
run: aws s3 sync ./build/ "s3://$BUCKET_NAME/releases/$VERSION" --delete
env:
BUCKET_NAME: ${{ secrets.AWS_STAGING_BUCKET_NAME }}
VERSION: ${{ github.event.release.tag_name }}
- name: Call script to prepare production deployments
if: (github.event_name == 'release' && github.event.action == 'released')
run: bash ./scripts/github/prepare_production_deployment.sh
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 }}
17 changes: 17 additions & 0 deletions scripts/github/prepare_production_deployment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

set -ev

# Only:
# - Tagged commits
# - Security env variables are available.
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 "[ERROR] Production deployment could not be prepared"
fi

0 comments on commit 6cc74ea

Please sign in to comment.