|
| 1 | +# This workflow installs PyGMT, builds and deploys documentation |
| 2 | + |
| 3 | +name: Docs |
| 4 | + |
| 5 | +on: |
| 6 | + push: |
| 7 | + branches: [ master ] |
| 8 | + pull_request: |
| 9 | + types: [opened, reopened, synchronize, ready_for_review] |
| 10 | + paths-ignore: |
| 11 | + - 'pygmt/tests/**' |
| 12 | + - '*.md' |
| 13 | + - '*.json' |
| 14 | + - 'LICENSE.txt' |
| 15 | + - '.gitignore' |
| 16 | + - '.pylintrc' |
| 17 | + release: |
| 18 | + types: |
| 19 | + - published |
| 20 | + |
| 21 | +jobs: |
| 22 | + docs: |
| 23 | + name: ${{ matrix.os }} - Python ${{ matrix.python-version }} |
| 24 | + runs-on: ${{ matrix.os }} |
| 25 | + strategy: |
| 26 | + fail-fast: false |
| 27 | + matrix: |
| 28 | + python-version: [3.9] |
| 29 | + os: [ubuntu-latest, macOS-latest, windows-latest] |
| 30 | + # Is it a draft Pull Request (true or false)? |
| 31 | + isDraft: |
| 32 | + - ${{ github.event.pull_request.draft }} |
| 33 | + # Only run one job (Ubuntu + Python 3.9) for draft PRs |
| 34 | + exclude: |
| 35 | + - os: macOS-latest |
| 36 | + isDraft: true |
| 37 | + - os: windows-latest |
| 38 | + isDraft: true |
| 39 | + defaults: |
| 40 | + run: |
| 41 | + shell: bash -l {0} |
| 42 | + |
| 43 | + steps: |
| 44 | + # Cancel previous runs that are not completed |
| 45 | + - name: Cancel Previous Runs |
| 46 | + |
| 47 | + with: |
| 48 | + access_token: ${{ github.token }} |
| 49 | + |
| 50 | + # Checkout current git repository |
| 51 | + - name: Checkout |
| 52 | + |
| 53 | + with: |
| 54 | + # fecth all history so that setuptools-scm works |
| 55 | + fetch-depth: 0 |
| 56 | + |
| 57 | + # Setup Miniconda |
| 58 | + - name: Setup Miniconda |
| 59 | + uses: conda-incubator/[email protected] |
| 60 | + with: |
| 61 | + activate-environment: pygmt |
| 62 | + python-version: ${{ matrix.python-version }} |
| 63 | + channels: conda-forge |
| 64 | + miniconda-version: "latest" |
| 65 | + |
| 66 | + # Install GMT and other required dependencies from conda-forge |
| 67 | + - name: Install dependencies |
| 68 | + run: | |
| 69 | + conda install gmt=6.1.1 numpy pandas xarray netCDF4 packaging \ |
| 70 | + ipython make myst-parser \ |
| 71 | + sphinx sphinx-copybutton sphinx-gallery sphinx_rtd_theme=0.4.3 |
| 72 | +
|
| 73 | + # Show installed pkg information for postmortem diagnostic |
| 74 | + - name: List installed packages |
| 75 | + run: conda list |
| 76 | + |
| 77 | + # Download cached remote files (artifacts) from GitHub |
| 78 | + - name: Download remote data from GitHub |
| 79 | + |
| 80 | + with: |
| 81 | + workflow: cache_data.yaml |
| 82 | + workflow_conclusion: success |
| 83 | + name: gmt-cache |
| 84 | + path: .gmt |
| 85 | + |
| 86 | + # Move downloaded files to ~/.gmt directory and list them |
| 87 | + - name: Move and list downloaded remote files |
| 88 | + run: | |
| 89 | + mkdir -p ~/.gmt |
| 90 | + mv .gmt/* ~/.gmt |
| 91 | + # Change modification times of the two files, so GMT won't refresh it |
| 92 | + touch ~/.gmt/server/gmt_data_server.txt ~/.gmt/server/gmt_hash_server.txt |
| 93 | + ls -lhR ~/.gmt |
| 94 | +
|
| 95 | + # Install the package that we want to test |
| 96 | + - name: Install the package |
| 97 | + run: | |
| 98 | + python setup.py sdist --formats=zip |
| 99 | + pip install dist/* |
| 100 | +
|
| 101 | + # Build the documentation |
| 102 | + - name: Build the documentation |
| 103 | + run: make -C doc clean all |
| 104 | + |
| 105 | + - name: Checkout the gh-pages branch |
| 106 | + uses: actions/checkout@28c7f3d2b5162b5ddd3dfd9a45aa55eaf396478b |
| 107 | + with: |
| 108 | + ref: gh-pages |
| 109 | + # Checkout to this folder instead of the current one |
| 110 | + path: deploy |
| 111 | + # Download the entire history |
| 112 | + fetch-depth: 0 |
| 113 | + if: (github.event_name == 'release' || github.event_name == 'push') && (matrix.os == 'ubuntu-latest') |
| 114 | + |
| 115 | + - name: Push the built HTML to gh-pages |
| 116 | + run: | |
| 117 | + # Detect if this is a release or from the master branch |
| 118 | + if [[ "${GITHUB_EVENT_NAME}" == "release" ]]; then |
| 119 | + # Get the tag name without the "refs/tags/" part |
| 120 | + version="${GITHUB_REF#refs/*/}" |
| 121 | + else |
| 122 | + version=dev |
| 123 | + fi |
| 124 | + echo "Deploying version: $version" |
| 125 | + # Make the new commit message. Needs to happen before cd into deploy |
| 126 | + # to get the right commit hash. |
| 127 | + message="Deploy $version from $(git rev-parse --short HEAD)" |
| 128 | + cd deploy |
| 129 | + # Need to have this file so that Github doesn't try to run Jekyll |
| 130 | + touch .nojekyll |
| 131 | + # Delete all the files and replace with our new set |
| 132 | + echo -e "\nRemoving old files from previous builds of ${version}:" |
| 133 | + rm -rvf ${version} |
| 134 | + echo -e "\nCopying HTML files to ${version}:" |
| 135 | + cp -Rvf ../doc/_build/html/ ${version}/ |
| 136 | + # If this is a new release, update the link from /latest to it |
| 137 | + if [[ "${version}" != "dev" ]]; then |
| 138 | + echo -e "\nSetup link from ${version} to 'latest'." |
| 139 | + rm -f latest |
| 140 | + ln -sf ${version} latest |
| 141 | + fi |
| 142 | + # Stage the commit |
| 143 | + git add -A . |
| 144 | + echo -e "\nChanges to be applied:" |
| 145 | + git status |
| 146 | + # Configure git to be the GitHub Actions account |
| 147 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 148 | + git config user.name "github-actions[bot]" |
| 149 | + # If this is a dev build and the last commit was from a dev build |
| 150 | + # (detect if "dev" was in the previous commit message), reuse the |
| 151 | + # same commit |
| 152 | + if [[ "${version}" == "dev" && `git log -1 --format='%s'` == *"dev"* ]]; then |
| 153 | + echo -e "\nAmending last commit:" |
| 154 | + git commit --amend --reset-author -m "$message" |
| 155 | + else |
| 156 | + echo -e "\nMaking a new commit:" |
| 157 | + git commit -m "$message" |
| 158 | + fi |
| 159 | + # Make the push quiet just in case there is anything that could leak |
| 160 | + # sensitive information. |
| 161 | + echo -e "\nPushing changes to gh-pages." |
| 162 | + git push -fq origin gh-pages 2>&1 >/dev/null |
| 163 | + echo -e "\nFinished uploading generated files." |
| 164 | + if: (github.event_name == 'release' || github.event_name == 'push') && (matrix.os == 'ubuntu-latest') |
0 commit comments