github actions 적용예시 - Get Jupyter Notebook diff with Github Actions

2021-08-05

.

Data_engineering_TIL(20210805)

[학습자료]

“Get Jupyter Notebook diff with Github Actions” 블로그 글을 읽고 실습한 내용입니다.

URL :

1) https://dev.to/canas/get-jupyter-notebook-diff-with-github-actions-4b90

2) https://github.com/Canas/test-nbdiff-github-action

[실습목표]

git repository에 github actions - Get Jupyter Notebook diff with Github Actions 적용하기

[실습내용]

STEP 1) git repository master branch에 아래 그림과 같이 .github/workflows/nbdiff.yaml를 생성하고, repository의 Actions 메뉴에서 Generate notebook diff라는 action이 등록되었는지 확인한다.

0

  • nbdiff.yaml
name: Generate notebook diff

on: ["pull_request"]

jobs:
  check-diff:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0

      - name: Fetch target branch
        run: git fetch origin $:$

      - name: Setup Python
        uses: actions/setup-python@v1
        with:
          python-version: "3.6"

      - name: Install requirements
        run: pip3 install nbdime

      - name: Run and store diff
        run: |
          nbdiff $ --no-color > diff.log
          sed -i '1s/^/```diff\n&/' diff.log
          sed -i '$s/$/\n&```/' diff.log

      - name: Get comment body
        id: get-comment-body
        run: |
          body=$(cat diff.log)
          body="${body//'%'/'%25'}"
          body="${body//$'\n'/'%0A'}"
          body="${body//$'\r'/'%0D'}"
          echo ::set-output name=body::$body

      - name: Create comment
        uses: peter-evans/create-or-update-comment@v1
        with:
          issue-number: $
          body: $

STEP 2) my_branch라는 브랜치를 하나 생성한 다음에 아래와 같이 노트북을 생성한 다음에 노트북에 test1이라고 표시하고 푸쉬한번 해준다. 그런다음에 그 노트북에서 내용을 test2라고 수정한 다음에 아래 그림과 같이 나의 브랜치로 다시 push해준다.

00

1

STEP 3) 그런 다음에 마스터 브랜치로 pull request 요청하면 아래와 같이 git actions가 동작하는 것을 확인할 수 있다.

2

3

4

5