From c9fe638b1ceb473fbbcd1a9f22bf38e510905bdd Mon Sep 17 00:00:00 2001 From: Mark McDonald Date: Mon, 22 May 2023 17:07:31 +0800 Subject: [PATCH] Add workflow for notebook compliance --- .github/workflows/notebooks.yml | 60 +++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 .github/workflows/notebooks.yml diff --git a/.github/workflows/notebooks.yml b/.github/workflows/notebooks.yml new file mode 100644 index 000000000..d2951e7e7 --- /dev/null +++ b/.github/workflows/notebooks.yml @@ -0,0 +1,60 @@ +# Notebook-related checks + +name: Notebooks + +on: + # Relevant PRs + pull_request: + paths: + - "site/en/**" + # Allow manual runs + workflow_dispatch: + +jobs: + nbfmt: + name: Notebook format + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + - name: Install tensorflow-docs + run: python3 -m pip install -U git+https://github.com/tensorflow/docs + - name: Fetch master branch + run: git fetch -u origin main:main + - name: Check notebook formatting + run: | + # Only check notebooks modified in this pull request. + readarray -t changed_notebooks < <(git diff --name-only main | grep '\.ipynb$' || true) + if [[ ${#changed_notebooks[@]} == 0 ]]; then + echo "No notebooks modified in this pull request." + exit 0 + else + echo "Check formatting with nbfmt:" + python3 -m tensorflow_docs.tools.nbfmt --test "${changed_notebooks[@]}" + fi + + nblint: + name: Notebook lint + runs-on: ubuntu-latest + steps: + - uses: actions/setup-python@v1 + - uses: actions/checkout@v2 + - name: Install tensorflow-docs + run: python3 -m pip install -U git+https://github.com/tensorflow/docs + - name: Fetch main branch + run: git fetch -u origin main:main + - name: Lint notebooks + run: | + # Only check notebooks modified in this pull request. + readarray -t changed_notebooks < <(git diff --name-only main | grep '\.ipynb$' || true) + if [[ ${#changed_notebooks[@]} == 0 ]]; then + echo "No notebooks modified in this pull request." + exit 0 + else + echo "Lint check with nblint:" + python3 -m tensorflow_docs.tools.nblint \ + --styles=google,tensorflow \ + --arg=repo:google/generative-ai-docs --arg=branch:main \ + --exclude_lint=tensorflow::button_download \ + "${changed_notebooks[@]}" + fi