Skip to content

Commit b9b310d

Browse files
committed
ci: Build and publish documentation
For pull requests the documentation is built and uploaded as an artifact, so it can be manually checked. For pushes, the documentation is built and published. When pushing to a branch, if it is the default branch, then the published version is called "next". At some point we might want to consider having multiple vMAJOR.MINOR-dev documentation generated, but will come when/if we have multiple vMAJOR.MINOR being maintained. For now if a branch other than the default branch is pused to, nothing will be published. When pushing a new tag, if it is a pre-release tag (includes a `-`), then the documentation is not published (again it could be published once we have vMAJOR.MINOR-dev versions of the documentation). Otherwise the documentation is published with version vMAJOR.MINOR and a vMAJOR alias is added. If the MAJOR is the same as the default branch, a "latest" alias is added/updated to that version too. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 9e71a06 commit b9b310d

File tree

1 file changed

+111
-1
lines changed

1 file changed

+111
-1
lines changed

.github/workflows/ci.yaml

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,118 @@ jobs:
6666
path: dist/
6767
if-no-files-found: error
6868

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

0 commit comments

Comments
 (0)