-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #177 from TEAM-MONGDOL/MF-255-Next.js-WEB-CI
[chore] next.js CI Github Action 완성
- Loading branch information
Showing
4 changed files
with
152 additions
and
14 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
name: Node.js CI | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
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: 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 | ||
env: | ||
NEXT_PUBLIC_SERVER_URL: ${{ secrets.NEXT_PUBLIC_SERVER_URL }} | ||
NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }} | ||
NEXTAUTH_URL: ${{ secrets.NEXTAUTH_URL }} | ||
|
||
- 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 | ||
build-args: | | ||
NEXT_PUBLIC_SERVER_URL=${{ secrets.NEXT_PUBLIC_SERVER_URL }} | ||
NEXTAUTH_SECRET=${{ secrets.NEXTAUTH_SECRET }} | ||
NEXTAUTH_URL=${{ secrets.NEXTAUTH_URL }} | ||
- name: Create Release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: ${{ steps.create_tag.outputs.NEW_TAG }} | ||
release_name: Release ${{ steps.create_tag.outputs.NEW_TAG }} | ||
draft: false | ||
prerelease: false |
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
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