Skip to content

Commit 672aecc

Browse files
Merge pull request #82 from TeachBooks/rlanzafame-patch-1
Improved README.md description
2 parents 0661900 + 40438af commit 672aecc

File tree

2 files changed

+63
-10
lines changed

2 files changed

+63
-10
lines changed

.github/workflows/deploy-book.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,18 @@ env:
2323
GH_TOKEN: ${{ secrets.GH_PAT != '' && secrets.GH_PAT || secrets.GITHUB_TOKEN }}
2424

2525
# Branch shown on root (eg. teachbooks.github.io/template/).
26-
# `main` as primary by default, advised to use branch with most recent content.
26+
# - `main` as primary by default (eg. teachbooks.github.io/template/main/)
27+
# Advised to use default branch or that with which active users (eg. students) read.
2728
PRIMARY_BRANCH: ${{ vars.PRIMARY_BRANCH != '' && vars.PRIMARY_BRANCH || 'main' }}
2829

2930
# Determines how the PRIMARY_BRANCH is handled at the root of the website:
30-
# - 'copy': Copies the contents of the PRIMARY_BRANCH to the root directory.
3131
# - 'redirect': Redirects the root URL to the PRIMARY_BRANCH (default behavior).
32+
# - 'copy': Copies the contents of the PRIMARY_BRANCH to the root directory.
3233
# - 'move': Moves the contents of the PRIMARY_BRANCH to the root directory and removes it from its branch-specific URL.
3334
# By default, redirects to PRIMARY_BRANCH ('redirect').
3435
# Use 'redirect' if you expect to archive a version in the future so that the URL doesn't change for the reader.
36+
# Use 'copy' or 'move' if you plan to use the root URL only and don't need the URL containing the branch or alias name.
37+
# Use 'move' instead of 'copy' to avoid saving build artifact unnecessarily.
3538
BEHAVIOR_PRIMARY: ${{ vars.BEHAVIOR_PRIMARY != '' && vars.BEHAVIOR_PRIMARY || 'redirect' }}
3639

3740
# Release branch to custom url with an alias

README.md

+58-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# GitHub reusable action: publish your book online to GitHub Pages
22

3-
We developed a workflow which builds your TeachBook in your repository for all branches and releases them online via GitHub Pages. In simplified terms, it builds the website based on your repository.
3+
We developed a workflow which builds your TeachBook in your repository for all branches and releases them online via GitHub Pages. In simplified terms, it automatically builds the book website based on updates to your repository, creates multiple instances of your book (defined by each branch) and provides the ability to customize the URL's at which each instance of the book can be accessed. This tool is designed specifically for educational contexts, for example, when you may want to preserve book versions from multiple academic years so that students are able to access it later. The [TeachBooks Template](https://github.com/TeachBooks/template) uses this functionality for example.
44

