Simple GitHub Action to publish API docs

Here is an example of a simple GitHub Action to automatically generate your documentation with Pydoctor and publish it to your default GitHub Pages website.

Just substitute (projectname) and (packagedirectory) with the appropriate information.

name: apidocs
- push

    runs-on: ubuntu-latest

    - uses: actions/checkout@master
    - name: Set up Python 3.8
      uses: actions/setup-python@v2
        python-version: 3.8

    - name: Install requirements for documentation generation
      run: |
        python -m pip install --upgrade pip setuptools wheel
        python -m pip install docutils pydoctor

    - name: Generate API documentation with pydoctor
      run: |

        # Run pydoctor build
        pydoctor \
            --project-name=(projectname) \
            --project-url=$GITHUB_REPOSITORY \
            --html-viewsource-base=$GITHUB_REPOSITORY/tree/$GITHUB_SHA \
            --make-html \
            --html-output=./apidocs \
            --project-base-dir="$(pwd)" \
            --docformat=restructuredtext \
            --intersphinx= \

    - name: Push API documentation to Github Pages
      uses: peaceiris/actions-gh-pages@v3
        github_token: ${{ secrets.GITHUB_TOKEN }}
        publish_dir: ./apidocs
        commit_message: "Generate API documentation"


As mentioned in the actions-gh-pages documentation, the first workflow run won’t actually publish the documentation to GitHub Pages. GitHub Pages needs to be enabled afterwards in the repository settings, select gh-pages branch, then re-run your workflow.

The website will be located at https://(user)