Debian Codegraph @

docs/source/publish-github-action.rst

raw
1 :orphan:
2
3 Simple GitHub Action to publish API docs
4 ----------------------------------------
5
6 Here is an example of a simple GitHub Action to automatically
7 generate your documentation with Pydoctor
8 and publish it to your default GitHub Pages website when there is a push on the ``main`` branch.
9
10 Just substitute `(projectname)` and `(packagedirectory)`
11 with the appropriate information.
12
13 ::
14
15 name: apidocs
16 on:
17 push:
18 branches: [main]
19 pull_request:
20 branches: [main]
21
22 jobs:
23 deploy:
24 runs-on: ubuntu-latest
25
26 permissions:
27 contents: write
28
29 steps:
30 - uses: actions/checkout@master
31 - name: Set up Python 3.12
32 uses: actions/setup-python@v2
33 with:
34 python-version: 3.12
35
36 - name: Install requirements for documentation generation
37 run: |
38 python -m pip install --upgrade pip setuptools wheel
39 python -m pip install pydoctor
40
41 - name: Generate API documentation with pydoctor
42 run: |
43
44 # Run pydoctor build
45 pydoctor \
46 --project-name=(projectname) \
47 --project-url=https://github.com/$GITHUB_REPOSITORY \
48 --html-viewsource-base=https://github.com/$GITHUB_REPOSITORY/tree/$GITHUB_SHA \
49 --html-base-url=https://$GITHUB_REPOSITORY_OWNER.github.io/${GITHUB_REPOSITORY#*/} \
50 --html-output=./apidocs \
51 --docformat=restructuredtext \
52 --intersphinx=https://docs.python.org/3/objects.inv \
53 ./(packagedirectory)
54
55 - name: Push API documentation to Github Pages (if on main branch)
56 if: github.ref == 'refs/heads/main'
57 uses: peaceiris/actions-gh-pages@v4
58 with:
59 github_token: ${{ secrets.GITHUB_TOKEN }}
60 publish_dir: ./apidocs
61 commit_message: "Generate API documentation"
62
63 .. note:: As mentioned in the ``actions-gh-pages`` `documentation`__, the first workflow run won't actually publish the documentation to GitHub Pages.
64 GitHub Pages needs to be enabled afterwards in the repository settings, select ``gh-pages`` branch, then re-run your workflow.
65
66 The website will be located at `https://(user).github.io/(repo)/`.
67
68 __ https://github.com/peaceiris/actions-gh-pages