Skip to content

Commit 81733bf

Browse files
committed
ci: Generate and publish the documentation
Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 2b1aae7 commit 81733bf

File tree

1 file changed

+115
-1
lines changed
  • cookiecutter/{{cookiecutter.github_repo_name}}/.github/workflows

1 file changed

+115
-1
lines changed

cookiecutter/{{cookiecutter.github_repo_name}}/.github/workflows/ci.yaml

Lines changed: 115 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,123 @@ jobs:
8383
path: dist/
8484
if-no-files-found: error
8585

86+
test-docs:
87+
name: Test documentation website generation
88+
if: github.event_name != 'push'
89+
runs-on: ubuntu-{{'${{ env.DEFAULT_UBUNTU_VERSION }}'}}
90+
steps:
91+
- name: Fetch sources
92+
uses: actions/checkout@v3
93+
94+
- name: Setup Git user and e-mail
95+
uses: frequenz-floss/setup-git-user@v2
96+
97+
- name: Set up Python
98+
uses: actions/setup-python@v4
99+
with:
100+
python-version: {{'${{ env.DEFAULT_PYTHON_VERSION }}'}}
101+
cache: 'pip'
102+
103+
- name: Install build dependencies
104+
run: |
105+
python -m pip install -U pip
106+
python -m pip install .[dev-mkdocs]
107+
108+
- name: Generate the documentation
109+
env:
110+
MIKE_VERSION: gh-{{'${{ github.job }}'}}
111+
run: |
112+
mike deploy $MIKE_VERSION
113+
mike set-default $MIKE_VERSION
114+
115+
- name: Upload site
116+
uses: actions/upload-artifact@v3
117+
with:
118+
name: docs-site
119+
path: site/
120+
if-no-files-found: error
121+
122+
publish-docs:
123+
name: Publish documentation website to GitHub pages
124+
needs: ["test", "build"]
125+
if: github.event_name == 'push'
126+
runs-on: ubuntu-{{'${{ env.DEFAULT_UBUNTU_VERSION }}'}}
127+
permissions:
128+
contents: write
129+
steps:
130+
- name: Calculate and check version
131+
id: mike-metadata
132+
env:
133+
REF: {{'${{ github.ref }}'}}
134+
REF_NAME: {{'${{ github.ref_name }}'}}
135+
DEFAULT_BRANCH: {{'${{ github.event.repository.default_branch }}'}}
136+
run: |
137+
aliases=
138+
version=
139+
if test "$REF_NAME" = "$DEFAULT_BRANCH"
140+
then
141+
version=next
142+
# A tag that starts with vX.Y or X.Y
143+
elif echo "$REF" | grep -q '^refs/tags' && echo "$REF_NAME" | grep -Pq '^v?\d+\.\d+\.'
144+
then
145+
if echo "$REF_NAME" | grep -Pq -- "-" # pre-release
146+
then
147+
echo "::notice title=Documentation was not published::" \
148+
"The tag '$REF_NAME' looks like a pre-release."
149+
exit 0
150+
fi
151+
version=$(echo "$REF_NAME" | sed -r 's/^(v?[0-9]+\.[0-9]+)\..*$/\1/') # vX.Y
152+
major=$(echo "$REF_NAME" | sed -r 's/^(v?[0-9]+)\..*$/\1/') # vX
153+
default_major=$(echo "$DEFAULT_BRANCH" | sed -r 's/^(v?[0-9]+)\..*$/\1/') # vX
154+
aliases=$major
155+
if test "$major" = "$default_major"
156+
then
157+
aliases="$aliases latest"
158+
fi
159+
else
160+
echo "::warning title=Documentation was not published::" \
161+
"Don't know how to handle '$REF' to make 'mike' version."
162+
exit 0
163+
fi
164+
echo "version=$version" >> $GITHUB_OUTPUT
165+
echo "aliases=$aliases" >> $GITHUB_OUTPUT
166+
167+
- name: Fetch sources
168+
if: steps.mike-metadata.outputs.version
169+
uses: actions/checkout@v3
170+
171+
- name: Setup Git user and e-mail
172+
if: steps.mike-metadata.outputs.version
173+
uses: frequenz-floss/setup-git-user@v2
174+
175+
- name: Set up Python
176+
if: steps.mike-metadata.outputs.version
177+
uses: actions/setup-python@v4
178+
with:
179+
python-version: {{'${{ env.DEFAULT_PYTHON_VERSION }}'}}
180+
cache: 'pip'
181+
182+
- name: Install build dependencies
183+
if: steps.mike-metadata.outputs.version
184+
run: |
185+
python -m pip install -U pip
186+
python -m pip install .[dev-mkdocs]
187+
188+
- name: Fetch the gh-pages branch
189+
if: steps.mike-metadata.outputs.version
190+
run: git fetch origin gh-pages --depth=1
191+
192+
- name: Publish site
193+
if: steps.mike-metadata.outputs.version
194+
env:
195+
VERSION: {{'${{ steps.mike-metadata.outputs.version }}'}}
196+
ALIASES: {{'${{ steps.mike-metadata.outputs.aliases }}'}}
197+
run: |
198+
mike deploy --push --update-aliases "$VERSION" $ALIASES
199+
86200
create-github-release:
87201
name: Create GitHub release
88-
needs: ["build"]
202+
needs: ["publish-docs"]
89203
# Create a release only on tags creation
90204
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
91205
permissions:

0 commit comments

Comments
 (0)