Skip to content

Commit 2ca5c40

Browse files
authored
Merge pull request #27 from sphinx-notes/feat/publishing-from-branch
Support publishing from a branch
2 parents d5d6652 + cbf52a7 commit 2ca5c40

File tree

3 files changed

+75
-22
lines changed

3 files changed

+75
-22
lines changed

README.rst

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,21 @@ Sphinx to GitHub Pages V3
77

88
Helps you deploy your Sphinx documentation to Github Pages.
99

10-
.. warning:: v3 is **in beta and subject to change**, use v2__ if you need a stable version.
11-
12-
__ https://github.com/sphinx-notes/pages/tree/v2
13-
1410
Usage
1511
=====
1612

13+
We provides two ways for publishing GitHub pages.
14+
The first one is the default but **still in beta**, use the second one if you tend to be stable.
15+
16+
Publishing with this action (default)
17+
***************************************
18+
1719
1. `Set the publishing sources to "Github Actions"`__
18-
2. Create workflow:
20+
2. Create the following workflow:
1921

2022
.. code-block:: yaml
2123
2224
name: Deploy Sphinx documentation to Pages
23-
24-
# Runs on pushes targeting the default branch
25-
on:
26-
push:
27-
branches: [master]
28-
2925
jobs:
3026
pages:
3127
runs-on: ubuntu-20.04
@@ -41,6 +37,33 @@ Usage
4137
4238
__ https://docs.github.com/en/pages/getting-started-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site#publishing-with-a-custom-github-actions-workflow
4339

40+
Publishing from a branch (classical)
41+
************************************
42+
43+
1. Create a branch ``gh-pages``
44+
2. `Set the publishing sources to "Deploy from a branch"`__, then specify the branch just created
45+
3. Create the following workflow, in this way user need to publish the site by another action,
46+
we use `peaceiris/actions-gh-pages`__ here:
47+
48+
.. code-block:: yaml
49+
50+
name: Deploy Sphinx documentation to Pages
51+
jobs:
52+
pages:
53+
runs-on: ubuntu-20.04
54+
steps:
55+
- id: deployment
56+
uses: sphinx-notes/pages@v3
57+
with:
58+
publish: false
59+
- uses: peaceiris/actions-gh-pages@v3
60+
with:
61+
github_token: ${{ secrets.GITHUB_TOKEN }}
62+
publish_dir: ${{ steps.deployment.outputs.artifact }}
63+
64+
__ https://docs.github.com/en/pages/getting-started-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site#publishing-from-a-branch
65+
__ https://github.com/peaceiris/actions-gh-pages
66+
4467
Inputs
4568
======
4669

@@ -52,24 +75,39 @@ Input Default Required Description
5275
used in ``pip install -r XXX`` command
5376
``pyproject_extras`` ``docs`` false Extras of `Requirement Specifier`__
5477
used in ``pip install .[XXX]``
78+
========================== ============================ ======== =================================================
79+
80+
Advanced
81+
********
82+
83+
In most cases you don't need to know about the following inputs.
84+
Unless you need to highly customize the action's behavior.
85+
86+
========================== ============================ ======== =================================================
87+
Input Default Required Description
88+
-------------------------- ---------------------------- -------- -------------------------------------------------
5589
``python_version`` ``3.10`` false Version of Python
5690
``sphinx_version`` ``5.3`` false Version of Sphinx
5791
``sphinx_build_options`` false Additional options passed to ``sphinx-build``
5892
``cache`` ``false`` false Enable cache to speed up documentation building
5993
``checkout`` ``true`` false Whether to automatically checkout the repository,
6094
if false, user need to do it byself
95+
``publish`` ``true`` false Whether to automatically publish the repository
6196
========================== ============================ ======== =================================================
6297

6398
__ https://pip.pypa.io/en/stable/reference/requirement-specifiers/#overview
6499

65100
Outputs
66101
=======
67102

68-
======================= ============================
103+
======================= =========================================================
69104
Output Description
70-
----------------------- ----------------------------
71-
``page_url`` URL to deployed GitHub Pages
72-
======================= ============================
105+
----------------------- ---------------------------------------------------------
106+
``page_url`` URL to deployed GitHub Pages,
107+
only available when option ``publish`` is set to ``true``
108+
``artifact`` Directory where artifact (HTML documentation) is stored,
109+
user can use it to deploy GitHub Pages manually
110+
======================= =========================================================
73111

74112
Examples
75113
========

action.yml

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,17 @@ inputs:
3838
description: 'Whether to automatically checkout the repository, if false, user need to do it byself'
3939
required: false
4040
default: true
41+
publish:
42+
description: 'Whether to automatically publish the pages, if false, user need to manually publish by self'
43+
required: false
44+
default: true
4145
outputs:
4246
page_url:
43-
description: 'URL to deployed GitHub Pages'
47+
description: 'URL to deployed GitHub Pages, only available when option publish is set to true'
4448
value: ${{ steps.deployment.outputs.page_url }}
49+
artifact:
50+
description: 'Directory where artifact (HTML documentation) is stored, user can use it to deploy GitHub Pages manually'
51+
value: ${{ steps.build.outputs.artifact }}
4552

4653
runs:
4754
using: "composite"
@@ -77,7 +84,8 @@ runs:
7784
restore-keys: |
7885
sphinxnotes-pages-${{ runner.os }}
7986
80-
- name: Build documentation
87+
- id: build
88+
name: Build documentation
8189
run: ${{ github.action_path }}/main.sh
8290
shell: bash
8391
env:
@@ -91,12 +99,15 @@ runs:
9199

92100
- name: Setup Pages
93101
uses: actions/configure-pages@v2
102+
if: ${{ inputs.publish == 'true' }}
94103

95104
- name: Upload artifact
96105
uses: actions/upload-pages-artifact@v1
106+
if: ${{ inputs.publish == 'true' }}
97107
with:
98-
path: /tmp/sphinxnotes-pages
99-
100-
- name: Deploy to GitHub Pages
101-
id: deployment
108+
path: ${{ steps.build.outputs.artifact }}
109+
110+
- id: deployment
111+
name: Deploy to GitHub Pages
102112
uses: actions/deploy-pages@v1
113+
if: ${{ inputs.publish == 'true' }}

main.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@
33
# set -x
44
set -e
55

6+
echo ::group:: Initialize various paths
7+
68
repo_dir=$GITHUB_WORKSPACE/$INPUT_REPOSITORY_PATH
79
doc_dir=$repo_dir/$INPUT_DOCUMENTATION_PATH
810
# https://stackoverflow.com/a/4774063/4799273
911
action_dir=$GITHUB_ACTION_PATH
1012

11-
echo ::group:: Initialize various paths
1213
echo Action: $action_dir
1314
echo Workspace: $GITHUB_WORKSPACE
1415
echo Repository: $repo_dir
1516
echo Documentation: $doc_dir
17+
1618
echo ::endgroup::
1719

1820
# The actions doesn't depends on any images,
@@ -96,3 +98,5 @@ if ! sphinx-build -b html $INPUT_SPHINX_BUILD_OPTIONS "$doc_dir" "$build_dir"; t
9698
exit 1
9799
fi
98100
echo ::endgroup::
101+
102+
echo "artifact=$build_dir" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)