5-
The [TeachBooks Template](https://github.com/TeachBooks/template) uses this functionality for example. The workflow `call-deploy-book.yml` calls the `deploy-book.yml` workflow, which builds the Jupyter books at the calling repository for all branches, and deploys them via GitHub Pages.
5+
The workflow `call-deploy-book.yml` calls the `deploy-book.yml` workflow, which builds a Jupyter Book at the calling repository for all branches, and deploys them via GitHub Pages. It is currently configured to create a Jupyter Book using the TeachBooks Python package (i.e., `teachbooks build book`), although this may be adapted in the future to make it easier to use in other applications (e.g., to build books with other software or any static website in general).
66

77
The workflow has the following features:
88
- Releasing of your [TeachBook](https://teachbooks.io/)-repository (built with [Jupyter Book](https://github.com/executablebooks/jupyter-book)) to GitHub Pages
@@ -13,12 +13,12 @@ If you have an organization for your TeachBook on GitHub, link your GitHub team
1313
- Provides a summary describing where the TeachBook is released, errors in the build process per branch and how the release step is configured
1414
- Caching of already built books so that it can be partially reused when another branch is released or the next build contains critical errors
1515
- Caching of python environment to speed up the workflow
16-
- Allowing to use submodules within your book
16+
- Allowing use of submodules within your book
1717
- Customizable trigger for the workflow itself
18-
- Optionally preprocess branches using the [`teachbooks` package](https://github.com/TeachBooks/TeachBooks).
18+
- Optionally preprocess branches using the [`teachbooks` package](https://github.com/TeachBooks/TeachBooks) (e.g., Draft-Release Worklflow).
1919
- Converting branch-names to well-defined URLs
20-
- Customizable settings on where the books should be deployed including alias for branch-names and selection of one branch to be deployed on root. The workflow will gives warnings if these settings are ill-defined or conflicting. Although aliases are not allowed by GitHub Pages, it seems you can use one alias, but not more.
21-
- Redirects the root directory to one of the branches or copying or moving one of the branches to root.
20+
- Customizable settings on where the books should be deployed including alias for branch-names and selection of one branch to be deployed on root. The workflow will gives warnings if these settings are ill-defined or conflicting. Although aliases are generally not allowed by GitHub Pages, it seems you can use one alias, but not more.
21+
- Customizable behavior of book URL root directory, either by redirecting the root to one of the branches or by copying or moving one of the branches to root.
2222
- Adds an 'archived'-banner to old branches / branches of previous years.
2323

2424
## How to start using this workflow
@@ -36,10 +36,11 @@ As previously mentioned, this workflow is used in `TeachBooks/template`. Feel fr
3636
You can adapt the behaviour by setting repository variables as explained [here](https://docs.github.com/en/actions/learn-github-actions/variables#creating-configuration-variables-for-a-repository) or using the [VS Code Extension GitHub Actions](https://marketplace.visualstudio.com/items?itemName=GitHub.vscode-github-actions). Define the following repository variables:
3737
- `PRIMARY_BRANCH` which is set to `main` whenever it's not defined in the repository variables.
3838
- This sets the branch or alias (when using 'redirect' for `BEHAVIOR_PRIMARY`) which is shown on root.
39-
- It is advised to show your most recent branch on root.
39+
- It is advised to show either your default branch on root, or the branch shared with your primary/active book audience (e.g., your current students).
4040
- `BEHAVIOR_PRIMARY` which is set to `redirect` whenever it's not defined in the repository variables.
4141
- This indicates whether to copy the PRIMARY_BRANCH to root ('copy'), move the PRIMARY_BRANCH to root ('move') or redirect from root to the PRIMARY_BRANCH ('redirect')
42-
- Advised to use 'redirect' if you expect to archive a version in the future so that the URL doesn't change for the reader.
42+
- Advised to use 'redirect' if you expect to archive a version in the future so that the URL doesn't change for the reader (e.g., to preserve URL containing the current academic year shared with students).
43+
- Use copy or move when you only expect readers to use the root URL. Move is useful to remove unnecessary build artifacts and if you don't need to visit the URL containing the branch or alias name.
4344
- `BRANCH_ALIASES` which is set to ` ` (just a space) whenever it's not defined in the repository variables.
4445
- This defines an alias (custom URL) for a branch
4546
- Variables should be a space-separated list of branch names, e.g. 'alias:really-long-branch-name`
@@ -57,6 +58,55 @@ You can adapt the behaviour by setting repository variables as explained [here](
5758

5859
In `call-deploy-book.yml` itself you can specify the trigger for this workflow. By default, a push to any branch triggers the workflow. You can limit the branches or subdirectories.
5960

61+
## Common Usage Examples
62+
63+
Relevant use cases are explained here, along with an explanation for how to set up the workflow accordingly. Note that it is not required to set your `PRIMARY_BRANCH` to the default branch of your GitHub repository; this is a choice that is determined by what version of the source code you want visitors to see (i.e., work in progress, or the most recent "complete" or "released" version of a book).
64+
65+
### Books with active users of different versions (academic years)
66+
67+
Consider a case where each academic year you would like to create a new book for your students. However, you need to ensure that students from previous years can still access "their" version of the book.
68+
69+
Assume for this example that we are working in the "my_organization" GitHub Organization in repository "my_book" and that the current academic year is 2025, and that we have one or more books in our repository from previous years. The desired URL structure is thus:
70+
- students from this year use the book at `my_organization.github.io/my_book/2025/`
71+
- students from last year use the book at `my_organization.github.io/my_book/2024/`
72+
- visitors to `my_organization.github.io/my_book/` will automatically be redirected to the book from the current year
73+
74+
To create this behavior, do the following:
75+
76+
- Create a branch for each year: a logical name would have format `YYYY`, (technically it can be anything, as the URL can be set to `YYYY` with `BRANCH_ALIASES`).
77+
- Set `PRIMARY_BRANCH` to the branch for the current academic year (e.g., `2025`)
78+
- Set `BEHAVIOR_PRIMARY` to `redirect` (default)
79+
80+
#### Alternative without redirect to current year
81+
82+
One possible modification to this setup would be if you are progressively releasing content to your current students (e.g., `2025`) but you wanted visitors to `my_organization.github.io/my_book/` to see a complete version of your book. Assuming that the ideal version for such visitors is the completed book from the previous year (`2024`), you could do this:
83+
- Set `PRIMARY_BRANCH` to `2024`
84+
- Set `BEHAVIOR_PRIMARY` to `copy`
85+
86+
As your current students may then accidentally go to the older version of the book, we recommend you use a banner to indicate to readers that there is a (partial) new version available, and advise them where to find it. You can add a banner using this workflow (`BRANCHES_ARCHIVED`) or the [standard Jupyter Book banner feature](https://jupyterbook.org/en/stable/web/announcements.html).
87+
88+
### Books with active editors working in parallel
89+
90+
Consider a case where several authors are working on material for a book and you would like to be able to see the work of any author at any time. You also have a branch that is used to share finalized material with your readers (we call this a "release" branch) and a branch that is used to collect and review the work of all authors before releasing it (we call this a "draft" branch).
91+
92+
Assume for this example that we are working in the "my_organization" GitHub Organization in repository "my_book." The released book is on branch `release` the draft book is on branch `draft`; author branches are `author_1`, `author_2`, etc. The desired URL structure is thus:
93+
- official (released) version of the book is at `my_organization.github.io/my_book/`
94+
- draft version of the book is at `my_organization.github.io/my_book/draft/`
95+
- the work of each author can be found at `my_organization.github.io/my_book/author_1/`, etc.
96+
97+
To create this behavior, do the following:
98+
99+
- Create a branch for each author as well as `release` and `draft` branches
100+
- Set `draft` to the default branch
101+
- Set `PRIMARY_BRANCH` to `release`
102+
- Set `BEHAVIOR_PRIMARY` to `copy`
103+
104+
Note that in this situation we strongly recommend using the Draft-Release workflow that is incorporated in the TeachBooks Python package, which allows you to restrict specific content from appearing in the `release` book that is already incorporated in the `draft` book. [Find out more in the TeachBooks Manual](https://teachbooks.io/manual/features/draft-release.html). This is useful, for example, if you would like to review many chapters, but release only one at a time, or use a banner in the draft book (e.g., via `_config.yml`) but not the released book.
105+
106+
#### Why make the draft branch default?
107+
108+
What if you want to make sure the source code for the released book is visible in the repository, rather than the draft version (e.g., you want to make sure external visitors see this version of the material)? You can do this by making `release` your default branch instead of `draft`. However, this also means that Pull Requests will be default be made into the `release` branch instead of `draft`, which may alter the working method of your team in an undesirable way (e.g., not being able to use a `draft` branch, accidentally releasing material before checking on `draft`, or having to manually adjust every PR that is created by GitHub to merge into `draft` instead of `release`).
109+
60110
## Additional GitHub settings
61111
We advise you to enable two options in the general repository setting regarding pull requests in GitHub:
62112
- Enable `Always suggest updating pull request branches`, suggesting a merge from the default branch into any separate branch before merging into main.

0 commit comments

Comments
 (0)