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

Feat/#92. Github Actions 자동화 코드 추가 #95

Merged
merged 7 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
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
61 changes: 61 additions & 0 deletions .github/workflows/create-hotfix-branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# 최신 Tag 기준으로 Hotfix Branch 생성
name: Create Hotfix Branch

on:
workflow_dispatch:
inputs:
artifact:
type: choice
description: 'artifact type'
required: true
default: 'Api'
options:
- 'Api'
- 'Batch'

jobs:
create-branch:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
token: ${{ secrets.MY_TOKEN }}
fetch-depth: 0

# 최신 Tag 가져오기
- name: Get latest tag
id: get-latest-tag
run: |
latest_tag=$(git describe --tags --abbrev=0 --match "${{ github.event.inputs.artifact }}-v*")
echo "LATEST_TAG=$latest_tag" >> $GITHUB_OUTPUT

# Hotfix 용 버전 생성
- name: Create new hotfix version
id: create-new-version
run: |
tag=${{ steps.get-latest-tag.outputs.LATEST_TAG }}

IFS='+' read -ra version_parts <<< "$tag"
version=${version_parts[0]}
fix_number=${version_parts[1]}

# 픽스넘버가 비어 있는 경우 0으로 설정
if [ -z "$fix_number" ]; then
fix_number=0
fi

# 픽스넘버 증가
fix_number=$((fix_number + 1))

# hotfix 버전
new_version="${version}+${fix_number}"
echo "NEW_VERSION=$new_version" >> $GITHUB_OUTPUT

# tag 기반 Hotfix Branch 생성
- name: Create and push hotfix branch
run: |
tag=${{ steps.get-latest-tag.outputs.LATEST_TAG }}

git checkout -b hotfix/${{ steps.create-new-version.outputs.NEW_VERSION }} tags/$tag
git push origin hotfix/${{ steps.create-new-version.outputs.NEW_VERSION }}
69 changes: 69 additions & 0 deletions .github/workflows/create-release-branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# 새로운 버전의 Release Branch 생성
name: Create Release Branch

on:
workflow_dispatch:
inputs:
artifact:
type: choice
description: 'artifact type'
required: true
default: 'Api'
options:
- 'Api'
- 'Batch'
version-up:
type: choice
description: 'version up type'
required: true
default: 'patch'
options:
- 'major'
- 'minor'
- 'patch'

jobs:
create-branch:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
token: ${{ secrets.MY_TOKEN }}
fetch-depth: 0

# 최신 Tag 가져오기
- name: Get latest tag
id: get-latest-tag
run: |
latest_tag=$(git describe --tags --abbrev=0 --match "${{ github.event.inputs.artifact }}-v*" 2>/dev/null || echo "")
echo "LATEST_TAG=$latest_tag" >> $GITHUB_OUTPUT

# 최신 Tag 기준으로 버전 업데이트
- name: Version up
id: version-up
run: |
latest_tag=${{ steps.get-latest-tag.outputs.LATEST_TAG }}

if [ -z "$latest_tag" ]; then
new_version="1.0.0"
else
version=$(echo $latest_tag | egrep -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}')

if [ ${{ github.event.inputs.version-up }} == "major" ]; then
new_version=$(echo $version | awk -F'.' '{printf "%d.%d.%d", $1 + 1, 0, 0}')
elif [ ${{ github.event.inputs.version-up }} == "minor" ]; then
new_version=$(echo $version | awk -F'.' '{printf "%d.%d.%d", $1, $2 + 1, 0}')
else
new_version=$(echo $version | awk -F'.' '{printf "%d.%d.%d", $1, $2, $3 + 1}')
fi
fi

echo "NEW_VERSION=$new_version" >> $GITHUB_OUTPUT

# 새 버전 Release Branch 생성
- name: Create and push release branch
run: |
new_version=${{ steps.version-up.outputs.NEW_VERSION }}
git checkout -b release/${{ github.event.inputs.artifact}}-v$new_version
git push origin release/${{ github.event.inputs.artifact}}-v$new_version
64 changes: 64 additions & 0 deletions .github/workflows/deploy-dev-api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# API - Dev Server에 배포
name: API - Deploy Development Environment

