[chore] next.js CI Github Action 완성 #11
Workflow file for this run
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: Node.js CI | |
on: | |
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 | |
id: get_latest_tag | |
run: | | |
git fetch --tags | |
latest_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") | |
echo "LATEST_TAG=$latest_tag" >> $GITHUB_OUTPUT | |
- name: Bump version | |
id: bump_version | |
run: | | |
latest_tag=${{ steps.get_latest_tag.outputs.LATEST_TAG }} | |
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" | |
echo "NEW_TAG=$new_tag" >> $GITHUB_OUTPUT | |
- 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.bump_version.outputs.NEW_TAG }} | |
git push https://[email protected]/${{ github.repository }}.git ${{ steps.bump_version.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.bump_version.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.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ steps.bump_version.outputs.NEW_TAG }} | |
release_name: Release ${{ steps.bump_version.outputs.NEW_TAG }} | |
draft: false | |
prerelease: false |