Skip to content

Commit 78bf149

Browse files
committed
CI: Separate jobs to build and deploy documentation
1 parent 77a2d59 commit 78bf149

File tree

1 file changed

+42
-19
lines changed

1 file changed

+42
-19
lines changed

.github/workflows/ci_docs.yml

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
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
#
1615
name: Docs
@@ -44,7 +43,7 @@ concurrency:
4443
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
4544

4645
jobs:
47-
docs:
46+
build-docs:
4847
name: ${{ matrix.os }}
4948
runs-on: ${{ matrix.os }}
5049
if: github.repository == 'GenericMappingTools/pygmt'
@@ -139,6 +138,27 @@ jobs:
139138
- name: Build the documentation
140139
run: make -C doc clean all
141140

141+
- name: Upload HMTL documentation artifact
142+
uses: actions/upload-artifact@v4.5.0
143+
with:
144+
name: pygmt-docs-html
145+
path: doc/_build/html/
146+
if: matrix.os == 'ubuntu-latest'
147+
148+
deploy-docs:
149+
name: Deploy documentation
150+
needs: build-docs
151+
runs-on: ubuntu-latest
152+
if: (github.event_name == 'release' || github.event_name == 'push') && github.repository == 'GenericMappingTools/pygmt'
153+
154+
steps:
155+
# Checkout current git repository
156+
- name: Checkout
157+
uses: actions/checkout@v4.2.2
158+
with:
159+
# fetch all history so that setuptools-scm works
160+
fetch-depth: 0
161+
142162
- name: Checkout the gh-pages branch
143163
uses: actions/checkout@v4.2.2
144164
with:
@@ -147,7 +167,12 @@ jobs:
147167
path: deploy
148168
# Download the entire history
149169
fetch-depth: 0
150-
if: (github.event_name == 'release' || github.event_name == 'push') && (matrix.os == 'ubuntu-latest')
170+
171+
- name: Download HTML documentation artifact
172+
uses: actions/download-artifact@v4.1.8
173+
with:
174+
name: pygmt-docs-html
175+
path: pygmt-docs-html
151176

152177
- name: Push the built HTML to gh-pages
153178
run: |
@@ -159,10 +184,10 @@ jobs:
159184
version=dev
160185
fi
161186
echo "Deploying version: $version"
162-
# Make the new commit message. Needs to happen before cd into deploy
163-
# to get the right commit hash.
187+
# Make the new commit message. Needs to happen before cd into deploy to get
188+
# the right commit hash.
164189
message="Deploy $version from $(git rev-parse --short HEAD)"
165-
cd deploy
190+
cd deploy/
166191
# Create some files in the root directory.
167192
# .nojekyll: Need to have this file so that GitHub doesn't try to run Jekyll
168193
touch .nojekyll
@@ -174,7 +199,7 @@ jobs:
174199
echo -e "\nRemoving old files from previous builds of ${version}:"
175200
rm -rvf ${version}
176201
echo -e "\nCopying HTML files to ${version}:"
177-
cp -Rvf ../doc/_build/html/ ${version}/
202+
cp -Rvf ../pygmt-docs-html/ ${version}/
178203
# If this is a new release, update the link from /latest to it
179204
if [[ "${version}" != "dev" ]]; then
180205
echo -e "\nSetup link from ${version} to 'latest'."
@@ -188,19 +213,17 @@ jobs:
188213
# Configure git to be the GitHub Actions account
189214
git config user.email "github-actions[bot]@users.noreply.github.com"
190215
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
216+
# If this is a dev build and the last commit was from a dev build (detect if
217+
# "dev" was in the previous commit message), reuse the same commit.
194218
if [[ "${version}" == "dev" && `git log -1 --format='%s'` == *"dev"* ]]; then
195219
echo -e "\nAmending last commit:"
196220
git commit --amend --reset-author -m "$message"
197221
else
198222
echo -e "\nMaking a new commit:"
199223
git commit -m "$message"
200224
fi
201-
# Make the push quiet just in case there is anything that could leak
202-
# sensitive information.
225+
# Make the push quiet just in case there is anything that could leak sensitive
226+
# information.
203227
echo -e "\nPushing changes to gh-pages."
204228
git push -fq origin gh-pages 2>&1 >/dev/null
205229
echo -e "\nFinished uploading generated files."
206-
if: (github.event_name == 'release' || github.event_name == 'push') && (matrix.os == 'ubuntu-latest')

0 commit comments

Comments
 (0)