on:
create:
push:
branches:
- release/Api-v*
- hotfix/Api-v*

jobs:
check-branch:
# Branch 이름 가져오기
if: ${{ github.event_name != 'create' || github.ref_type != 'tag' }}
runs-on: ubuntu-latest
outputs:
current_branch: ${{ steps.branch-name.outputs.current_branch }}
steps:
- name: Get branch name
id: branch-name
uses: tj-actions/branch-names@v8

deploy-development-environment:
needs: check-branch
# release, hotfix 일때만 실행
if: startsWith(${{ needs.check-branch.outputs.current_branch}}, 'release/Api-v') || startsWith(${{ needs.check-branch.outputs.current_branch}}, 'hotfix/Api-v')
runs-on: 'ubuntu-latest'
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
token: ${{ secrets.MY_TOKEN }}
submodules: true

# JDK 환경 셋팅
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '17'
cache: gradle

# Gradle Permission
- name: Grant execute permission for gradlew
run: chmod +x gradlew

# Build
- name: Gradle build
run: |
./gradlew globalCopyConfig
./gradlew adevspoon-api:build -x test

# AWS Config
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-region: ${{ env.AWS_REGION }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

# Deploy to Lambda
- name: Deploy to lambda
run: |
# aws lambda update-function-code --function-name adevspoon-api --zip-file fileb://adevspoon-api/build/libs/adevspoon-api-*.jar
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: API Server Deploy to Production
name: API - Deploy Production Environment
on:
push:
branches:
- main
tags:
- Api-v*
workflow_dispatch:

env:
Expand All @@ -17,9 +17,9 @@ jobs:
steps:
# Repo checkout
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
token: ${{ secrets.TOKEN_GITHUB }}
token: ${{ secrets.MY_TOKEN }}
submodules: true

# JDK 환경 셋팅
Expand All @@ -35,7 +35,7 @@ jobs:
run: chmod +x gradlew

# Build App
- name: Gradle Build
- name: Gradle build
run: |
./gradlew globalCopyConfig
./gradlew adevspoon-api:build -x test
Expand All @@ -49,15 +49,15 @@ jobs:
aws-region: ${{ env.AWS_REGION }}

# S3 Upload
- name: S3 Upload
- name: S3 upload
run: |
aws deploy push \
--application-name ${{ env.CODE_DEPLOY_APPLICATION_NAME }} \
--ignore-hidden-files \
--s3-location s3://$S3_BUCKET_NAME/$GITHUB_SHA.zip \
--source ./adevspoon-api

# Code Deploy 실행 (블루-그린 배포)
# Code Deploy 실행 (블루/그린 무중단 배포)
- name: CodeDeploy - Blue-Green Deployment
run: |
aws deploy create-deployment \
Expand Down
47 changes: 47 additions & 0 deletions .github/workflows/tagging-and-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Tag 생성 및 Release 생성
name: Versioning - Tagging and Release

on:
pull_request:
branches:
- develop
types:
- closed

jobs:
check-branch:
runs-on: ubuntu-latest
outputs:
current_branch: ${{ steps.branch-name.outputs.current_branch }}
steps:
- name: Get branch names
id: branch-name
uses: tj-actions/branch-names@v8

# Release 또는 Hotfix 브랜치가 merge 될때 실행
tagging-and-release:
needs: check-branch
runs-on: 'ubuntu-latest'
if: github.event.pull_request.merged == true && (startsWith(${{ needs.check-branch.outputs.current_branch }}, 'release/') || startsWith(${{ needs.check-branch.outputs.current_branch }}, 'hotfix/'))
steps:
- name: Get tag
id: get-tag
run: |
branch=${{ needs.check-branch.outputs.current_branch }}
new_tag="${branch#release/}"
new_tag="${new_tag#hotfix/}"
echo "NEW_TAG=$new_tag" >> $GITHUB_OUTPUT

- name: Check tag
run: |
echo ${{ steps.get-tag.outputs.NEW_TAG }}

- name: Create Release & Tag
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.MY_TOKEN }}
with:
tag_name: ${{ steps.get-tag.outputs.NEW_TAG }}
release_name: ${{ steps.get-tag.outputs.NEW_TAG }}
body: |
${{ github.event.pull_request.body }}
Loading
Loading