Skip to content

Commit

Permalink
Config: test브랜치 action 수정
Browse files Browse the repository at this point in the history
- test 머지 추가
- test 풀리퀘 수정
  • Loading branch information
marinesnow34 committed Oct 23, 2023
1 parent b3c0379 commit 27e8c1e
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 29 deletions.
64 changes: 48 additions & 16 deletions .github/workflows/dev_pr.yml → .github/workflows/test_merge.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Dev Server Pull-request # Workflow 이름
on:
pull_request: #pr이벤트를 감지
branches:
- dev #dev 브랜치에 한해서
jobs: # Job 설정
name: Test Server Merge
on:
push:
branches: [ "test" ]

jobs:
build:
runs-on: ubuntu-latest
steps:
Expand All @@ -18,32 +18,64 @@ jobs: # Job 설정

- name: Set .env from secrets
run: |
echo "PORT=${{ secrets.DEV_PORT }}" > .env
echo "PORT=${{ secrets.TEST_PORT }}" > .env
echo "WDS_SOCKET_PORT=0" >> .env
echo "NODE_PATH=src/" >> .env
echo "REACT_APP_API_ROOT=${{ secrets.DEV_REACT_APP_API_ROOT }}" >> .env
echo "REACT_APP_HOME_URL=${{ secrets.DEV_REACT_APP_HOME_URL }}" >> .env
echo "REACT_APP_API_ROOT=${{ secrets.TEST_REACT_APP_API_ROOT }}" >> .env
echo "REACT_APP_HOME_URL=${{ secrets.TEST_REACT_APP_HOME_URL }}" >> .env
- name: cat env file
run: cat .env

- name: Generate build # React Build
run: npm run build

- name: Compress build # 압축
run: tar -czvf build.tar.gz build/

- name: Upload compressed build to S3 #압축 파일 올리기

- name: file copy
uses: actions/upload-artifact@v3
with:
name: build
path: build
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: file download
uses: actions/download-artifact@v3
with:
name: build
path: build
- name: Upload to Cloudflare
env:
AWS_ACCESS_KEY_ID: ${{ secrets.CF_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.CF_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: us-east-1
BUCKET_NAME: ${{ secrets.CF_BUCKET_NAME }}
ENDPOINT_URL: ${{ secrets.CF_ENDPOINT_URL }}
run: |
aws s3 cp build.tar.gz s3://$BUCKET_NAME/build.tar.gz \
aws s3 sync build s3://$BUCKET_NAME/build \
--endpoint-url $ENDPOINT_URL
- name: SSH and deploy
uses: appleboy/[email protected]
env:
BUCKET_NAME: ${{ secrets.CF_BUCKET_NAME }}
ENDPOINT_URL: ${{ secrets.CF_ENDPOINT_URL }}
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.PORT }}
timeout: 40s # 30초 기본
script: |
aws s3 sync s3://$BUCKET_NAME/build ./docker/react/build \
--endpoint-url $ENDPOINT_URL
after:
if: always() # Ensures this job always runs after 'build'
needs: deploy
runs-on: ubuntu-latest
permissions: write-all

steps:
- name: Discordbot alert # 디스코드 알림
uses: sarisia/[email protected]
with:
Expand All @@ -53,4 +85,4 @@ jobs: # Job 설정
(github.actor == 'imi21123' && '<@999337351799128115>') ||
(github.actor == 'marina-yhm' && '<@946431150614794240>') ||
(github.actor == 'hhhhyelim' && '<@1076887091427946496>') }}
if: always()
if: always()
54 changes: 41 additions & 13 deletions .github/workflows/test_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,49 @@ on:
branches: [ "test" ]

jobs:
build-and-comment:
build:
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Check branch
- name: Checkout source code. # Repo checkout
uses: actions/checkout@v3

- name: Check Node v # Node v 확인
run: node -v

- name: Install dependencies # 의존 파일 설치
run: npm install

- name: Set .env from secrets
run: |
echo "Head branch is: ${{ github.head_ref }}"
echo "Base branch is: ${{ github.base_ref }}"
if [[ "${{ github.head_ref }}" != "dev" ]]; then
echo "dev 브랜치가 아님"
exit 1
fi
echo "PORT=${{ secrets.TEST_PORT }}" > .env
echo "WDS_SOCKET_PORT=0" >> .env
echo "NODE_PATH=src/" >> .env
echo "REACT_APP_API_ROOT=${{ secrets.TEST_REACT_APP_API_ROOT }}" >> .env
echo "REACT_APP_HOME_URL=${{ secrets.TEST_REACT_APP_HOME_URL }}" >> .env
- name: cat env file
run: cat .env

- name: Generate build # React Build
run: npm run build

- name: close PR
if: failure()
after:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
- name: Discordbot alert # 디스코드 알림
uses: sarisia/[email protected]
with:
webhook: ${{ secrets.DISCORD_WEBHOOK }}
content: ${{ (github.actor == 'marinesnow34' && '<@392607023495118862>') ||
(github.actor == '1223v' && '<@368775981667844098>') ||
(github.actor == 'imi21123' && '<@999337351799128115>') ||
(github.actor == 'marina-yhm' && '<@946431150614794240>') ||
(github.actor == 'hhhhyelim' && '<@1076887091427946496>') }}
if: always()
- name: Comment on failure and close PR
if: needs.build.result == 'failure'
uses: actions/github-script@v6
with:
github-token: ${{ github.token }}
Expand All @@ -28,7 +56,7 @@ jobs:
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '브랜치 확인!!'
body: '빌드 실패'
});
github.rest.pulls.update({
Expand All @@ -39,7 +67,7 @@ jobs:
});
- name: Auto approve pull request
if: success()
if: needs.build.result == 'success'
uses: actions/github-script@v6
with:
github-token: ${{ github.token }}
Expand Down

0 comments on commit 27e8c1e

Please sign in to comment.