Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto format notebooks #391

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 39 additions & 5 deletions .github/workflows/notebooks.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Notebook-related checks

name: Notebooks

on:
Expand All @@ -17,11 +15,49 @@ 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.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
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 "[email protected]"
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
Expand All @@ -38,7 +74,6 @@ jobs:
echo "Check formatting with nbfmt:"
python3 -m tensorflow_docs.tools.nbfmt --test "${changed_notebooks[@]}"
fi

nblint:
name: Notebook lint
runs-on: ubuntu-latest
Expand Down Expand Up @@ -75,5 +110,4 @@ jobs:
--arg=base_url:https://ai.google.dev/ \
--exclude_lint=tensorflow::button_github \
"${changed_notebooks[@]}"
fi

fi
19 changes: 1 addition & 18 deletions gemini-2/websockets/live_api_starter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@
},
{
"cell_type": "markdown",
"metadata": {
"id": "gnzxta_57_Ip"
},
"metadata": {},
"source": [
"## Setup"
]
Expand Down Expand Up @@ -451,9 +449,6 @@
},
"outputs": [
{
"metadata": {
"tags": null
},
"name": "stdout",
"output_type": "stream",
"text": [
Expand All @@ -479,9 +474,6 @@
"output_type": "display_data"
},
{
"metadata": {
"tags": null
},
"name": "stdout",
"output_type": "stream",
"text": [
Expand All @@ -506,9 +498,6 @@
"output_type": "display_data"
},
{
"metadata": {
"tags": null
},
"name": "stdout",
"output_type": "stream",
"text": [
Expand All @@ -533,9 +522,6 @@
"output_type": "display_data"
},
{
"metadata": {
"tags": null
},
"name": "stdout",
"output_type": "stream",
"text": [
Expand All @@ -560,9 +546,6 @@
"output_type": "display_data"
},
{
"metadata": {
"tags": null
},
"name": "stdout",
"output_type": "stream",
"text": [
Expand Down
Loading