Skip to content

Commit e69c191

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 b84479c commit e69c191

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
@@ -65,8 +65,116 @@ jobs:
6565
path: dist/
6666
if-no-files-found: error
6767

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

0 commit comments

Comments
 (0)