Skip to content

Commit

Permalink
fix: tag versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
MinhoJJang authored Aug 8, 2024
1 parent e13e349 commit 7dc09f0
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions .github/workflows/nextjs-prod-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,60 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- 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
run: |
git config user.name github-actions
git config user.email [email protected]
git tag ${{ steps.bump_version.outputs.NEW_TAG }}
git push origin ${{ steps.bump_version.outputs.NEW_TAG }}
- name: Set up environment variables
run: |
echo "NEXT_PUBLIC_SERVER_URL=${{ secrets.NEXT_PUBLIC_SERVER_URL }}" >> .env.local
echo "ACCESS_KEY=${{ secrets.ACCESS_KEY }}" >> .env.local
echo "ACCESS_SECRET_KEY=${{ secrets.ACCESS_SECRET_KEY }}" >> .env.local
- name: Set version from commit message
run: echo "VERSION=${{ github.event.head_commit.message }}" >> $GITHUB_ENV

- name: Build the Docker image
run: |
docker build -t ${{ env.IMAGE_NAME }}:${{ env.VERSION }} --platform linux/amd64 .
docker tag ${{ env.IMAGE_NAME }}:${{ env.VERSION }} ${{ env.PROJECT_NAME }}.kr-central-2.kcr.dev/${{ env.REPOSITORY_NAME }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}
docker build -t ${{ env.IMAGE_NAME }}:${{ steps.bump_version.outputs.NEW_TAG }} --platform linux/amd64 .
docker tag ${{ env.IMAGE_NAME }}:${{ steps.bump_version.outputs.NEW_TAG }} ${{ env.PROJECT_NAME }}.kr-central-2.kcr.dev/${{ env.REPOSITORY_NAME }}/${{ env.IMAGE_NAME }}:${{ steps.bump_version.outputs.NEW_TAG }}
- name: Login to KCR
run: |
echo "${{ secrets.ACCESS_SECRET_KEY }}" | docker login ${{ env.PROJECT_NAME }}.kr-central-2.kcr.dev -u "${{ secrets.ACCESS_KEY }}" --password-stdin
- name: Push to KCR
run: |
docker push ${{ env.PROJECT_NAME }}.kr-central-2.kcr.dev/${{ env.REPOSITORY_NAME }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}
docker push ${{ env.PROJECT_NAME }}.kr-central-2.kcr.dev/${{ env.REPOSITORY_NAME }}/${{ env.IMAGE_NAME }}:${{ steps.bump_version.outputs.NEW_TAG }}
- name: Create Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.VERSION }}
release_name: ${{ env.VERSION }}
tag_name: ${{ steps.bump_version.outputs.NEW_TAG }}
release_name: Release ${{ steps.bump_version.outputs.NEW_TAG }}
draft: false
prerelease: false

0 comments on commit 7dc09f0

Please sign in to comment.