Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: Separate jobs to build and deploy documentation #3767

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 42 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,27 @@ jobs:
- name: Build the documentation
run: make -C doc clean all

- name: Upload HMTL 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 +167,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 HTML 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 +184,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 +199,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 +213,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')
Loading