Skip to content

Commit e1c1246

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 1a4c2a2 commit e1c1246

File tree

1 file changed

+109
-1
lines changed

1 file changed

+109
-1
lines changed

.github/workflows/ci.yaml

Lines changed: 109 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,116 @@ 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: "3.10"
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+
steps:
108+
- name: Calculate and check version
109+
id: mike-metadata
110+
env:
111+
REF: ${{ github.ref }}
112+
REF_NAME: ${{ github.ref_name }}
113+
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
114+
run: |
115+
aliases=
116+
version=
117+
if test "$REF_NAME" = "$DEFAULT_BRANCH"
118+
then
119+
version=next
120+
# A tag that starts with vX.Y or X.Y
121+
elif echo "$REF" | grep -q '^refs/tags' && echo "$REF_NAME" | grep -Pq '^v?\d+\.\d+\.'
122+
then
123+
if echo "$REF_NAME" | grep -Pq -- "-" # pre-release
124+
then
125+
echo "::notice title=Documentation was not published::" \
126+
"The tag '$REF_NAME' looks like a pre-release."
127+
exit 0
128+
fi
129+
version=$(echo "$REF_NAME" | sed -r 's/^(v?[0-9]+\.[0-9]+)\..*$/\1/') # vX.Y
130+
major=$(echo "$REF_NAME" | sed -r 's/^(v?[0-9]+)\..*$/\1/') # vX
131+
default_major=$(echo "$DEFAULT_BRANCH" | sed -r 's/^(v?[0-9]+)\..*$/\1/') # vX
132+
aliases=$major
133+
if test "$major" = "$default_major"
134+
then
135+
aliases="$aliases latest"
136+
fi
137+
else
138+
echo "::warning title=Documentation was not published::" \
139+
"Don't know how to handle '$REF' to make 'mike' version."
140+
exit 0
141+
fi
142+
echo "version=$version" >> $GITHUB_OUTPUT
143+
echo "aliases=$aliases" >> $GITHUB_OUTPUT
144+
145+
- name: Fetch sources
146+
if: steps.mike-metadata.outputs.version
147+
uses: actions/checkout@v3
148+
149+
- name: Setup Git user and e-mail
150+
if: steps.mike-metadata.outputs.version
151+
uses: frequenz-floss/setup-git-user@v1
152+
153+
- name: Set up Python
154+
if: steps.mike-metadata.outputs.version
155+
uses: actions/setup-python@v4
156+
with:
157+
python-version: "3.10"
158+
159+
- name: Install build dependencies
160+
if: steps.mike-metadata.outputs.version
161+
run: |
162+
python -m pip install -U pip
163+
python -m pip install .[docs]
164+
165+
- name: Fetch the gh-pages branch
166+
if: steps.mike-metadata.outputs.version
167+
run: git fetch origin gh-pages --depth=1
168+
169+
- name: Publish site
170+
if: steps.mike-metadata.outputs.version
171+
env:
172+
VERSION: ${{ steps.mike-metadata.outputs.version }}
173+
ALIASES: ${{ steps.mike-metadata.outputs.aliases }}
174+
run: |
175+
mike deploy --push "$VERSION" $ALIASES
176+
177+
create-github-release:
178+
needs: ["publish-docs"]
71179
# Create a release only on tags creation
72180
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
73181
permissions:

0 commit comments

Comments
 (0)