Giter Club home page Giter Club logo

rtds-action's Introduction

Interface Read the Docs and GitHub Actions

Docs Documentation Status

I like to use Read the Docs to build (and version!) my docs, but I also like to use Jupyter notebooks to write tutorials. Unfortunately, even though notebooks can be executed on Read the Docs, some of them take a very long time to run or need special Docker environments to execute, which goes beyond what the platform supports. In these cases I needed to check executed notebooks (often with large images) into my git repository, causing huge amounts of bloat. Futhermore, the executed notebooks would often get out of sync with the development of the code. No more!!

This library avoids these issues by executing code on GitHub Actions, uploading build artifacts (in this case, executed Jupter notebooks), and then (only then!) triggering a Read the Docs build that can download the executed notebooks.

There is still some work required to set up this workflow, but this library has three pieces that make it a bit easier:

  1. A GitHub action that can be used to trigger a build for the current branch on Read the Docs.
  2. A Sphinx extension that interfaces with the GitHub API to download the artifact produced for the target commit hash.
  3. Some documentation that shows you how to set all this up!

Usage

The following gives the detailed steps of the process of setting up a project using this workflow. But you can also see a fully functional example in this repository. The documentation source is the docs directory and the .github/workflows directory includes a workflow that is executed to build the docs using this package. The rendered page is available at rtds-action.readthedocs.io.

1. Set up Read the Docs

  1. First, you'll need to import your project as usual. If you've already done that, don't worry: this will also work with existing Read the Docs projects.
  2. Next, go to the admin page for your project on Read the Docs, click on Integrations (the URL is something like https://readthedocs.org/dashboard/YOUR_PROJECT_NAME/integrations/).
  3. Click Add integration and select Generic API incoming webhook.
  4. Take note of the webhook URL and token on this page for use later.

You should also edit your webhook settings on GitHub by going to https://github.com/USERNAME/REPONAME/settings/hooks and clicking "Edit" next to the Read the Docs hook. On that page, you should un-check the Pushes option.

2. Set up GitHub Actions workflow

In this example, we'll assume that we have tutorials written as Jupyter notebooks, saved as Python scripts using Jupytext (because that's probably what you should be doing anyways!) in a directory called docs/tutorials.

First, you'll need to add the Read the Docs webhook URL and token that you recorded above as "secrets" for your GitHub project by going to the URL https://github.com/USERNAME/REPONAME/settings/secrets. I'll call them RTDS_WEBHOOK_URL (include the https!) and RTDS_WEBHOOK_TOKEN respectively.

For this use case, we can create the workflow .github/workflows/docs.yml as follows:

name: Docs
on: [push, release]

