diff --git a/.github/workflows/create-pr.yaml b/.github/workflows/create-pr.yaml new file mode 100644 index 0000000..66311ce --- /dev/null +++ b/.github/workflows/create-pr.yaml @@ -0,0 +1,45 @@ +name: Auto Create or Update PR + +on: + push: + branches: + [ + feature/*, + release/*, + bugfix/*, + hotfix/*, + refactor/*, + test/*, + docs/*, + chore/*, + ] + +jobs: + auto_pr: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Create or Update PR + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # 현재 브랜치 이름 가져오기 + CURRENT_BRANCH=$(echo $GITHUB_REF | sed 's|refs/heads/||') + echo "Current branch: $CURRENT_BRANCH" + + # 기존 PR이 있는지 확인 + EXISTING_PR=$(gh pr list --head "$CURRENT_BRANCH" --json number -q ".[0].number") + + if [ -z "$EXISTING_PR" ]; then + echo "No existing PR. Creating a new one..." + gh pr create \ + --title "Auto PR for $CURRENT_BRANCH" \ + --body "This PR was automatically created for the branch $CURRENT_BRANCH." \ + --base main + else + echo "PR #$EXISTING_PR exists. Syncing with the latest changes..." + gh pr comment "$EXISTING_PR" --body "Branch updated with new changes." + fi