Skip to content

Instantly share code, notes, and snippets.

@seye2
Last active December 28, 2019 11:28
Show Gist options
  • Save seye2/627ffa15d05b3fdd1c8358f6bfac2f68 to your computer and use it in GitHub Desktop.
Save seye2/627ffa15d05b3fdd1c8358f6bfac2f68 to your computer and use it in GitHub Desktop.
Github Actions#2 branch별 S3배포하기
name: React build
on:
push: # master, develop Branch에서 push 이벤트가 일어났을 때만 실행
branches:
- master
- develop
jobs:
build:
runs-on: ubuntu-18.04
steps:
- name: Checkout source code. # 레포지토리 체크아웃
uses: actions/checkout@v1
- name: Set an Environment Variable # add an environment variable step
run: |
IFS='/' read -ra vBranch <<< "$GITHUB_REF" # 현재 workflow를 실행한 refs/heads/branch를 '/'를 기준으로 array형태로 vBranch에 저장
branch=${vBranch[2]} # vBranch array중에 2번째(branch)를 branch에 저장
echo ::set-env name=BRANCH::$branch # set-env
- name: Cache node modules # node modules 캐싱
uses: actions/cache@v1
with:
path: node_modules
key: ${{ runner.OS }}-build-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-build-
${{ runner.OS }}-
- name: Install Dependencies # 의존 파일 설치
run: npm install
- name: Build # React Build
run: npm run build
- name: Deploy # S3에 배포하기
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: |
aws s3 cp \
--recursive \
--region ap-northeast-2 \
build s3://github-actions-dh/$BRANCH # 위에서 shell script로 작성한 현재 실행 중인 branch명을 사용, 해당 branch 디렉토리로 배포
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment