Skip to content

Commit

Permalink
릴리즈 브랜치 생성 후 main, develop에 동기화 하는 PR이 생성되도록 해요
Browse files Browse the repository at this point in the history
  • Loading branch information
kts6056 committed Aug 27, 2024
1 parent a575944 commit 0316eaf
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 23 deletions.
38 changes: 25 additions & 13 deletions .github/actions/calculate-distribution-version/action.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
name: "Calculate Distribution Version"
description: "Calculate Next Distribution Version"
name: 'Calculate Distribution Version'
description: 'Calculate Next Distribution Version'

outputs:
next_year:
year:
description: "다음 정기배포 년도 버전"
value: ${{ steps.calc-next-version.outputs.next_year }}
next_week:
value: ${{ steps.calc-next-version.outputs.year }}
week:
description: "다음 정기배포 주차 버전"
value: ${{ steps.calc-next-version.outputs.next_week }}
next_hotfix:
value: ${{ steps.calc-next-version.outputs.week }}
hotfix:
description: "다음 정기배포 핫픽스 버전"
value: ${{ steps.calc-next-version.outputs.next_hotfix }}
value: ${{ steps.calc-next-version.outputs.hotfix }}
version_code:
description: "다음 정기배포 버전 코드"
value: ${{ steps.calc-next-version.outputs.version_code }}
version_name:
description: "다음 정기배포 버전 네임"
value: ${{ steps.calc-next-version.outputs.version_name }}


runs:
using: "composite"
Expand All @@ -20,10 +27,15 @@ runs:
shell: bash
run: |
# 다음 정기배포 버전 정보
year=$(TZ="Asia/Seoul" date -d "next week" +'%y')
week=$(TZ="Asia/Seoul" date -d "next week" +'%V')
year=$(TZ="Asia/Seoul" date +'%y')
week=$(TZ="Asia/Seoul" date +'%V')
hotfix=00
echo "next_year=$year" >> $GITHUB_OUTPUT
echo "next_week=$week" >> $GITHUB_OUTPUT
echo "next_hotfix=$hotfix" >> $GITHUB_OUTPUT
version_code="${year}${week}00"
version_name="${year}.${week}.0"
echo "year=$year" >> $GITHUB_OUTPUT
echo "week=$week" >> $GITHUB_OUTPUT
echo "hotfix=$hotfix" >> $GITHUB_OUTPUT
echo "version_code=$version_code" >> $GITHUB_OUTPUT
echo "version_name=$version_name" >> $GITHUB_OUTPUT
54 changes: 54 additions & 0 deletions .github/actions/create-pull-request-to-release/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: "Create Pull Request to Release"
description: "Create Pull Request to Release"


inputs:
branch:
description: '배포될 베이스 브랜치'
required: true
version_name:
description: '배포될 앱 버전 이름'
required: true
github_token:
description: '깃헙 토큰'
required: true

runs:
using: "composite"
steps:
- name: Determine PR type and version
shell: bash
id: pr_details
run: |
BRANCH_NAME="${{ inputs.branch }}"
if [[ "$BRANCH_NAME" =~ ^release/([0-9]+)$ ]]; then
echo "PR_TYPE=Release" >> $GITHUB_ENV
echo "VERSION=${BASH_REMATCH[1]}" >> $GITHUB_ENV
elif [[ "$BRANCH_NAME" =~ ^hotfix/([0-9]+)$ ]]; then
echo "PR_TYPE=Hotfix" >> $GITHUB_ENV
echo "VERSION=${BASH_REMATCH[1]}" >> $GITHUB_ENV
else
echo "배포는 'release/' 혹은 'hotfix/'에서 되어야 해요."
exit 1
fi
- name: Set PR title and body
shell: bash
run: |
echo "TITLE=[SYNC] : ${{ env.PR_TYPE }} ${{ inputs.version_name }}" >> $GITHUB_ENV
echo "BODY=${{ env.PR_TYPE }}를 위한 ${{ env.VERSION }} 버전 PR 입니다." >> $GITHUB_ENV
- name: Create Pull Request to main
shell: bash
env:
GH_TOKEN: ${{ inputs.github_token }}
run: |
gh pr create --draft --base "main" --head "${{ inputs.branch }}" --title "${{ env.TITLE }} to main" --body "${{ env.BODY }}" --milestone "${{ inputs.version_name }}"
- name: Create Pull Request to develop
shell: bash
env:
GH_TOKEN: ${{ inputs.github_token }}
run: |
gh pr create --draft --base "develop" --head "${{ inputs.branch }}" --title "${{ env.TITLE }} to develop" --body "${{ env.BODY }}" --milestone "${{ inputs.version_name }}"
36 changes: 26 additions & 10 deletions .github/workflows/create-release-branch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ env:

permissions:
contents: write
pull-requests: write

jobs:
create-release-branch:
Expand All @@ -23,24 +24,39 @@ jobs:
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- name: Calculate Release Version
id: calculate-distribution-version
uses: ./.github/actions/calculate-distribution-version

- name: Check Release Branch
run: |
echo "원격 브랜치 중 '${{ env.BRANCH_PREFIX }}/*' 형태가 존재하는지 확인해요"
existing_branches=$(git ls-remote --heads origin | grep "refs/heads/${{ env.BRANCH_PREFIX }}/" || true)
if [ -n "$existing_branches" ]; then
formatted_branches=$(echo "$existing_branches" | sed 's/.*refs\/heads\///')
echo "$formatted_branches 브랜치들이 이미 존재해서 작업을 종료해요"
fi
- name: Create Release Branch
id: create-release-branch
run: |
year=$(TZ="Asia/Seoul" date -d "next week" +'%y')
week=$(TZ="Asia/Seoul" date -d "next week" +'%V')
hotfix=00
next_version="${year}${week}${hotfix}"
branch_name="${BRANCH_PREFIX}/$next_version"
branch_name="${{ env.BRANCH_PREFIX }}/${{ steps.calculate-distribution-version.outputs.version_code }}"
echo "릴리즈 브랜치 생성"
git switch -c $branch_name
git push origin $branch_name
echo "브랜치 $branch_name 생성했어요"
- name: Update App Version
uses: ./.github/actions/update-app-version
with:
year: $(TZ="Asia/Seoul" date -d "next week" +'%y')
week_no: $(TZ="Asia/Seoul" date -d "next week" +'%V')
hotfix: 00
year: ${{ steps.calculate-distribution-version.outputs.year }}
week_no: ${{ steps.calculate-distribution-version.outputs.week }}
hotfix: ${{ steps.calculate-distribution-version.outputs.hotfix }}
file: ./app-version.json

- name: Create Pull Request to Release
uses: ./.github/actions/create-pull-request-to-release
with:
branch: "${{ env.BRANCH_PREFIX }}/${{ steps.calculate-distribution-version.outputs.version_code }}"
github_token: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 0316eaf

Please sign in to comment.