Merge pull request #264 from TEAM-MONGDOL/develop #58
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: NextJS CI | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
permissions: | |
contents: write | |
env: | |
PROJECT_NAME: dkation | |
REPOSITORY_NAME: dkation-prod-front | |
IMAGE_NAME: dkation-prod-fe | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '18' | |
cache: 'npm' | |
- name: Create .env.local file | |
run: | | |
echo "NEXT_PUBLIC_SERVER_URL=${{ secrets.NEXT_PUBLIC_SERVER_URL }}" >> .env.local | |
echo "NEXTAUTH_SECRET=${{ secrets.NEXTAUTH_SECRET }}" >> .env.local | |
echo "NEXTAUTH_URL=${{ secrets.NEXTAUTH_URL }}" >> .env.local | |
echo "NEXT_PUBLIC_KAKAO_API_KEY=${{ secrets.NEXT_PUBLIC_KAKAO_API_KEY }}" >> .env.local | |
echo "SENTRY_AUTH_TOKEN=${{ secrets.SENTRY_AUTH_TOKEN }}" >> .env.local | |
- name: Install dependencies | |
run: | | |
npm ci | |
npm install -g npm@latest | |
npm install sharp | |
- name: Lint | |
run: npm run lint | |
- name: Build Next.js app | |
run: npm run build | |
- name: Get latest tag and create new tag | |
id: create_tag | |
run: | | |
git fetch --tags | |
latest_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") | |
while true; do | |
IFS='.' read -ra ADDR <<< "${latest_tag#v}" | |
major="${ADDR[0]}" | |
minor="${ADDR[1]}" | |
patch="${ADDR[2]}" | |
new_patch=$((patch + 1)) | |
new_tag="v$major.$minor.$new_patch" | |
if git rev-parse $new_tag >/dev/null 2>&1; then | |
echo "Tag $new_tag already exists, incrementing..." | |
latest_tag=$new_tag | |
else | |
echo "NEW_TAG=$new_tag" >> $GITHUB_OUTPUT | |
break | |
fi | |
done | |
- name: Create and push new tag | |
env: | |
PAT: ${{ secrets.PAT }} | |
run: | | |
git config user.name github-actions | |
git config user.email [email protected] | |
git tag ${{ steps.create_tag.outputs.NEW_TAG }} | |
git push https://[email protected]/${{ github.repository }}.git ${{ steps.create_tag.outputs.NEW_TAG }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to KCR | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ env.PROJECT_NAME }}.kr-central-2.kcr.dev | |
username: ${{ secrets.ACCESS_KEY }} | |
password: ${{ secrets.ACCESS_SECRET_KEY }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
push: true | |
tags: | | |
${{ env.PROJECT_NAME }}.kr-central-2.kcr.dev/${{ env.REPOSITORY_NAME }}/${{ env.IMAGE_NAME }}:${{ steps.create_tag.outputs.NEW_TAG }} | |
${{ env.PROJECT_NAME }}.kr-central-2.kcr.dev/${{ env.REPOSITORY_NAME }}/${{ env.IMAGE_NAME }}:latest | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- name: Create Release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.PAT }} | |
with: | |
tag_name: ${{ steps.create_tag.outputs.NEW_TAG }} | |
release_name: Release ${{ steps.create_tag.outputs.NEW_TAG }} | |
draft: false | |
prerelease: false | |
token: ${{ secrets.PAT }} |