[docs] readme 작성 #15
This file contains hidden or 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: Create branch from issue | |
| on: | |
| issues: | |
| types: [opened, labeled] # 이슈 생성 또는 라벨 붙을 때 작동 | |
| jobs: | |
| create-branch: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Decide branch prefix | |
| id: prefix | |
| run: | | |
| PREFIX="feat" # 기본값 | |
| for label in ${{ join(github.event.issue.labels.*.name, ' ') }}; do | |
| if [[ "$label" =~ ^(feat|docs|chore)$ ]]; then | |
| PREFIX=$label | |
| break | |
| fi | |
| done | |
| echo "prefix=$PREFIX" >> $GITHUB_OUTPUT | |
| - name: Get custom branch name from issue body | |
| id: custom | |
| run: | | |
| echo "===== ISSUE BODY =====" | |
| echo "${{ github.event.issue.body }}" | |
| CUSTOM=$(echo "${{ github.event.issue.body }}" \ | |
| | awk ' | |
| /브랜치 이름/ {getline; getline; print; exit} | |
| ' \ | |
| | xargs) | |
| if [ -n "$CUSTOM" ]; then | |
| echo "custom_name=$CUSTOM" >> $GITHUB_OUTPUT | |
| else | |
| echo "custom_name=" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Create branch | |
| run: | | |
| ISSUE_NUMBER=${{ github.event.issue.number }} | |
| PREFIX=${{ steps.prefix.outputs.prefix }} | |
| CUSTOM=${{ steps.custom.outputs.custom_name }} | |
| # 공백 제거 및 소문자 변환 | |
| CUSTOM=$(echo "$CUSTOM" \ | |
| | sed 's/^[ \t]*//;s/[ \t]*$//' \ | |
| | tr '[:upper:]' '[:lower:]' \ | |
| | tr -cs 'a-z0-9' '-') | |
| BRANCH_NAME="${PREFIX}/${CUSTOM}-#${ISSUE_NUMBER}" | |
| echo "Creating branch: $BRANCH_NAME" | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| DEFAULT_BRANCH=${{ github.event.repository.default_branch }} | |
| git fetch origin $DEFAULT_BRANCH | |
| git checkout -b "$BRANCH_NAME" origin/$DEFAULT_BRANCH | |
| git push origin "$BRANCH_NAME" | |