코드트리는 자체적으로 GitHub 연동 기능을 제공합니다.
GitHub 연동을 하면, 지정한 레포지토리의 루트 디렉토리에 날짜별로 폴더가 생성됩니다.
하지만 위처럼 루트에 직접 폴더가 생성되기 때문에,
백준, 프로그래머스 등 다양한 플랫폼의 문제 풀이를 하나의 레포지토리에서 정리하는 사용자에게는 다소 아쉬울 수 있습니다.
이를 해결하기 위해 저는 Git Subtree를 사용해 codetree/
폴더 아래로 문제를 정리해보았습니다.
먼저 코드트리의 GitHub 연동 시 사용할 전용 레포지토리를 하나 생성합니다.
레포 생성 시
README.md
또는 초기 커밋이 꼭 있어야main
브랜치가 자동 생성됩니다.
이제 자신이 사용하는 알고리즘 레포에서, 코드트리 레포를 서브트리로 연결합니다.
# 1. 코드트리 레포를 remote 등록
git remote add codetree https://github.com/your-username/codetree-solutions.git
# 2. 원격 저장소의 내용을 가져옴
git fetch codetree
# 3. 코드트리의 main 브랜치를 codetree/ 폴더로 가져옴
git subtree add --prefix=codetree codetree main
# squash 옵션을 추가하면 외부 커밋이 하나로 압축되어 로그가 깔끔해지지만 저는 기존 커밋을 유지하기를 원하기때문에 패스
git subtree add --prefix=codetree codetree main --squash
그러면 기존 레포지토리의 구조에서 codetree 폴더가 생성됩니다.
# 1. 코드트리 최신 내용 가져오기
git fetch codetree
# 2. codetree/main 브랜치를 codetree/ 폴더에 병합
git subtree pull --prefix=codetree codetree main
name: Sync Codetree Subtree
on:
schedule:
- cron: '0 16 * * *' # 매일 KST 1시 (UTC 기준 16시)
workflow_dispatch: # 수동 실행 버튼도 추가
jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Checkout algorithm repo
uses: actions/checkout@v4
with:
fetch-depth: 0 # subtree 병합을 위해 전체 커밋 기록이 필요함
- name: Set Git config
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Add codetree remote
run: |
git remote add codetree https://github.com/your-username/codetree-solutions.git
git fetch codetree
- name: Pull codetree subtree
run: |
git subtree pull --prefix=codetree codetree main -m "chore(subtree): sync codetree"
- name: Push updated subtree
run: |
git push origin main