Skip to content

Commit 05fd428

Browse files
committed
CI: Separate jobs to build and deploy documentation
1 parent dbaacd6 commit 05fd428

File tree

1 file changed

+41
-15
lines changed

1 file changed

+41
-15
lines changed

.github/workflows/ci_docs.yml

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Build and deploy documentation
1+
# Build and deploy documentation.
22
#
33
# This workflow builds the documentation on Linux/macOS/Windows.
44
#
@@ -42,11 +42,10 @@ concurrency:
4242
group: ${{ github.workflow }}-${{ github.ref }}
4343
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
4444

45-
permissions:
46-
contents: write
45+
permissions: {}
4746

4847
jobs:
49-
docs:
48+
build-docs:
5049
name: ${{ matrix.os }}
5150
runs-on: ${{ matrix.os }}
5251
if: github.repository == 'GenericMappingTools/pygmt'
@@ -168,6 +167,30 @@ jobs:
168167
GH_TOKEN: ${{ github.token }}
169168
REF_NAME: ${{ github.ref_name }}
170169

170+
- name: Upload HMTL documentation artifact
171+
uses: actions/[email protected]
172+
with:
173+
name: pygmt-docs-html
174+
path: doc/_build/html/
175+
if: matrix.os == 'ubuntu-latest'
176+
177+
deploy-docs:
178+
name: Deploy documentation
179+
needs: build-docs
180+
runs-on: ubuntu-latest
181+
if: (github.event_name == 'release' || github.event_name == 'push') && github.repository == 'GenericMappingTools/pygmt'
182+
permissions:
183+
contents: write
184+
185+
steps:
186+
# Checkout current git repository
187+
- name: Checkout
188+
uses: actions/[email protected]
189+
with:
190+
# fetch all history so that setuptools-scm works
191+
fetch-depth: 0
192+
persist-credentials: false
193+
171194
- name: Checkout the gh-pages branch
172195
uses: actions/[email protected]
173196
with:
@@ -177,7 +200,12 @@ jobs:
177200
# Download the entire history
178201
fetch-depth: 0
179202
persist-credentials: true
180-
if: (github.event_name == 'release' || github.event_name == 'push') && (matrix.os == 'ubuntu-latest')
203+
204+
- name: Download HTML documentation artifact
205+
uses: actions/[email protected]
206+
with:
207+
name: pygmt-docs-html
208+
path: pygmt-docs-html
181209

182210
- name: Push the built HTML to gh-pages
183211
run: |
@@ -189,10 +217,10 @@ jobs:
189217
version=dev
190218
fi
191219
echo "Deploying version: $version"
192-
# Make the new commit message. Needs to happen before cd into deploy
193-
# to get the right commit hash.
220+
# Make the new commit message. Needs to happen before cd into deploy to get
221+
# the right commit hash.
194222
message="Deploy $version from $(git rev-parse --short HEAD)"
195-
cd deploy
223+
cd deploy/
196224
# Create some files in the root directory.
197225
# .nojekyll: Need to have this file so that GitHub doesn't try to run Jekyll
198226
touch .nojekyll
@@ -204,7 +232,7 @@ jobs:
204232
echo -e "\nRemoving old files from previous builds of ${version}:"
205233
rm -rvf ${version}
206234
echo -e "\nCopying HTML files to ${version}:"
207-
cp -Rvf ../doc/_build/html/ ${version}/
235+
cp -Rvf ../pygmt-docs-html/ ${version}/
208236
# If this is a new release, update the link from /latest to it
209237
if [[ "${version}" != "dev" ]]; then
210238
echo -e "\nSetup link from ${version} to 'latest'."
@@ -218,19 +246,17 @@ jobs:
218246
# Configure git to be the GitHub Actions account
219247
git config user.email "github-actions[bot]@users.noreply.github.com"
220248
git config user.name "github-actions[bot]"
221-
# If this is a dev build and the last commit was from a dev build
222-
# (detect if "dev" was in the previous commit message), reuse the
223-
# same commit
249+
# If this is a dev build and the last commit was from a dev build (detect if
250+
# "dev" was in the previous commit message), reuse the same commit.
224251
if [[ "${version}" == "dev" && `git log -1 --format='%s'` == *"dev"* ]]; then
225252
echo -e "\nAmending last commit:"
226253
git commit --amend --reset-author -m "$message"
227254
else
228255
echo -e "\nMaking a new commit:"
229256
git commit -m "$message"
230257
fi
231-
# Make the push quiet just in case there is anything that could leak
232-
# sensitive information.
258+
# Make the push quiet just in case there is anything that could leak sensitive
259+
# information.
233260
echo -e "\nPushing changes to gh-pages."
234261
git push -fq origin gh-pages 2>&1 >/dev/null
235262
echo -e "\nFinished uploading generated files."
236-
if: (github.event_name == 'release' || github.event_name == 'push') && (matrix.os == 'ubuntu-latest')

0 commit comments

Comments
 (0)