Skip to content

Commit

Permalink
CI: Separate jobs to build and deploy documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
seisman committed Jan 12, 2025
1 parent 77a2d59 commit 689ee4c
Showing 1 changed file with 43 additions and 19 deletions.
62 changes: 43 additions & 19 deletions .github/workflows/ci_docs.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
# Build and deploy documentation
# Build and deploy documentation.
#
# This workflow builds the documentation on Linux/macOS/Windows.
#
# It is run on every commit to the main and pull request branches, and also
# when a new release is published.
# In draft pull requests, only the job on Linux is triggered to save on
# Continuous Integration resources.
# It is run on every commit to the main and pull request branches, and also when a new
# release is published. In draft pull requests, only the job on Linux is triggered to
# save on Continuous Integration resources.
#
# On the main branch, the workflow also handles the documentation deployment:
#
# * Updating the development documentation by pushing the built HTML pages
# from the main branch onto the dev folder of the gh-pages branch.
# * Updating the development documentation by pushing the built HTML pages from the main
# branch onto the dev folder of the gh-pages branch.
# * Updating the latest documentation link to the new release.
#
name: Docs
Expand Down Expand Up @@ -44,7 +43,7 @@ concurrency:
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

jobs:
docs:
build-docs:
name: ${{ matrix.os }}
runs-on: ${{ matrix.os }}
if: github.repository == 'GenericMappingTools/pygmt'
Expand Down Expand Up @@ -139,6 +138,28 @@ jobs:
- name: Build the documentation
run: make -C doc clean all

# Upload documentation artifact
- name: Upload documentation artifact
uses: actions/[email protected]
with:
name: pygmt-docs-html
path: doc/_build/html/
if: matrix.os == 'ubuntu-latest'

deploy-docs:
name: Deploy documentation
needs: build-docs
runs-on: ubuntu-latest
if: (github.event_name == 'release' || github.event_name == 'push') && github.repository == 'GenericMappingTools/pygmt'

steps:
# Checkout current git repository
- name: Checkout
uses: actions/[email protected]
with:
# fetch all history so that setuptools-scm works
fetch-depth: 0

- name: Checkout the gh-pages branch
uses: actions/[email protected]
with:
Expand All @@ -147,7 +168,12 @@ jobs:
path: deploy
# Download the entire history
fetch-depth: 0
if: (github.event_name == 'release' || github.event_name == 'push') && (matrix.os == 'ubuntu-latest')

- name: Download documentation artifact
uses: actions/[email protected]
with:
name: pygmt-docs-html
path: pygmt-docs-html

- name: Push the built HTML to gh-pages
run: |
Expand All @@ -159,10 +185,10 @@ jobs:
version=dev
fi
echo "Deploying version: $version"
# Make the new commit message. Needs to happen before cd into deploy
# to get the right commit hash.
# Make the new commit message. Needs to happen before cd into deploy to get
# the right commit hash.
message="Deploy $version from $(git rev-parse --short HEAD)"
cd deploy
cd deploy/
# Create some files in the root directory.
# .nojekyll: Need to have this file so that GitHub doesn't try to run Jekyll
touch .nojekyll
Expand All @@ -174,7 +200,7 @@ jobs:
echo -e "\nRemoving old files from previous builds of ${version}:"
rm -rvf ${version}
echo -e "\nCopying HTML files to ${version}:"
cp -Rvf ../doc/_build/html/ ${version}/
cp -Rvf ../pygmt-docs-html/ ${version}/
# If this is a new release, update the link from /latest to it
if [[ "${version}" != "dev" ]]; then
echo -e "\nSetup link from ${version} to 'latest'."
Expand All @@ -188,19 +214,17 @@ jobs:
# Configure git to be the GitHub Actions account
git config user.email "github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
# If this is a dev build and the last commit was from a dev build
# (detect if "dev" was in the previous commit message), reuse the
# same commit
# If this is a dev build and the last commit was from a dev build (detect if
# "dev" was in the previous commit message), reuse the same commit.
if [[ "${version}" == "dev" && `git log -1 --format='%s'` == *"dev"* ]]; then
echo -e "\nAmending last commit:"
git commit --amend --reset-author -m "$message"
else
echo -e "\nMaking a new commit:"
git commit -m "$message"
fi
# Make the push quiet just in case there is anything that could leak
# sensitive information.
# Make the push quiet just in case there is anything that could leak sensitive
# information.
echo -e "\nPushing changes to gh-pages."
git push -fq origin gh-pages 2>&1 >/dev/null
echo -e "\nFinished uploading generated files."
if: (github.event_name == 'release' || github.event_name == 'push') && (matrix.os == 'ubuntu-latest')

0 comments on commit 689ee4c

Please sign in to comment.