CI/CD에 marimo 통합하기
PART 05 Ch05에서 marimo check를 GitHub Actions에 추가하는 기초 YAML을 작성했습니다. 이 챕터는 그것을 확장합니다. 린트(marimo check), 테스트(pytest), 그리고 필요하다면 WASM 내보내기까지 하나의 파이프라인으로 연결합니다.
기본 파이프라인 구성
PART 05의 marimo check 단계를 출발점으로, pytest를 추가합니다.
# .github/workflows/ci.ymlname: marimo CIon: push: branches: [main] pull_request: branches: [main]jobs: lint-and-test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Python 설정 uses: actions/setup-python@v5 with: python-version: "3.11" - name: 의존성 설치 run: | pip install "marimo==0.23.*" pip install pytest - name: marimo check 실행 run: | for f in notebooks/*.py; do marimo check "$f" || exit 1 done - name: pytest 실행 run: pytest tests/ -v
PART 05에서 사용한 marimo==0.23.*, python-version: "3.11", checkout@v4, setup-python@v5를 그대로 유지합니다. pytest 스텝만 추가됐습니다.
프로젝트 의존성 파일로 버전 고정
CI에서 pip install "marimo==0.23.*"처럼 직접 지정하는 것보다, 프로젝트 의존성 파일에서 버전을 관리하는 방식이 더 안정적입니다.
requirements.txt를 쓴다면 이렇습니다.
# requirements.txtmarimo==0.23.15pytest==8.3.4pandas==2.2.3
pyproject.toml을 쓴다면 이렇습니다.
# pyproject.toml
[project]
name = "my-analysis"
version = "0.1.0"
requires-python = ">=3.11"
dependencies = [
"marimo==0.23.15",
"pandas==2.2.3",
]
[project.optional-dependencies]
dev = [
"pytest==8.3.4",
]
CI YAML에서 이 파일을 참조합니다.
- name: 의존성 설치 run: pip install -r requirements.txt -r requirements-dev.txt
또는 pyproject.toml의 경우입니다.
- name: 의존성 설치 run: pip install ".[dev]"
버전을 파일 한 곳에서 관리하면 로컬 환경과 CI 환경이 동일한 버전을 씁니다. 업그레이드도 파일 수정 한 번으로 양쪽에 적용됩니다.
캐시로 설치 시간 단축
패키지 설치는 시간이 걸립니다. GitHub Actions의 pip 캐시를 활용하면 이미 설치된 패키지를 재사용합니다.
- name: pip 캐시 설정 uses: actions/cache@v4 with: path: ~/.cache/pip key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }} restore-keys: | ${{ runner.os }}-pip- - name: 의존성 설치 run: pip install -r requirements.txt
requirements.txt가 바뀌면 캐시 키가 달라져 새로 설치합니다. 파일이 같으면 캐시에서 복원합니다.
WASM 내보내기를 CD 파이프라인에 추가하기
PART 09에서 다룬 WASM 내보내기를 배포 자동화에 넣을 수 있습니다. main 브랜치에 푸시될 때만 실행하도록 분기합니다.
export-wasm: needs: lint-and-test runs-on: ubuntu-latest if: github.ref == 'refs/heads/main' && github.event_name == 'push' steps: - uses: actions/checkout@v4 - name: Python 설정 uses: actions/setup-python@v5 with: python-version: "3.11" - name: marimo 설치 run: pip install "marimo==0.23.*" - name: WASM HTML 내보내기 run: | marimo export html-wasm notebooks/dashboard.py -o dist - name: GitHub Pages 배포 uses: peaceiris/actions-gh-pages@v4 with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: dist
lint-and-test 잡이 통과한 다음에만 export-wasm이 실행됩니다. 테스트가 실패하면 배포도 멈춥니다.
PR 체크 요약
PR이 올라오면 lint-and-test 잡이 실행됩니다. marimo check가 MB002·MB003 같은 정적 오류를 잡고, pytest가 순수 함수 로직을 검증합니다. 두 단계 중 하나라도 실패하면 PR 머지 버튼이 비활성화됩니다. 두 단계 모두 통과해야 머지할 수 있습니다.
main 브랜치 머지 후에는 export-wasm이 추가로 실행됩니다.
전체 워크플로우 파일
앞에서 설명한 내용을 하나의 파일로 합칩니다.
# .github/workflows/ci.ymlname: marimo CI/CDon: push: branches: [main] pull_request: branches: [main]jobs: lint-and-test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Python 설정 uses: actions/setup-python@v5 with: python-version: "3.11" - name: pip 캐시 설정 uses: actions/cache@v4 with: path: ~/.cache/pip key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }} restore-keys: | ${{ runner.os }}-pip- - name: 의존성 설치 run: pip install -r requirements.txt - name: marimo check 실행 run: | for f in notebooks/*.py; do marimo check "$f" || exit 1 done - name: pytest 실행 run: pytest tests/ -v export-wasm: needs: lint-and-test runs-on: ubuntu-latest if: github.ref == 'refs/heads/main' && github.event_name == 'push' steps: - uses: actions/checkout@v4 - name: Python 설정 uses: actions/setup-python@v5 with: python-version: "3.11" - name: marimo 설치 run: pip install "marimo==0.23.*" - name: WASM 내보내기 run: | marimo export html-wasm notebooks/dashboard.py -o dist - name: GitHub Pages 배포 uses: peaceiris/actions-gh-pages@v4 with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: dist
WASM 내보내기와 GitHub Pages 배포는 필요한 경우에만 포함합니다. 서버 배포를 선택한 경우라면 export-wasm 잡을 제거하거나 Docker 이미지 빌드 잡으로 교체합니다.
정리
- PART 05 Ch05의
marimo checkYAML에 pytest 스텝을 추가하는 것이 기본 확장입니다. - 의존성 버전은
requirements.txt또는pyproject.toml에 고정하고, CI YAML이 그 파일을 참조합니다. - pip 캐시를 설정하면 패키지가 변경되지 않은 실행에서 설치 시간을 줄일 수 있습니다.
- WASM 내보내기와 GitHub Pages 배포는
needs: lint-and-test로 테스트가 통과한 뒤에만 실행되게 합니다. - 서버 배포, WASM 배포, 정적 HTML 배포 중 어느 것을 선택하든 린트와 테스트는 앞에 공통으로 두는 구조가 안전합니다.