From 4d777961c4a46f65d1a78b4d36c3cee15be55d25 Mon Sep 17 00:00:00 2001 From: giom Date: Mon, 30 Dec 2024 14:47:02 +0000 Subject: [PATCH 01/10] Fixing link --- gemini-2/websockets/live_api_starter.ipynb | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/gemini-2/websockets/live_api_starter.ipynb b/gemini-2/websockets/live_api_starter.ipynb index b75c75c73..97bc5f416 100644 --- a/gemini-2/websockets/live_api_starter.ipynb +++ b/gemini-2/websockets/live_api_starter.ipynb @@ -69,14 +69,12 @@ "\n", "- The [Live API - Text to Text](../Live_API_Text_to_Text.ipynb) notebook is even simpler than this, as it doesn't deal with audio.\n", "- The [Live API - Audio Streaming in Colab](./live_api_streaming_in_colab.ipynb) demonstrates streaming audio **in Colab**.
It's more _fun_ than this notebook but **not optimized for readability**.\n", - "- The [Live API Audio Video to Audio python script](./live_api_audio_video_to_audio.py) doesn't work in colab, but provides a relatively readable implementation of audio and video streaming." + "- The [Live API Audio Video to Audio python script](./live_api_starter.py) doesn't work in colab, but provides a relatively readable implementation of audio and video streaming." ] }, { "cell_type": "markdown", - "metadata": { - "id": "gnzxta_57_Ip" - }, + "metadata": {}, "source": [ "## Setup" ] @@ -451,9 +449,6 @@ }, "outputs": [ { - "metadata": { - "tags": null - }, "name": "stdout", "output_type": "stream", "text": [ @@ -479,9 +474,6 @@ "output_type": "display_data" }, { - "metadata": { - "tags": null - }, "name": "stdout", "output_type": "stream", "text": [ @@ -506,9 +498,6 @@ "output_type": "display_data" }, { - "metadata": { - "tags": null - }, "name": "stdout", "output_type": "stream", "text": [ @@ -533,9 +522,6 @@ "output_type": "display_data" }, { - "metadata": { - "tags": null - }, "name": "stdout", "output_type": "stream", "text": [ @@ -560,9 +546,6 @@ "output_type": "display_data" }, { - "metadata": { - "tags": null - }, "name": "stdout", "output_type": "stream", "text": [ From b53e78c9d357da7dc07902e0a4d3f1b11dfab479 Mon Sep 17 00:00:00 2001 From: giom Date: Mon, 30 Dec 2024 15:03:02 +0000 Subject: [PATCH 02/10] test: auto-formatting notebooks. --- .github/workflows/notebooks.yaml | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/.github/workflows/notebooks.yaml b/.github/workflows/notebooks.yaml index f42843f9b..1e94aa813 100644 --- a/.github/workflows/notebooks.yaml +++ b/.github/workflows/notebooks.yaml @@ -17,12 +17,15 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + with: + # Check out the pull request branch + ref: ${{ github.event.pull_request.head.ref }} - uses: actions/setup-python@v4 - 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: Check notebook formatting + - name: Format notebooks run: | if [ "${{ github.event_name }}" == "pull_request" ]; then # Only check notebooks modified in this pull request @@ -33,17 +36,25 @@ jobs: fi 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[@]}" + echo "Formatting notebooks with nbfmt:" + python3 -m tensorflow_docs.tools.nbfmt "${changed_notebooks[@]}" fi + - name: Commit and push changes (if any) + if: ${{ success() }} # Only run if previous steps were successful + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git diff --quiet && git diff --staged --quiet || (git commit -a -m "Format notebooks" && git push) nblint: name: Notebook lint runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + with: + # Check out the pull request branch to reflect changes from nbfmt + ref: ${{ github.event.pull_request.head.ref }} - uses: actions/setup-python@v4 - name: Install tensorflow-docs run: python3 -m pip install -U git+https://github.com/tensorflow/docs @@ -75,5 +86,4 @@ jobs: --arg=base_url:https://ai.google.dev/ \ --exclude_lint=tensorflow::button_github \ "${changed_notebooks[@]}" - fi - + fi \ No newline at end of file From 46d681f6a9900a1e5057e637a33bfd151a031279 Mon Sep 17 00:00:00 2001 From: giom Date: Mon, 30 Dec 2024 15:08:14 +0000 Subject: [PATCH 03/10] undo: auto-formatting notebooks. --- .github/workflows/notebooks.yaml | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/.github/workflows/notebooks.yaml b/.github/workflows/notebooks.yaml index 1e94aa813..f42843f9b 100644 --- a/.github/workflows/notebooks.yaml +++ b/.github/workflows/notebooks.yaml @@ -17,15 +17,12 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - with: - # Check out the pull request branch - ref: ${{ github.event.pull_request.head.ref }} - uses: actions/setup-python@v4 - 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: Format notebooks + - name: Check notebook formatting run: | if [ "${{ github.event_name }}" == "pull_request" ]; then # Only check notebooks modified in this pull request @@ -36,25 +33,17 @@ jobs: fi if [[ ${#changed_notebooks[@]} == 0 ]]; then echo "No notebooks modified in this pull request." + exit 0 else - echo "Formatting notebooks with nbfmt:" - python3 -m tensorflow_docs.tools.nbfmt "${changed_notebooks[@]}" + echo "Check formatting with nbfmt:" + python3 -m tensorflow_docs.tools.nbfmt --test "${changed_notebooks[@]}" fi - - name: Commit and push changes (if any) - if: ${{ success() }} # Only run if previous steps were successful - run: | - git config --local user.email "action@github.com" - git config --local user.name "GitHub Action" - git diff --quiet && git diff --staged --quiet || (git commit -a -m "Format notebooks" && git push) nblint: name: Notebook lint runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - with: - # Check out the pull request branch to reflect changes from nbfmt - ref: ${{ github.event.pull_request.head.ref }} - uses: actions/setup-python@v4 - name: Install tensorflow-docs run: python3 -m pip install -U git+https://github.com/tensorflow/docs @@ -86,4 +75,5 @@ jobs: --arg=base_url:https://ai.google.dev/ \ --exclude_lint=tensorflow::button_github \ "${changed_notebooks[@]}" - fi \ No newline at end of file + fi + From f301f30ba0d114f02190ea86a1d6422e252f6545 Mon Sep 17 00:00:00 2001 From: giom Date: Mon, 30 Dec 2024 15:09:53 +0000 Subject: [PATCH 04/10] trying to auto-format notbooks --- .github/workflows/notebooks.yaml | 60 ++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/.github/workflows/notebooks.yaml b/.github/workflows/notebooks.yaml index f42843f9b..993848915 100644 --- a/.github/workflows/notebooks.yaml +++ b/.github/workflows/notebooks.yaml @@ -1,5 +1,3 @@ -# Notebook-related checks - name: Notebooks on: @@ -21,49 +19,66 @@ jobs: - name: Install tensorflow-docs run: python3 -m pip install -U git+https://github.com/tensorflow/docs - name: Fetch main branch + if: ${{ github.event_name == 'pull_request' }} # Only need to fetch main on PRs run: git fetch -u origin main:main - - name: Check notebook formatting + - name: Get changed notebooks + id: changed-notebooks run: | if [ "${{ github.event_name }}" == "pull_request" ]; then # Only check notebooks modified in this pull request - readarray -t changed_notebooks < <(git diff --name-only main | grep '\.ipynb$' || true) + git diff --name-only origin/main | grep '\.ipynb$' > changed_notebooks.txt else # Manual run, check everything - readarray -t changed_notebooks < <(find -name '*.ipynb') + find . -name '*.ipynb' > changed_notebooks.txt fi - if [[ ${#changed_notebooks[@]} == 0 ]]; then - echo "No notebooks modified in this pull request." - exit 0 + echo "changed_notebooks=$(cat changed_notebooks.txt)" >> $GITHUB_OUTPUT + - name: Format notebooks + run: | + if [ -s "${{ steps.changed-notebooks.outputs.changed_notebooks }}" ]; then + echo "Formatting notebooks with nbfmt:" + python3 -m tensorflow_docs.tools.nbfmt ${{ steps.changed-notebooks.outputs.changed_notebooks }} else - echo "Check formatting with nbfmt:" - python3 -m tensorflow_docs.tools.nbfmt --test "${changed_notebooks[@]}" + echo "No notebooks to format." fi + - name: Commit and push changes (if any) + if: ${{ success() }} + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git diff --quiet && git diff --staged --quiet || (git commit -a -m "Format notebooks" && git push) + nblint: name: Notebook lint runs-on: ubuntu-latest + needs: nbfmt # Ensure nblint runs after nbfmt steps: - uses: actions/checkout@v3 + with: + # Checkout PR branch for PR events, main branch for manual runs + ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || 'main' }} - uses: actions/setup-python@v4 - name: Install tensorflow-docs run: python3 -m pip install -U git+https://github.com/tensorflow/docs - name: Fetch main branch + if: ${{ github.event_name == 'pull_request' }} # Only need to fetch main on PRs run: git fetch -u origin main:main - - # Lint for all notebooks - - name: Lint notebooks + - name: Get changed notebooks + id: changed-notebooks run: | if [ "${{ github.event_name }}" == "pull_request" ]; then # Only check notebooks modified in this pull request - readarray -t changed_notebooks < <(git diff --name-only main |grep '\.ipynb$' || true) + git diff --name-only origin/main | grep '\.ipynb$' > changed_notebooks.txt else # Manual run, check everything - readarray -t changed_notebooks < <(find . -name '*.ipynb') + find . -name '*.ipynb' > changed_notebooks.txt fi - if [[ ${#changed_notebooks[@]} == 0 ]]; then - echo "No website notebooks modified in this pull request." - exit 0 - else + echo "changed_notebooks=$(cat changed_notebooks.txt)" >> $GITHUB_OUTPUT + + # Lint for all notebooks + - name: Lint notebooks + run: | + if [ -s "${{ steps.changed-notebooks.outputs.changed_notebooks }}" ]; then echo "WARNING: If the button_colab check fails for you, make sure you have " echo "Lint check with nblint:" python3 -m tensorflow_docs.tools.nblint \ @@ -74,6 +89,7 @@ jobs: --exclude_lint=tensorflow::button_website \ --arg=base_url:https://ai.google.dev/ \ --exclude_lint=tensorflow::button_github \ - "${changed_notebooks[@]}" - fi - + ${{ steps.changed-notebooks.outputs.changed_notebooks }} + else + echo "No notebooks to lint." + fi \ No newline at end of file From 6d04ba63b1652182debb66e0869b6d7c432eaf6b Mon Sep 17 00:00:00 2001 From: giom Date: Mon, 30 Dec 2024 15:15:17 +0000 Subject: [PATCH 05/10] Trying ot use the PR's branch --- .github/workflows/notebooks.yaml | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/.github/workflows/notebooks.yaml b/.github/workflows/notebooks.yaml index 993848915..aa6b0e5df 100644 --- a/.github/workflows/notebooks.yaml +++ b/.github/workflows/notebooks.yaml @@ -15,11 +15,15 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + with: + # Checkout PR branch for PR events, main branch for manual runs + ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || 'main' }} + fetch-depth: 0 # Fetch all history to avoid issues with rebasing - uses: actions/setup-python@v4 - name: Install tensorflow-docs run: python3 -m pip install -U git+https://github.com/tensorflow/docs - name: Fetch main branch - if: ${{ github.event_name == 'pull_request' }} # Only need to fetch main on PRs + if: ${{ github.event_name == 'pull_request' }} run: git fetch -u origin main:main - name: Get changed notebooks id: changed-notebooks @@ -40,18 +44,26 @@ jobs: else echo "No notebooks to format." fi - - name: Commit and push changes (if any) if: ${{ success() }} run: | git config --local user.email "action@github.com" git config --local user.name "GitHub Action" - git diff --quiet && git diff --staged --quiet || (git commit -a -m "Format notebooks" && git push) + # Check if there are changes + if ! git diff --quiet; then + # Commit on the current branch + git add . + git commit -m "Format notebooks" + # Push directly to the PR branch + git push origin ${{ github.event.pull_request.head.ref }} + else + echo "No changes to commit." + fi nblint: name: Notebook lint runs-on: ubuntu-latest - needs: nbfmt # Ensure nblint runs after nbfmt + needs: nbfmt steps: - uses: actions/checkout@v3 with: @@ -61,7 +73,7 @@ jobs: - name: Install tensorflow-docs run: python3 -m pip install -U git+https://github.com/tensorflow/docs - name: Fetch main branch - if: ${{ github.event_name == 'pull_request' }} # Only need to fetch main on PRs + if: ${{ github.event_name == 'pull_request' }} run: git fetch -u origin main:main - name: Get changed notebooks id: changed-notebooks From 9d5dd7fef2692b8836aa1cc4da1a0d83ce8bf074 Mon Sep 17 00:00:00 2001 From: giom Date: Mon, 30 Dec 2024 15:21:12 +0000 Subject: [PATCH 06/10] using origin's branch --- .github/workflows/notebooks.yaml | 89 +------------------------------- 1 file changed, 2 insertions(+), 87 deletions(-) diff --git a/.github/workflows/notebooks.yaml b/.github/workflows/notebooks.yaml index aa6b0e5df..1d8fdc72c 100644 --- a/.github/workflows/notebooks.yaml +++ b/.github/workflows/notebooks.yaml @@ -17,91 +17,6 @@ jobs: - uses: actions/checkout@v3 with: # Checkout PR branch for PR events, main branch for manual runs - ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || 'main' }} + ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || 'main' }} fetch-depth: 0 # Fetch all history to avoid issues with rebasing - - uses: actions/setup-python@v4 - - name: Install tensorflow-docs - run: python3 -m pip install -U git+https://github.com/tensorflow/docs - - name: Fetch main branch - if: ${{ github.event_name == 'pull_request' }} - run: git fetch -u origin main:main - - name: Get changed notebooks - id: changed-notebooks - run: | - if [ "${{ github.event_name }}" == "pull_request" ]; then - # Only check notebooks modified in this pull request - git diff --name-only origin/main | grep '\.ipynb$' > changed_notebooks.txt - else - # Manual run, check everything - find . -name '*.ipynb' > changed_notebooks.txt - fi - echo "changed_notebooks=$(cat changed_notebooks.txt)" >> $GITHUB_OUTPUT - - name: Format notebooks - run: | - if [ -s "${{ steps.changed-notebooks.outputs.changed_notebooks }}" ]; then - echo "Formatting notebooks with nbfmt:" - python3 -m tensorflow_docs.tools.nbfmt ${{ steps.changed-notebooks.outputs.changed_notebooks }} - else - echo "No notebooks to format." - fi - - name: Commit and push changes (if any) - if: ${{ success() }} - run: | - git config --local user.email "action@github.com" - git config --local user.name "GitHub Action" - # Check if there are changes - if ! git diff --quiet; then - # Commit on the current branch - git add . - git commit -m "Format notebooks" - # Push directly to the PR branch - git push origin ${{ github.event.pull_request.head.ref }} - else - echo "No changes to commit." - fi - - nblint: - name: Notebook lint - runs-on: ubuntu-latest - needs: nbfmt - steps: - - uses: actions/checkout@v3 - with: - # Checkout PR branch for PR events, main branch for manual runs - ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || 'main' }} - - uses: actions/setup-python@v4 - - name: Install tensorflow-docs - run: python3 -m pip install -U git+https://github.com/tensorflow/docs - - name: Fetch main branch - if: ${{ github.event_name == 'pull_request' }} - run: git fetch -u origin main:main - - name: Get changed notebooks - id: changed-notebooks - run: | - if [ "${{ github.event_name }}" == "pull_request" ]; then - # Only check notebooks modified in this pull request - git diff --name-only origin/main | grep '\.ipynb$' > changed_notebooks.txt - else - # Manual run, check everything - find . -name '*.ipynb' > changed_notebooks.txt - fi - echo "changed_notebooks=$(cat changed_notebooks.txt)" >> $GITHUB_OUTPUT - - # Lint for all notebooks - - name: Lint notebooks - run: | - if [ -s "${{ steps.changed-notebooks.outputs.changed_notebooks }}" ]; then - echo "WARNING: If the button_colab check fails for you, make sure you have
" - echo "Lint check with nblint:" - python3 -m tensorflow_docs.tools.nblint \ - --styles=google,tensorflow \ - --arg=repo:google-gemini/cookbook \ - --arg=branch:main \ - --exclude_lint=tensorflow::button_download \ - --exclude_lint=tensorflow::button_website \ - --arg=base_url:https://ai.google.dev/ \ - --exclude_lint=tensorflow::button_github \ - ${{ steps.changed-notebooks.outputs.changed_notebooks }} - else - echo "No notebooks to lint." - fi \ No newline at end of file + - uses: actions/setup \ No newline at end of file From 43bb57215706d2ee4fbd8d99fd228917e9cc81eb Mon Sep 17 00:00:00 2001 From: giom Date: Mon, 30 Dec 2024 15:31:02 +0000 Subject: [PATCH 07/10] Splitting changes in different PRs --- gemini-2/websockets/live_api_starter.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gemini-2/websockets/live_api_starter.ipynb b/gemini-2/websockets/live_api_starter.ipynb index 97bc5f416..d864e7d79 100644 --- a/gemini-2/websockets/live_api_starter.ipynb +++ b/gemini-2/websockets/live_api_starter.ipynb @@ -69,7 +69,7 @@ "\n", "- The [Live API - Text to Text](../Live_API_Text_to_Text.ipynb) notebook is even simpler than this, as it doesn't deal with audio.\n", "- The [Live API - Audio Streaming in Colab](./live_api_streaming_in_colab.ipynb) demonstrates streaming audio **in Colab**.
It's more _fun_ than this notebook but **not optimized for readability**.\n", - "- The [Live API Audio Video to Audio python script](./live_api_starter.py) doesn't work in colab, but provides a relatively readable implementation of audio and video streaming." + "- The [Live API Audio Video to Audio python script](./live_api_audio_video_to_audio.py) doesn't work in colab, but provides a relatively readable implementation of audio and video streaming." ] }, { From a8dedf63c66f10dd325f79ab6db0ce56207db40b Mon Sep 17 00:00:00 2001 From: giom Date: Wed, 1 Jan 2025 12:37:24 +0000 Subject: [PATCH 08/10] adding the missing part --- .github/workflows/notebooks.yaml | 60 +++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/.github/workflows/notebooks.yaml b/.github/workflows/notebooks.yaml index 1d8fdc72c..d963c36c8 100644 --- a/.github/workflows/notebooks.yaml +++ b/.github/workflows/notebooks.yaml @@ -19,4 +19,62 @@ jobs: # Checkout PR branch for PR events, main branch for manual runs ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || 'main' }} fetch-depth: 0 # Fetch all history to avoid issues with rebasing - - uses: actions/setup \ No newline at end of file + - uses: actions/setup + - uses: actions/setup-python@v4 + - 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: Check notebook formatting + run: | + if [ "${{ github.event_name }}" == "pull_request" ]; then + # Only check notebooks modified in this pull request + readarray -t changed_notebooks < <(git diff --name-only main | grep '\.ipynb$' || true) + else + # Manual run, check everything + readarray -t changed_notebooks < <(find -name '*.ipynb') + fi + 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/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 main branch + run: git fetch -u origin main:main + + # Lint for all notebooks + - name: Lint notebooks + run: | + if [ "${{ github.event_name }}" == "pull_request" ]; then + # Only check notebooks modified in this pull request + readarray -t changed_notebooks < <(git diff --name-only main |grep '\.ipynb$' || true) + else + # Manual run, check everything + readarray -t changed_notebooks < <(find . -name '*.ipynb') + fi + if [[ ${#changed_notebooks[@]} == 0 ]]; then + echo "No website notebooks modified in this pull request." + exit 0 + else + echo "WARNING: If the button_colab check fails for you, make sure you have
" + echo "Lint check with nblint:" + python3 -m tensorflow_docs.tools.nblint \ + --styles=google,tensorflow \ + --arg=repo:google-gemini/cookbook \ + --arg=branch:main \ + --exclude_lint=tensorflow::button_download \ + --exclude_lint=tensorflow::button_website \ + --arg=base_url:https://ai.google.dev/ \ + --exclude_lint=tensorflow::button_github \ + "${changed_notebooks[@]}" + fi \ No newline at end of file From a625c1f2ea9b0c8e01422f842d9ce6fd2d99a04f Mon Sep 17 00:00:00 2001 From: giom Date: Wed, 1 Jan 2025 12:45:20 +0000 Subject: [PATCH 09/10] remove duplicate action --- .github/workflows/notebooks.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/notebooks.yaml b/.github/workflows/notebooks.yaml index d963c36c8..4065f5cf7 100644 --- a/.github/workflows/notebooks.yaml +++ b/.github/workflows/notebooks.yaml @@ -19,8 +19,7 @@ jobs: # Checkout PR branch for PR events, main branch for manual runs ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || 'main' }} fetch-depth: 0 # Fetch all history to avoid issues with rebasing - - uses: actions/setup - - uses: actions/setup-python@v4 + - uses: actions/setup-python@v4 - name: Install tensorflow-docs run: python3 -m pip install -U git+https://github.com/tensorflow/docs - name: Fetch main branch From cb97b0bc05cc3f9d5881b11e8f55db0732456373 Mon Sep 17 00:00:00 2001 From: giom Date: Wed, 1 Jan 2025 12:48:49 +0000 Subject: [PATCH 10/10] Formatting notebooks --- .github/workflows/notebooks.yaml | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/.github/workflows/notebooks.yaml b/.github/workflows/notebooks.yaml index 4065f5cf7..3c7f96e90 100644 --- a/.github/workflows/notebooks.yaml +++ b/.github/workflows/notebooks.yaml @@ -24,6 +24,40 @@ jobs: run: python3 -m pip install -U git+https://github.com/tensorflow/docs - name: Fetch main branch run: git fetch -u origin main:main + - name: Get changed notebooks + id: changed-notebooks + run: | + if [ "${{ github.event_name }}" == "pull_request" ]; then + # Only check notebooks modified in this pull request + git diff --name-only origin/main | grep '\.ipynb$' > changed_notebooks.txt + else + # Manual run, check everything + find . -name '*.ipynb' > changed_notebooks.txt + fi + echo "changed_notebooks=$(cat changed_notebooks.txt)" >> $GITHUB_OUTPUT + - name: Format notebooks + run: | + if [ -s "${{ steps.changed-notebooks.outputs.changed_notebooks }}" ]; then + echo "Formatting notebooks with nbfmt:" + python3 -m tensorflow_docs.tools.nbfmt ${{ steps.changed-notebooks.outputs.changed_notebooks }} + else + echo "No notebooks to format." + fi + - name: Commit and push changes (if any) + if: ${{ success() }} + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + # Check if there are changes + if ! git diff --quiet; then + # Commit on the current branch + git add . + git commit -m "Format notebooks" + # Push directly to the PR branch + git push origin ${{ github.event.pull_request.head.ref }} + else + echo "No changes to commit." + fi - name: Check notebook formatting run: | if [ "${{ github.event_name }}" == "pull_request" ]; then