๐ฉน ์์ ฏ ์๋ฌ ์์ #66
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: Continuous Integration | |
# ์ํฌํ๋ก์ฐ ํธ๋ฆฌ๊ฑฐ ์ค์ | |
on: | |
push: | |
branches: [main] | |
paths-ignore: | |
- '.github/**' | |
workflow_dispatch: | |
inputs: | |
version_type: | |
description: '๋ฒ์ ์ฆ๊ฐ ์ ํ' | |
required: true | |
default: 'minor' | |
type: choice | |
options: | |
- minor | |
- major | |
# ํ๊ฒฝ ๋ณ์ ์ค์ | |
env: | |
AWS_REGION: ap-northeast-2 | |
ECR_REPOSITORY: threedays-app | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
# ์ ์ฅ์ ์ฒดํฌ์์ | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
submodules: 'recursive' | |
fetch-depth: 0 | |
# JDK 21 ์ค์ | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '21' | |
distribution: 'liberica' | |
# Gradle ํจํค์ง ์บ์ฑ | |
- name: Cache Gradle packages | |
uses: actions/cache@v4 | |
with: | |
path: ~/.gradle/caches | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} | |
restore-keys: ${{ runner.os }}-gradle | |
# AWS ์๊ฒฉ ์ฆ๋ช ๊ตฌ์ฑ | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ env.AWS_REGION }} | |
# Amazon ECR ๋ก๊ทธ์ธ | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v2 | |
# ๋ฒ์ ํ๊ทธ ์์ฑ | |
- name: Generate version tag | |
id: generate-version | |
run: | | |
# ์ต์ ํ๊ทธ ๊ฐ์ ธ์ค๊ธฐ | |
latest_tag="$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")" | |
echo "์ต์ ํ๊ทธ: $latest_tag" | |
# major, minor, patch ์ถ์ถ | |
IFS='.' read -r major minor patch <<< "${latest_tag#v}" | |
# ๋ฒ์ ์ฆ๊ฐ ์ ํ ๊ฒฐ์ | |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
increment_type="${{ github.event.inputs.version_type }}" | |
else | |
increment_type="patch" | |
fi | |
# ๋ฒ์ ์ฆ๊ฐ ๋ก์ง | |
case $increment_type in | |
major) | |
new_major=$((major + 1)) | |
new_minor=0 | |
new_patch=0 | |
;; | |
minor) | |
new_major=$major | |
new_minor=$((minor + 1)) | |
new_patch=0 | |
;; | |
patch|*) | |
new_major=$major | |
new_minor=$minor | |
new_patch=$((patch + 1)) | |
;; | |
esac | |
# ์ ๋ฒ์ ํ๊ทธ ์์ฑ | |
new_version="v$new_major.$new_minor.$new_patch" | |
# ์ ๋ฒ์ ์ด ์ต์ ํ๊ทธ๋ณด๋ค ํฐ์ง ํ์ธ | |
if [ $(echo "$new_version $latest_tag" | tr ' ' '\n' | sort -V | tail -n 1) != "$new_version" ]; then | |
echo "์ค๋ฅ: ์ ๋ฒ์ ($new_version)์ด ์ต์ ํ๊ทธ($latest_tag)๋ณด๋ค ํฌ์ง ์์ต๋๋ค." | |
exit 1 | |
fi | |
# ๊ฒฐ๊ณผ ์ถ๋ ฅ | |
echo "version=$new_version" >> $GITHUB_OUTPUT | |
echo "์ ๋ฒ์ : $new_version" | |
# Amazon ECR์ ์ด๋ฏธ์ง ๋น๋ ๋ฐ ํธ์ | |
- name: Build and push image to Amazon ECR | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
VERSION_TAG: ${{ steps.generate-version.outputs.version }} | |
run: | | |
./gradlew jib \ | |
-Djib.to.image="$ECR_REGISTRY/$ECR_REPOSITORY:$VERSION_TAG" \ | |
-Djib.to.tags="latest" \ | |
-Djib.console=plain | |
# ์ด๋ฏธ์ง ์ ๋ณด ์ ์ฅ | |
- name: Save image info | |
run: | | |
echo "${{ steps.login-ecr.outputs.registry }}/$ECR_REPOSITORY:${{ steps.generate-version.outputs.version }}" > image_info.txt | |
# ์ํฐํฉํธ ์ ๋ก๋ | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: image-info | |
path: image_info.txt | |
# Git ํ๊ทธ ์์ฑ | |
- name: Create Git tag | |
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.ref == 'refs/heads/main') | |
run: | | |
git config user.name github-actions | |
git config user.email [email protected] | |
git tag ${{ steps.generate-version.outputs.version }} | |
git push origin ${{ steps.generate-version.outputs.version }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }} |