Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add github action script for CI/CD #1

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Orbit FE Deploy !!!

on:
push:
branches:
- main
- develop

jobs:
build:
runs-on: ubuntu-latest
container:
image: node:alpine

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

- name: Set up environment
run: |
if [ "${{ github.ref }}" == "refs/heads/develop" ]; then
cp .env.development .env.production
fi

if [ "${{ github.ref }}" == "refs/heads/main" ]; then
echo "NEXT_PUBLIC_NEWRELIC_AGENT_ID=${{ secrets.NEXT_PUBLIC_NEWRELIC_AGENT_ID_PROD }}" >> .env.production
else
echo "NEXT_PUBLIC_NEWRELIC_AGENT_ID=${{ secrets.NEXT_PUBLIC_NEWRELIC_AGENT_ID_DEV }}" >> .env.production
fi

- name: Install dependencies
run: |
yarn
yarn build

- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: out
path: out

deploy:
runs-on: ubuntu-latest
needs: build
container:
image: amazon/aws-cli

steps:
- name: Download artifacts
uses: actions/download-artifact@v2
with:
name: out

- name: Configure AWS credentials
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY_SECRET }}
run: |
echo "AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }}"
echo "AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }}"
echo "AWS_DEFAULT_REGION=ap-northeast-2"

- name: Deploy to S3
run: |
if [ "${{ github.ref }}" == "refs/heads/develop" ]; then
aws s3 sync out s3://orbit-frontend-dev/out
aws cloudfront create-invalidation --distribution-id E36LDJJOTGQG37 --paths "/*"
elif [ "${{ github.ref }}" == "refs/heads/main" ]; then
aws s3 sync out s3://orbit-frontend-main/out
aws cloudfront create-invalidation --distribution-id E2ET5M5YHBDNVO --paths "/*"
else
echo "Deployment is not supported on this branch."
fi