Skip to content

Upload the documentation as release assets #3731

Closed

Description

@seisman

The PyGMT documentation is hosted in the gh-pages branch, with docs of each PyGMT release stored in subdirectories, and docs of the main branch in the dev subdirectory.

Screenshot from 2024-12-30 15-40-06

Currently, the documentation has no backups and we may lose all the documentation in some rare cases, e.g.,

  • Accidentally delete the gh-pages branch when someone tries to clean up stale branches (happened once in the GMT repository Web documentation missing gmt#7338)
  • Changes to the "Push the built HTML to gh-pages" step in the "Docs" workflow have uncaught flaws [That's why I'm hesitating to make any changes to improve the step, since it has been working well for a long time]
  • "Push the built HTML to gh-pages" step in the "Docs" workflow fails and leads to partial uploads
  • maybe more

Technically speaking, we can restore the PyGMT documentation since,

  • we may have the gh-pages branch in our local copy (maybe not)
  • we can create local environments and rebuild the docs for each PyGMT version [It takes a lot of efforts]

I think the easiest solution is to upload the documentation of each release as release assets. Then if we lose the documentation, we just need to:

  1. create a new gh-pages branch
  2. download the documentation for each release from the release page
  3. organize the documentation into subdirectories and add them to the gh-pages branch
  4. push the docs to the remote gh-pages branch
  5. manually trigger the "Docs" workflow once

Looking at the current gh-pages branch, there are more files/directories in addition to the version subdirectories, so the above steps are not enough to restore the gh-pages branch. Here are the additional files/directories:

  • .buildinfo: This file was added 6 years ago. At that time, files were pushed to the root directory instead of subdirectories in the gh-pages branch. In other words, this file should be deleted.
  • .nojekyll: Tell GitHub to not build this branch using Jekyll [Automatically created by the workflow]
  • CNAME: Set up the docs domain (xref: https://docs.github.com/en/pages/configuring-a-custom-domain-for-your-github-pages-site/troubleshooting-custom-domains-and-github-pages#cname-errors) [It was manually added and maintained. I think we should create it automatically in the workflow]
  • index.html: The index page, redirected to /latest/ automatically [Again, this file should be automatically created in the workflow]
  • latest: Symlink to the latest release [Automatically linked to the latest version only when making a release. So it's likely we have to create the symblink manually, but it's technically possible to determine the latest version using gh release list command]
  • dev: Contains the dev docs [Automatically created by the workflow]

It agreed, here are things we need to do:

Activity

  1. added
    discussions
    on Dec 30, 2024
  2. seisman commented on Jan 6, 2025

    @seisman
    MemberAuthor

    Ping @GenericMappingTools/pygmt-maintainers for comments.

  3. weiji14 commented on Jan 6, 2025

    @weiji14
    Member
    • Accidentally delete the gh-pages branch when someone tries to clean up stale branches (happened once in the GMT repository

    I just set a branch protection rule for gh-pages to prevent accidental deletion, and it should also disable force pushes.

    I think the easiest solution is to upload the documentation of each release as release assets. Then if we lose the documentation, we just need to:

    1. create a new gh-pages branch

    2. download the documentation for each release from the release page

    3. organize the documentation into subdirectories and add them to the gh-pages branch

    4. push the docs to the remote gh-pages branch

    5. manually trigger the "Docs" workflow once

    Step 1-3 is still a lot of work 😅 I do see the value of saving the HTML documentation (or a PDF copy, xref #1606) on GitHub or Zenodo for long term archival. But for restoring the gh-pages branch, it might be easier to just mirror it on another git hosting site as we already have on https://www.dagshub.com/GenericMappingTools/pygmt/src/gh-pages, probably do it in a more systematic way.

  4. seisman commented on Jan 7, 2025

    @seisman
    MemberAuthor
    • Accidentally delete the gh-pages branch when someone tries to clean up stale branches (happened once in the GMT repository

    I just set a branch protection rule for gh-pages to prevent accidental deletion, and it should also disable force pushes.

    We can't disable force pushes, since the doc deploy script always does force pushes:

    git push -fq origin gh-pages 2>&1 >/dev/null

    I think the easiest solution is to upload the documentation of each release as release assets. Then if we lose the documentation, we just need to:

    1. create a new gh-pages branch
    2. download the documentation for each release from the release page
    3. organize the documentation into subdirectories and add them to the gh-pages branch
    4. push the docs to the remote gh-pages branch
    5. manually trigger the "Docs" workflow once

    Step 1-3 is still a lot of work 😅

    Not that much work since we can use gh release download to download the pre-uploaded docs.

    I do see the value of saving the HTML documentation (or a PDF copy, xref #1606) on GitHub or Zenodo for long term archival. But for restoring the gh-pages branch, it might be easier to just mirror it on another git hosting site as we already have on https://www.dagshub.com/GenericMappingTools/pygmt/src/gh-pages, probably do it in a more systematic way.

    Good to know that at least we have a copy on DagsHub.

    Anyway, it does no harm to upload the HTML documentation as a release asset, with a name like pygmt-v0.14.0-docs.zip?

  5. added this to the 0.15.0 milestone on Jan 7, 2025
  6. seisman commented on Jan 7, 2025

    @seisman
    MemberAuthor
    • Accidentally delete the gh-pages branch when someone tries to clean up stale branches (happened once in the GMT repository

    I just set a branch protection rule for gh-pages to prevent accidental deletion, and it should also disable force pushes.

    We can't disable force pushes, since the doc deploy script always does force pushes:

    I've enabled force pushes so that the doc deploy script can update the gh-pages branch. The branch protection rule is still useful for preventing deletion.

  7. added
    maintenance
    and removed
    discussions
    on Jan 7, 2025
  8. seisman commented on Jan 10, 2025

    @seisman
    MemberAuthor
    • Upload the documentation of old versions to the release page [manually]

    This can be done by the following commands:

    # Clone the gh-pages branch into a separate directory.
    git clone -b gh-pages [email protected]:GenericMappingTools/pygmt.git pygmt-gh-pages
    
    cd pygmt-gh-pages
    
    # Create a directory for storing the zip files
    mkdir -p zipfiles
    
    # Loop over versions, create a zip file with names pygmt-<version>-docs.zip
    for version in $(ls -1d v0.*); do 
        echo ${version}
        cp -r ${version}/ pygmt-${version}-docs/   
        zip -r zipfiles/pygmt-${version}-docs.zip pygmt-${version}-docs/                    
        rm -r pygmt-${version}-docs  
    done

    The above commands create zip files with name pygmt-<version>-docs.zip and the directory inside the ZIP files also have the same name.

    Then we can upload them as release assets using the command below (not tested yet):

    for version in $(ls -1d v0.*); do 
        gh release upload $version zipfiles/pygmt-${version}-docs.zip
    done

    Please let me know if you have any comments before I take actions.

  9. self-assigned this
    on Jan 10, 2025
  10. seisman commented on Jan 11, 2025

    @seisman
    MemberAuthor

    After thinking twice, maybe we should just name the zip files like pygmt-docs.zip without the version string, similar to what we're doing to the baseline-images.zip.

    Then the commands will be:

    # Clone the gh-pages branch into a separate directory.
    git clone -b gh-pages [email protected]:GenericMappingTools/pygmt.git pygmt-gh-pages
    
    cd pygmt-gh-pages
    
    # Create a directory for storing the zip files
    mkdir -p zipfiles
    
    # Loop over versions, create a zip file with names pygmt-docs.zip
    for version in $(ls -1d v0.*); do 
        echo ${version}
        cp -r ${version}/ pygmt-docs/
        mkdir -p zipfiles/${version}/
        zip -r zipfiles/${version}/pygmt-docs.zip pygmt-docs/                    
        rm -r pygmt-docs  
    done
    

    and

    for version in $(ls -1d v0.*); do 
        gh release upload $version zipfiles/${version}/pygmt-docs.zip
    done
    
  11. seisman commented on Feb 8, 2025

    @seisman
    MemberAuthor

    In PR #3765, we started to build the PDF documentation, but the PDF file is not deployed anywhere. Now it's time to discuss how we'd like to deploy the HTML and PDF files.

    Here is a summary of the current behaviors:

    HTML PDF
    In PR Build Build
    Push to main (dev) Build + Deploy to the dev folder Build only
    Release Build + Deploy to the vX.Y.Z folder Build only

    In this issue, I've proposed to create the HTML documentation ZIP archive and upload it as a release asset. We should do the same thing for the PDF file, too. Then, we can add links to the HTML ZIP and PDF files on the sidebar. As for the dev version, we can just copy the HTML ZIP archive and PDF files into the dev folder.

    The expected behaviors are (bold marks the behavior changes):

    HTML HTML ZIP PDF
    In PR Build Create Build
    Push to main (dev) Build + Deploy to the dev folder Create and copy to the dev folder Build + Copy to the dev folder
    Release Build + Deploy to the vX.Y.Z folder Create + Upload as release asset Build + Upload as release asset

    #3794 is the POC PR implementing the proposed changes.

  12. seisman commented on Feb 19, 2025

    @seisman
    MemberAuthor

    After thinking twice, maybe we should just name the zip files like pygmt-docs.zip without the version string, similar to what we're doing to the baseline-images.zip.

    Then the commands will be:

    # Clone the gh-pages branch into a separate directory.
    git clone -b gh-pages [email protected]:GenericMappingTools/pygmt.git pygmt-gh-pages
    
    cd pygmt-gh-pages
    
    # Create a directory for storing the zip files
    mkdir -p zipfiles
    
    # Loop over versions, create a zip file with names pygmt-docs.zip
    for version in $(ls -1d v0.*); do 
        echo ${version}
        cp -r ${version}/ pygmt-docs/
        mkdir -p zipfiles/${version}/
        zip -r zipfiles/${version}/pygmt-docs.zip pygmt-docs/                    
        rm -r pygmt-docs  
    done
    

    and

    for version in $(ls -1d v0.*); do 
        gh release upload $version zipfiles/${version}/pygmt-docs.zip
    done
    

    I've manually uploaded the pygmt-docs.zip files for old versions using the above commands.

  13. seisman commented on Feb 19, 2025

    @seisman
    MemberAuthor

    The expected behaviors are (bold marks the behavior changes):

    HTML HTML ZIP PDF
    In PR Build Create Build
    Push to main (dev) Build + Deploy to the dev folder Create and copy to the dev folder Build + Copy to the dev folder
    Release Build + Deploy to the vX.Y.Z folder Create + Upload as release asset Build + Upload as release asset

    After #3814 and #3794, we have PDF and HTML ZIP files deployed/uploaded.

    For releases, the permanent links are:

    • https://github.com/GenericMappingTools/pygmt/releases/download/<version>/pygmt-docs.zip
    • https://github.com/GenericMappingTools/pygmt/releases/download/<version>/pygmt-docs.pdf

    For dev versions, the permanent links are:

    We need to add these links to the website. There are two options:

    1. On the sidebar
    2. On the "Minimum Supported Versions" page

    Debating which one is better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

maintenance

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions