1- # Build and deploy documentation
1+ # Build and deploy documentation.
22#
33# This workflow builds the documentation on Linux/macOS/Windows.
44#
5- # It is run on every commit to the main and pull request branches, and also
6- # when a new release is published.
7- # In draft pull requests, only the job on Linux is triggered to save on
8- # Continuous Integration resources.
5+ # It is run on every commit to the main and pull request branches, and also when a new
6+ # release is published. In draft pull requests, only the job on Linux is triggered to
7+ # save on Continuous Integration resources.
98#
109# On the main branch, the workflow also handles the documentation deployment:
1110#
12- # * Updating the development documentation by pushing the built HTML pages
13- # from the main branch onto the dev folder of the gh-pages branch.
11+ # * Updating the development documentation by pushing the built HTML pages from the main
12+ # branch onto the dev folder of the gh-pages branch.
1413# * Updating the latest documentation link to the new release.
1514#
1615name : Docs
@@ -44,7 +43,7 @@ concurrency:
4443 cancel-in-progress : ${{ github.ref != 'refs/heads/main' }}
4544
4645jobs :
47- docs :
46+ build- docs :
4847 name : ${{ matrix.os }}
4948 runs-on : ${{ matrix.os }}
5049 if : github.repository == 'GenericMappingTools/pygmt'
@@ -139,6 +138,28 @@ jobs:
139138 - name : Build the documentation
140139 run : make -C doc clean all
141140
141+ # Upload documentation artifact
142+ - name : Upload documentation artifact
143+ 144+ with :
145+ name : pygmt-docs-html
146+ path : doc/_build/html/
147+ if : matrix.os == 'ubuntu-latest'
148+
149+ deploy-docs :
150+ name : Deploy documentation
151+ needs : build-docs
152+ runs-on : ubuntu-latest
153+ if : (github.event_name == 'release' || github.event_name == 'push') && github.repository == 'GenericMappingTools/pygmt'
154+
155+ steps :
156+ # Checkout current git repository
157+ - name : Checkout
158+ 159+ with :
160+ # fetch all history so that setuptools-scm works
161+ fetch-depth : 0
162+
142163 - name : Checkout the gh-pages branch
143164144165 with :
@@ -147,7 +168,12 @@ jobs:
147168 path : deploy
148169 # Download the entire history
149170 fetch-depth : 0
150- if : (github.event_name == 'release' || github.event_name == 'push') && (matrix.os == 'ubuntu-latest')
171+
172+ - name : Download documentation artifact
173+ 174+ with :
175+ name : pygmt-docs-html
176+ path : pygmt-docs-html
151177
152178 - name : Push the built HTML to gh-pages
153179 run : |
@@ -159,10 +185,10 @@ jobs:
159185 version=dev
160186 fi
161187 echo "Deploying version: $version"
162- # Make the new commit message. Needs to happen before cd into deploy
163- # to get the right commit hash.
188+ # Make the new commit message. Needs to happen before cd into deploy to get
189+ # the right commit hash.
164190 message="Deploy $version from $(git rev-parse --short HEAD)"
165- cd deploy
191+ cd deploy/
166192 # Create some files in the root directory.
167193 # .nojekyll: Need to have this file so that GitHub doesn't try to run Jekyll
168194 touch .nojekyll
@@ -174,7 +200,7 @@ jobs:
174200 echo -e "\nRemoving old files from previous builds of ${version}:"
175201 rm -rvf ${version}
176202 echo -e "\nCopying HTML files to ${version}:"
177- cp -Rvf ../doc/_build/ html/ ${version}/
203+ cp -Rvf ../pygmt-docs- html/ ${version}/
178204 # If this is a new release, update the link from /latest to it
179205 if [[ "${version}" != "dev" ]]; then
180206 echo -e "\nSetup link from ${version} to 'latest'."
@@ -188,19 +214,17 @@ jobs:
188214 # Configure git to be the GitHub Actions account
189215 git config user.email "github-actions[bot]@users.noreply.github.com"
190216 git config user.name "github-actions[bot]"
191- # If this is a dev build and the last commit was from a dev build
192- # (detect if "dev" was in the previous commit message), reuse the
193- # same commit
217+ # If this is a dev build and the last commit was from a dev build (detect if
218+ # "dev" was in the previous commit message), reuse the same commit.
194219 if [[ "${version}" == "dev" && `git log -1 --format='%s'` == *"dev"* ]]; then
195220 echo -e "\nAmending last commit:"
196221 git commit --amend --reset-author -m "$message"
197222 else
198223 echo -e "\nMaking a new commit:"
199224 git commit -m "$message"
200225 fi
201- # Make the push quiet just in case there is anything that could leak
202- # sensitive information.
226+ # Make the push quiet just in case there is anything that could leak sensitive
227+ # information.
203228 echo -e "\nPushing changes to gh-pages."
204229 git push -fq origin gh-pages 2>&1 >/dev/null
205230 echo -e "\nFinished uploading generated files."
206- if : (github.event_name == 'release' || github.event_name == 'push') && (matrix.os == 'ubuntu-latest')
0 commit comments