Skip to content

Commit

Permalink
CI: Refactor doc deployment
Browse files Browse the repository at this point in the history
Use a separate job to deploy docs using an uploaded artifact. This
reduces what code runs in the github pages environment, and also ensures
that job/environment is never used for a PR.
  • Loading branch information
dopplershift committed Nov 5, 2021
1 parent ec1c34a commit a827d5d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
14 changes: 9 additions & 5 deletions .github/actions/build-docs/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ inputs:
description: 'Whether the linkchecker should be run'
required: false
default: 'false'
upload-build:
description: 'Whether the build of the docs should be uploaded as an artifact.'
required: false
default: 'true'
key:
description: 'Key to use for artifacts'
required: false
Expand All @@ -17,6 +13,9 @@ outputs:
log_available:
description: 'Whether a log from the doc build is available'
value: ${{ steps.builddocs.outputs.log_available == 'true' || steps.linkchecker.outputs.log_available == 'true'}}
doc_version:
description: 'What version the docs correspond to'
value: ${{ steps.docversion.outputs.doc_version }}
runs:
using: composite
steps:
Expand Down Expand Up @@ -50,8 +49,13 @@ runs:
[ ! -s build/linkcheck/output.txt ] || (cp build/linkcheck/output.txt linkchecker.log && echo '::set-output name=log_available::true' && false)
popd
- name: Set doc version
id: docversion
shell: bash -l {0}
run: echo "::set-output name=doc_version::v$(python -c 'import metpy,re; print(re.search(r"(\d+\.\d+)", metpy.__version__)[0])')"

- name: Upload docs as artifact
if: ${{ inputs.upload-build == 'true' }}
if: ${{ always() && inputs.key != '' }}
uses: actions/upload-artifact@v2
with:
name: ${{ inputs.key }}-docs
Expand Down
26 changes: 20 additions & 6 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ jobs:
#
Docs:
name: ${{ matrix.python-version }} ${{ matrix.dep-versions }}
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
env:
DOC_VERSION: dev
environment:
name: github-pages
strategy:
fail-fast: false
matrix:
Expand All @@ -36,6 +34,8 @@ jobs:
- python-version: 3.9
check-links: true
dep-versions: requirements.txt
outputs:
doc_version: ${{ steps.build-docs.outputs.doc-version }}

steps:
# We check out only a limited depth and then pull tags to save time
Expand All @@ -58,20 +58,34 @@ jobs:
python-version: ${{ matrix.dep-versions }}

- name: Build docs
id: build-docs
uses: ./.github/actions/build-docs
with:
run-linkchecker: ${{ github.event_name == 'pull_request' && matrix.check-links == true }}
upload-build: ${{ github.event_name == 'pull_request' }}
key: ${{ runner.os }}-${{ matrix.python-version }}

Deploy:
if: ${{ github.event_name != 'pull_request' }}
needs: Docs
environment:
name: github-pages
runs-on: ubuntu-latest
env:
DOC_VERSION: dev

steps:
- name: Download doc build
uses: actions/download-artifact@v2
with:
name: Linux-3.9-docs

# This overrides the version "dev" with the proper version if we're building off a
# branch that's not main (which is confined to n.nn.x above) or on a tag.
- name: Set doc version
if: ${{ github.event_name != 'push' || !contains(github.ref, 'main') }}
run: echo "DOC_VERSION=v$(python -c 'import metpy,re; print(re.search(r"(\d+\.\d+)", metpy.__version__)[0])')" >> $GITHUB_ENV
run: echo "DOC_VERSION=v${{ needs.Docs.outputs.doc-version }}" >> $GITHUB_ENV

- name: Upload to GitHub Pages
if: ${{ github.event_name != 'pull_request' && matrix.python-version == '3.9' }}
uses: peaceiris/[email protected]
with:
deploy_key: ${{ secrets.GHPAGES_DEPLOY_KEY }}
Expand Down

0 comments on commit a827d5d

Please sign in to comment.