From 1b75d7238cd68719f8350bc8014135b8aef6e41b Mon Sep 17 00:00:00 2001 From: Sylvain Gugger <35901082+sgugger@users.noreply.github.com> Date: Fri, 10 Dec 2021 14:20:56 -0500 Subject: [PATCH] Automatically build doc notebooks (#14718) * Test workflow * Build doc * Make a clean build * Add doc config * Restore other workflows * Final job * Print something in else statements * Pull before making changes --- .github/workflows/build_documentation.yml | 50 ++++++++++++++++++----- docs/source/_config.py | 7 ++++ 2 files changed, 47 insertions(+), 10 deletions(-) create mode 100644 docs/source/_config.py diff --git a/.github/workflows/build_documentation.yml b/.github/workflows/build_documentation.yml index a5be45cf09..cd38c45eab 100644 --- a/.github/workflows/build_documentation.yml +++ b/.github/workflows/build_documentation.yml @@ -17,11 +17,19 @@ jobs: - uses: actions/checkout@v2 with: repository: 'huggingface/doc-builder' + path: doc-builder + token: ${{ secrets.HUGGINGFACE_PUSH }} + + - uses: actions/checkout@v2 + with: + repository: 'huggingface/transformers' + path: transformers + + - uses: actions/checkout@v2 + with: + repository: 'huggingface/notebooks' + path: notebooks token: ${{ secrets.HUGGINGFACE_PUSH }} - - - name: Clone transformers - run: | - git clone https://github.com/huggingface/transformers - name: Loading cache. uses: actions/cache@v2 @@ -37,7 +45,7 @@ jobs: run: | sudo apt-get -y update && sudo apt-get install -y libsndfile1-dev - pip install git+https://github.com/huggingface/doc-builder + pip install git+https://github.com/huggingface/doc-builder@add-install-cell pip install git+https://github.com/huggingface/transformers#egg=transformers[dev] export TORCH_VERSION=$(python -c "from torch import version; print(version.__version__.split('+')[0])") @@ -55,15 +63,37 @@ jobs: run: | git config --global user.name "Hugging Face" git config --global user.email transformers@huggingface.co + + cd doc-builder git pull origin main + cd .. + + cd notebooks + git pull origin master + cd .. - name: Make documentation run: | - doc-builder build transformers ./transformers/docs/source + doc-builder build transformers transformers/docs/source --build_dir doc-builder/build --notebook_dir notebooks/transformers_doc --clean - - name: Push to repository + - name: Push to repositories run: | - git add build - git commit -m "Updated with commit ${{ github.sha }}" - git push origin main + cd doc-builder + if [[ `git status --porcelain` ]]; then + git add build + git commit -m "Updated with commit ${{ github.sha }}" + git push origin main + else + echo "No diff in the documentation." + fi + cd .. + cd notebooks + if [[ `git status --porcelain` ]]; then + git add build + git commit -m "Updated Transformer doc notebooks with commit ${{ github.sha }}" + git push origin master + else + echo "No diff in the notebooks." + fi + cd .. diff --git a/docs/source/_config.py b/docs/source/_config.py new file mode 100644 index 0000000000..a038fc874a --- /dev/null +++ b/docs/source/_config.py @@ -0,0 +1,7 @@ +INSTALL_CONTENT = """ +# Transformers installation ! pip install transformers datasets # To install from source instead of the last release, +comment the command above and uncomment the following one. # ! pip install +git+https://github.com/huggingface/transformers.git +""" + +notebook_first_cells = [{"type": "code", "content": INSTALL_CONTENT}] \ No newline at end of file