Merge pull request #148 from SWM14-Architect/fix/question #103
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Dev branch Push Workflow | |
on: | |
push: | |
branches: | |
- dev | |
workflow_dispatch: # Run workflow(수동 실행) 기능 활성화 | |
branches: | |
- dev | |
env: | |
PYTHON_VERSION: '3.10' | |
MOVIEW_CORE_ENV: 'dev' | |
jobs: | |
test_and_deploy: | |
runs-on: ubuntu-latest | |
steps: | |
# 1. 환경 설정 | |
- name: Checkout source code | |
uses: actions/checkout@v3 | |
- name: Prepare appspec file for main branch | |
run: cp appspec-dev.yml appspec.yml | |
- name: Set up Python ${{ env.PYTHON_VERSION }} | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ env.PYTHON_VERSION }} | |
- name: Setup Python venv | |
run: python -m venv venv | |
- name: Install dependencies | |
run: ./venv/bin/python -m pip install -r requirements.txt | |
- 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_REGION }} | |
# # 2. 테스트 진행 | |
# - name: Run tests with coverage | |
# run: ./venv/bin/python -m coverage run -m unittest discover -s tests -p "test_*.py" | |
# shell: bash | |
# | |
# - name: Check test coverage | |
# id: coverage-check | |
# run: | | |
# COVERAGE=$(./venv/bin/python -m coverage report -m | grep TOTAL | awk '{print $6}' | sed 's/%//') | |
# echo "Test coverage: $COVERAGE%" | |
# echo "::set-output name=coverage::$COVERAGE" | |
# shell: bash | |
# | |
# # 3. 배포 진행 (테스트 커버리지가 60% 이상일 경우) | |
# - name: Check Test Coverage Threshold | |
# id: check-coverage-threshold | |
# run: | | |
# COVERAGE=${{ steps.coverage-check.outputs.coverage }} | |
# if (( $(echo "$COVERAGE < 60" | bc -l) )); then | |
# echo "테스트 커버리지가 부족하여 배포를 취소합니다." | |
# exit 1 | |
# fi | |
# shell: bash | |
- name: Remove venv | |
run: rm -rf venv | |
- name: Make zip file | |
run: zip -qq -r ./moview_core_dev.zip . | |
shell: bash | |
- name: Upload to S3 | |
run: aws s3 cp --region ${{ secrets.AWS_REGION }} ./moview_core_dev.zip s3://${{ secrets.DEV_S3_BUCKET_NAME }}/moview_core_dev.zip --source . | |
- name: Deploy to EC2 | |
id: deploy | |
run: | | |
DEPLOY_ID=$(aws deploy create-deployment \ | |
--application-name ${{ secrets.CODE_DEPLOY_APP_NAME }} \ | |
--deployment-config-name CodeDeployDefault.AllAtOnce \ | |
--deployment-group-name ${{ secrets.DEV_CODE_DEPLOY_GROUP_NAME }} \ | |
--s3-location bucket=${{ secrets.DEV_S3_BUCKET_NAME }},bundleType=zip,key=moview_core_dev.zip \ | |
--query "[deploymentId]" --output text) | |
echo "Deployment ID: $DEPLOY_ID" | |
echo "Monitoring deployment status..." | |
while true; do | |
DEPLOY_STATUS=$(aws deploy get-deployment --deployment-id $DEPLOY_ID --query "[deploymentInfo.status]" --output text) | |
case $DEPLOY_STATUS in | |
Created|InProgress|Pending) | |
echo "Deployment status: $DEPLOY_STATUS" | |
;; | |
Succeeded) | |
echo "Deployment completed successfully." | |
break | |
;; | |
Failed|Stopped|Error) | |
echo "Deployment failed with status: $DEPLOY_STATUS" | |
exit 1 | |
;; | |
*) | |
echo "Unknown status: $DEPLOY_STATUS" | |
exit 1 | |
;; | |
esac | |
sleep 15 | |
done | |
shell: bash |