You may be familiar with GitHub Actions: it is a widely used continuous integration tool which can easily and automatically publish your Jupyter Book as a website. This lesson is designed to get you familiar with GitHub Actions in your Jupyter Book and learn how to manipulate them.
What is GitHub Actions?
If you have no idea, or are confused what an Action is, don’t despair! The most simple explanation is that GHA is a tool for automating workflows. For our purposes, everything you need to know is described in this dropdown tip.
“GitHub Actions” is GitHub’s product name for its Continuous Integration / Continuous Deployment (CI/CD) services: if this term is unfamiliar, it’s not important, as you can simply think of CI/CD and GH Actions as an algorithm that can be carried out on your GitHub repository automatically. It is the “workflow automation” framework that sometimes seem like magic to the outside observer.
Within GHA, “workflows” are defined using .yml files in the .github/workflows folder of a repository.
Each workflow can be triggered by one or more events, for example, a commit is pushed to the repository.
Each workflows can have multiple steps (e.g. install software, build the book, deploy the book), and as many steps are repeated, it is possible to find pre-built “actions” in an online marketplace.
In addition, workflows can include arbitrary code (e.g., bash or Python scripts).
GHA is generally free for public repositories, with some limitations on usage for private repositories.
By the end of this workshop you will read and modify workflow files to customize the build and deployment of your Jupyter Book.
Read it¶
In your folder of the repository there is a hidden folder called .github, and inside that is another folder called workflows.
Inside that folder is a file called deploy.yml (or similar).
This file defines the workflow that builds and deploys your Jupyter Book to GitHub Pages.
Observe it¶
Now that you have seen the “steps” of the workflow, it is good to see them “in action” in the Browser.
Make a commit and push it to your repository. Then visit the “Actions” tab and watch the workflow execute. Specifically, note:
the green, yellow or red “dot” indicating status of the workflow,
when you click on the most recent workflow run, you will see a summary of the job,
after clicking on the “box” in the workflow diagram, you can see all of the workflow steps,
you can investigate each step to see the command line output.
Understanding where this information is available in your repository is especially useful when debugging problems with your website and PDF build. It is also important to know that this is where you can search for error logs (in the CLI), especially when problems may not occur in your local setup, but your website is not deploying properly.
Break it¶
To make sure you know what a “problem” looks like, we can intentionally break the workflow.
Introduce an error in the workflow and watch the Actions and workflow pages to observe what it looks like when an error occurs.
There are many ways to accomplish this; perhaps the easiest would be to modify the terminal commands in one of the workflow steps (e.g., replace jupyter book build with jupyter book break, which does not exist).
Revert the error afterwards.
Change it¶
Here we will modify the workflow to add a new feature: automatically updating the “last edited” date in our published book.
The following bash script will modify date: field in the myst.yml file:
- name: Add current date to myst.yml
shell: bash
run: |
BUILD_DATE="$(date +'%Y-%m-%d')"
sed -i "s|\${BUILD_DATE}|${BUILD_DATE}|g" myst.yml
echo "myst.yml:"
grep -nE '^\s*date:' myst.ymlIn addition, this simple script requires setting ${BUILD_DATE} for the date field value in myst.yml.
Modify deploy.yml to implement the feature.
Confirm this was done successfully by checking the rendered website online.
Although the time is not displayed in our update, what is the actual date and time that is represented in the value BUILD_DATE?
A. time that file was edited
B. time of commit
C. time of push
D. other
Check your answer
The answer is D, other. The time represented by BUILD_DATE corresponds to the moment when the first line in the code snippet added to the workflow file was executed in the cloud. It is closest to the time of the push, plus the extra time needed to set up the virtual environment and start the book build process.