jobs:
  notebooks:
    name: "Build the notebooks for the docs"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - name: Set up Python
        uses: actions/setup-python@v2
        with:
          python-version: 3.8

      - name: Install dependencies
        run: |
          python -m pip install -U pip
          python -m pip install -r .github/workflows/requirements.txt

      - name: Execute the notebooks
        run: |
          jupytext --to ipynb --execute docs/tutorials/*.py

      - uses: actions/upload-artifact@v2
        with:
          name: notebooks-for-${{ github.sha }}
          path: docs/tutorials

      - name: Trigger RTDs build
        uses: dfm/rtds-action@v1
        with:
          webhook_url: ${{ secrets.RTDS_WEBHOOK_URL }}
          webhook_token: ${{ secrets.RTDS_WEBHOOK_TOKEN }}
          commit_ref: ${{ github.ref }}

Here, we're also assuming that we've added a pip requirements file at .github/workflows/requirements.txt with the dependencies required to execute the notebooks. Also note that in the upload-artifact step we give our artifact that depends on the hash of the current commit. This is crucial! We also need to take note of the notebooks-for- prefix because we'll use that later.

It's worth emphasizing here that the only "special" steps in this workflow are the last two. You can do whatever you want to generate your artifact in the previous steps (for example, you could use conda instead of pip) because this workflow is not picky about how you get there!

3. Set up Sphinx

Finally, you can edit the conf.py for your Sphinx documentation to add support for fetching the artifact produced by your action. Here is a minimal example:

import os

extensions = [... "rtds_action"]

# The name of your GitHub repository
rtds_action_github_repo = "USERNAME/REPONAME"

# The path where the artifact should be extracted
# Note: this is relative to the conf.py file!
rtds_action_path = "tutorials"

# The "prefix" used in the `upload-artifact` step of the action
rtds_action_artifact_prefix = "notebooks-for-"

# A GitHub personal access token is required, more info below
rtds_action_github_token = os.environ["GITHUB_TOKEN"]

# Whether or not to raise an error on Read the Docs if the
# artifact containing the notebooks can't be downloaded (optional)
rtds_action_error_if_missing = False

Where we have added the custom extension and set the required configuration parameters.

You'll need to provide Read the Docs with a GitHub personal access token (it only needs the public_repo scope if your repo is public). You can generate a new token by going to your GitHub settings page. Then, save it as an environment variable (called GITHUB_TOKEN in this case) on Read the Docs.

Development

For now, just a note: if you edit src/js/index.js, you must run npm run package to generate the compiled action source.

rtds-action's People

Contributors

astrojuanlu avatar bsipocz avatar dependabot[bot] avatar dfm avatar maikia avatar rodluger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

rtds-action's Issues

publishing current version?

Hey first of all I love this extension and the workflow! Thank you for the great extension!

I realize there're some difference between the current github version and the published 1.0.2.
Specifically I'm looking for the rtds_action_error_if_missing config, which is documented on github but doesn't seem to be available with 1.0.2.

This would be really helpful for my workflow, since currently the artifacts are only available on github after the full workflow has finished, but the rtd build was triggered much earlier, and I would much prefer an old version/failed build instead of a new one without the notebooks.

So just wondering whether there's any plan to release the current version soon?

Action running but not triggering the RTD build (for pull requests)

We're trying to get GitHub actions to run our example notebooks for in the documentation. After following the instructions on the Readme, we run into the problem where the build is not triggered. I've seen the other issues that seem to refer to similar problems (#1, #13, #16), but reading those discussions hasn't helped me solve my problem just yet, hence the new issue.

This is the response from RTD:

{
  "build_triggered": false,
  "project": "pastas",
  "versions": []
}

See the more detailed result from RTD/Integrations/Generic API incoming webhook:

image

So is there something I can do get GH Actions to manage to trigger RTD?

Further info:

The RTD webhook in GH Actions is configured with only the following two events selected:
image

Additionally, when I manually add the source branch for the PR to RTD and manually trigger a docs build, the commit hash doesn't correspond to the artifact name on GitHub, which i guess is expected but I wonder if there is a way to get them to match somehow.

Example GH Actions workflow run: https://github.com/pastas/pastas/actions/runs/4936253855/jobs/8823565728

Example RTD manual build: https://readthedocs.org/projects/pastas/builds/20585343/

Unrelated, but I also saw that GitHub is warning about the rtds-action using an outdated version of Node.js (12, when it wants 16 apparently).

Thanks in advance for your time and help!

multiple notebook locations

Is it possible to upload notebooks from multiple locations?

For example, I have some folders for thumbnail galleries and some for tutorials but separated.

docs/
|_______gallery/ *.py
|
|_______tutorials/ *.py

README example says to use @v1, but this is not an available version

From the example workflow in the README:

      - name: Trigger RTDs build
        uses: dfm/rtds-action@v1

However, when using this, I got the following error:

An action could not be found at the URI 'https://api.github.com/repos/dfm/rtds-action/tarball/v1'

Instead, it should be @v1.0.2.

Support auto-building PR docs

Have been successfully using rtds-action for a few repos but for some reason the rtds is not being triggered on one of the repos now. I haven't been able to identify anything obvious. I have reset the Generic API incoming webhook on rtds and the secrets on github.

I noticed that the latest Docs action on rtds-action had the same message "build_triggered: false".

Not sure if this is a rtds-action or rtd issue. Any idea?

node.js deprecation warning

I see this warning while using this action. While the fix is easy, it would require a new release, too:


Trigger a ReadTheDocs build
Node.js 12 actions are deprecated. Please update the following actions to use Node.js 16: dfm/rtds-action@v1. For more information see: https://github.blog/changelog/2022-09-22-github-actions-all-actions-will-begin-running-on-node16-instead-of-node12/.

Clarify use case of this action

Hi! ๐Ÿ‘‹๐Ÿฝ It's Juan Luis from Read the Docs here (and former Astropy core developer โœจ ). A user of RTD is using rtds-action and I have some questions ๐Ÿ˜„

Once I got the mechanism (that Sphinx grabs the artifacts from GitHub on build time), I found it to be quite smart! And in fact, it could be useful for many other use cases beyond Jupyter notebooks.

However, from the README:

rtds-action/README.md

Lines 6 to 11 in 66a4e12

I like to use [ReadTheDocs](https://readthedocs.org/) to build (and version!) my
docs, but I _also_ like to use [Jupyter notebooks](https://jupyter.org/) to
write tutorials. Unfortunately, this has always meant that I needed to check
executed notebooks (often with large images) into my git repository, causing
huge amounts of bloat. Futhermore, the executed notebooks would often get out of
sync with the development of the code. **No more!!**

A personal project I maintain uses notebooks with uncommitted outputs + RTD just fine - in fact, they are in the myst format from jupytext, so they can't possibly hold any output. nbsphinx executes them on RTD just fine, with this result.

Therefore, the intro paragraph from the README strikes me as slightly confusing or misleading.

I understand that this action is most useful when notebooks take a lot of time to render (~hours or more) or require some special requirement that is unsupported on RTD (that is, something that can't be installed either with apt @ Ubuntu 20.04 or with conda/mamba from conda-forge). Am I right? Or am I missing anything?

I'm happy to learn more about how folks are using this action, and if any of the limitations could be addressed on the Read the Docs side. Also, if you agree that the intro paragraph could be refined a bit to provide better guidance, I'll be glad to send a PR or review one.

What are RTDS_WEBHOOK_URL and RTDS_WEBHOOK_TOKEN

Hi, I am trying to setup this action but i don't get what are the secrets to use. I went to integration on readthedoc and I only see one url:
https://readthedocs.org/api/v2/webhook/my_packege_name/a_number/
Is:
RTDS_WEBHOOK_URL = https://readthedocs.org/api/v2/webhook/my_packege_name/
and
RTDS_WEBHOOK_TOKEN = a_number?
Thanks in advance!

Action runs but does not trigger build

We are using the rtds-action in the CI of our project to render some .qmd tutorial files before building the documentation. A few days ago, everything worked as expected.

Now, while the weebhook does still reach readthedocs, it does not trigger a build:

{
  "build_triggered": false,
  "project": "liesel",
  "versions": []
}

I am at a loss in terms of how to debug this - and I don't know whether it's a user-problem or a bug in the action. We observed this the first time after we made a new release on GitHub. Would be thankful for some guidance.

invalid json response error

Hello, I'm getting the following error on an action run recently. Seems there might be some API change on rtd side? Let me know if I can provide more info!

Run dfm/rtds-action@v1
  with:
    webhook_url: ***
    webhook_token: ***
    commit_ref: refs/pull/207/merge
  env:
    CONDA_PKGS_DIR: /home/runner/conda_pkgs_dir
Error: invalid json response body at *** reason: Unexpected token < in JSON at position 0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.