@@ -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