Skip to content

Commit 967bc0b

Browse files
authored
Merge pull request #1129 from swcarpentry/update/workflows
Update Workflows to Version v1.0.2
2 parents e81b0c6 + eea9d97 commit 967bc0b

10 files changed

Lines changed: 202 additions & 268 deletions

.github/workflows/README.md

Lines changed: 78 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
# Workflow Documentation
1+
# Workbench Workflows Documentation
2+
3+
These GitHub Actions workflows manage and maintain the build processes for lessons using the Carpentries Workbench on GitHub.
4+
25

36
## Managing Workflow Updates
47

@@ -9,7 +12,11 @@ You can do this locally using your own R and Workbench installation, or via the
912

1013
### Updating locally
1114

12-
In a terminal/git bash, navigate to the lesson folder where you want to update the workflows.
15+
In a terminal/git bash, navigate to the lesson folder where you want to update the workflows, e.g.:
16+
17+
```bash
18+
cd ~/lessons/shell-novice
19+
```
1320

1421
Then, start an R session and:
1522

@@ -39,7 +46,22 @@ $ git push origin main
3946
> - Cancel any "01 Maintain: Build and Deploy Site" workflow currently running
4047
> - Run the "02 Maintain: Check for Updated Packages" workflow and merge any PR opened to update the renv lockfile
4148
> - This should automatically run the "03 Maintain: Apply Package Cache" workflow to install packages and build the cache
42-
> - A successful cache buid should then trigger the "01 Maintain: Build and Deploy Site" workflow
49+
> - A successful cache build should then trigger the "01 Maintain: Build and Deploy Site" workflow
50+
51+
#### Updating to a specific workflow release or branch
52+
53+
To test new Workbench workflow features or branches, or to pin to a specific release, the `branch` option can be supplied to `update_github_workflows()`.
54+
55+
For a given branch:
56+
57+
```r
58+
sandpaper::update_github_workflows(branch="develop")
59+
```
60+
61+
Or for a given release version:
62+
```r
63+
sandpaper::update_github_workflows(branch="1.0.1")
64+
```
4365

4466
### Updating using GitHub
4567

@@ -71,63 +93,90 @@ This will raise a PR with any changes to the workflows that are needed.
7193
If you are happy with the changes made, you can merge the PR into your lesson repository.
7294

7395

74-
## Package Caches for RMarkdown Lessons
96+
## Dependency Images for RMarkdown Lessons
97+
98+
Lessons that use R packages and RMarkdown are built on GitHub using Docker images within these workflows.
99+
These images are based on the [workbench-docker](https://github.com/carpentries/workbench-docker) image.
100+
This base image only contains the Workbench packages to build lessons and not any extra R packages your lesson might need.
75101

76-
In summary, generating a reusable package cache is achieved by running the "02 Maintain: Check for Updated Packages" workflow, and then the "03 Maintain: Apply Package Cache" workflow.
102+
Therefore, there are two steps to perform to resolve the required R packages in a lesson, and then generate a Docker image layer comprising those packages.
103+
104+
The "02 Maintain: Check for Updated Packages" workflow checks for any used R packages and their versions, and if successful, opens a Pull Request to update your lesson's renv lockfile (`renv.lock`).
105+
Once the PR is merged, the "03 Maintain: Apply Package Cache" workflow builds the dependency image layer with `docker build` and publishes it in your user or organisation account Packages area.
77106

78107
> [!NOTE]
79108
> Caching is only relevant for lessons that use Rmd files and renv to manage R packages.
80109
> If you are building basic markdown documents, caching will not apply to you, and the only
81110
> workflow that needs to be run is "01 Maintain: Build and Deploy Site".
82111
83-
### Caching
112+
### Publishing dependency images
84113

85-
The two cache management workflows are separated to ensure that once you have a successful build with a working renv cache, this cache is stored and will be reused by the Workbench Docker container.
86-
This means that lesson builds will be faster once an renv cache is created and reused by the Docker container.
114+
The two dependency workflows are separated to ensure that once you have a successful build with a working renv environment, the resulting dependency image is stored and will be reused by the Workbench Docker container.
115+
This means that lesson builds will be faster and more consistent once a dependency image is created and reused. This is doubly important if you need very specific versions of R packages, i.e. "pinning".
87116

88-
Another major bonus of this setup is that you can keep using this cache indefinitely to build your lesson.
89-
This is important if you need very specific versions of R packages ("pinning").
117+
This setup means that this dependency image layer is available indefinitely:
118+
- to build your lesson, improving robustness and reproducibility
119+
- for others to use as a complete environment in their local builds, teaching environments, or Codespaces
90120

91-
If and when you want to perform an update to the cache, you can re-run the "02 Maintain: Check for Updated Packages" and verify that your lesson still builds with the new packages.
92-
If all looks good, re-run the "03 Maintain: Apply Package Cache" workflow, and this will write a new renv cache file to GitHub.
121+
If and when you want to perform an update to the dependency image, you can re-run the "02 Maintain: Check for Updated Packages" workflow and verify that your lesson still builds with any new packages or changes.
122+
The "03 Maintain: Apply Package Cache" workflow will publish a new repository- or organisation-local GHCR image for the lesson.
93123

94-
In any case, the renv cache is invalidated by new versions of the `renv.lock` file.
124+
As such, the dependency image is invalidated by new versions of the `renv.lock` file.
95125
This happens:
96-
- if you update your lockfile locally by using the `sandpaper::update_cache()` function, and then push it to the lesson repository
126+
- if you update your lockfile locally by using the `sandpaper::update_cache()` and `sandpaper::manage_deps()` functions, and then push it to the lesson repository
97127
- when you run the "02 Maintain: Check for Updated Packages" and there are new packages to install
98128

99-
More information on managing local renv caches for lessons can be found in the [Sandpaper packages vignettes](https://carpentries.github.io/sandpaper/articles/building-with-renv.html).
129+
More information on managing local renv-based lesson dependencies can be found in the [Sandpaper packages vignettes](https://carpentries.github.io/sandpaper/articles/building-with-renv.html).
100130

101-
#### Using different package cache versions
131+
#### Using different dependency image versions
102132

103-
There are times when you may want to go back to a previous renv package cache file:
133+
There are times when you may want to go back to a previous dependency image:
104134
- if you run "02 Maintain: Check for Updated Packages" and "03 Maintain: Apply Package Cache" and the cache generation fails for some reason
105135
- if there is a new R package that produces incorrect or broken lesson output
136+
- a new R version is released and downstream packages fail to build and install, and need updating by the package maintainer(s)
106137

107-
Cache files will have the following name format, where IMAGE is the workbench-docker image version, and HASHSUM is the `renv.lock` lockfile MD5 hash:
138+
Dependency images will have the following name format, where IMAGE is the workbench-docker image version, and HASHSUM is the `renv.lock` lockfile hash:
108139

109140
```
110141
IMAGE HASHSUM
111142
[ | ] [ | ]
112143
v0.2.4_renv-2e499eb706112971b2cffceb49b55a6efe49f3ed75cd6579b10ff224489daca4
113144
```
114145

115-
Copy the hashsum part of the desired cache file you want to use, e.g. `2e499eb706112971b2cffceb49b55a6efe49f3ed75cd6579b10ff224489daca4`.
146+
Copy the hashsum part of the desired image tag you want to use, e.g. `2e499eb706112971b2cffceb49b55a6efe49f3ed75cd6579b10ff224489daca4`.
116147

117148
Then either:
118149
1. Add a repository variable called CACHE_VERSION, and paste in the hash
119-
- Go to ...
120-
2. Run the "01 Maintain: Build and Deploy Site" manually, supplying the CACHE_VERSION input
121-
- Go to ...
150+
2. Run the "01 Maintain: Build and Deploy Site" manually, supplying the `Optional renv cache version override` input
122151

123-
If you have no caches listed, make sure to run the "02 Maintain: Check for Updated Packages" and "03 Maintain: Apply Package Cache" to create a new renv cache file.
152+
If you have no images listed, make sure to run the "02 Maintain: Check for Updated Packages" and "03 Maintain: Apply Package Cache" workflows to publish a new dependency image.
124153

125154
> [!NOTE]
126-
> If you are maintaining an official lesson, caches are saved in an AWS S3 bucket owned by the Carpentries.
127-
> Once a successful cache has been saved, these will be listed in the outputs of the "01 Maintain: Build and Deploy Site" workflow.
155+
> If you are maintaining an official lesson, dependency images are saved to the Carpentries lesson program organisation, e.g. `datacarpentry`, GHCR package namespace.
156+
> Once a successful dependency image has been published, the build workflows will use it automatically when the matching Docker version tag exists, e.g. 'latest' or a specific version.
128157
>
129-
> If you are developing a lesson in your own repository, caches are saved on GitHub.
130-
> You can see available caches by going to the Actions tab, and clicking Caches on the left hand side.
158+
> If you are developing a lesson in your own repository, the dependency images are stored in your repository's GHCR package namespace.
159+
> You can see available images by going to your user or organisation's Packages tab, e.g. `https://github.com/<your_github_username>?tab=packages`.
160+
161+
#### Pruning dependency image layers
162+
163+
Through the lifetime of a lesson, an increasing number of dependency images will be generated.
164+
As the images are public, GitHub currently charges no storage, or network ingress or egress fees to upload or download them.
165+
166+
The "03 Maintain: Apply Package Cache" workflow will automatically check the number of published dependency images and keep each version published plus one underlying untagged digest (if any) for each version.
167+
This means it is possible to roll back easily to a previous version or digest, but not end up with a huge number of dependency images to manage.
168+
169+
In any case, you can manually delete any versions you wish by:
170+
- going to your user or organisation's Packages tab, e.g. `https://github.com/<your_github_username>?tab=packages`.
171+
- selecting the dependency image you want to manage, e.g. `<lesson_repo_name>-deps`
172+
- selecting `Package settings` on the right hand side
173+
- deleting any images
174+
175+
> [!NOTE]
176+
> Deleting these images manually may break your builds.
177+
> Only perform this action if you are sure you want to delete the generated dependency images.
178+
>
179+
> If you mistakenly delete an image, you can rebuild it by rerunning the "03 Maintain: Apply Package Cache" workflow.
131180
132181

133182
## User Settings
@@ -186,15 +235,14 @@ Repository-level variables for this workflow are:
186235
- This can be set to a specific version number to force all builds to use a given container version
187236
- Default is unset or `latest`
188237

189-
190238
### 04 Maintain: Update Workflow Files (update-workflows.yaml)
191239

192240
There are no repository variables for this workflow.
193241

194242

195243
## Pull Request and Review Management
196244

197-
Because our lessons execute code, pull requests are a security risk for any lesson and thus have security measures associted with them.
245+
Because our lessons execute code, pull requests are a security risk for any lesson and thus have security measures associated with them.
198246
**Do not merge any pull requests that do not pass checks and do not have bots commented on them.**
199247

200248
This series of workflows all go together and are described in the following diagram and the below sections:
@@ -256,5 +304,5 @@ This emits an artifact that is the pull request number for the next action.
256304

257305
### Remove Pull Request Branch (pr-post-remove-branch.yaml)
258306

259-
Tiggered by `pr-close-signal.yaml`.
307+
Triggered by `pr-close-signal.yaml`.
260308
This removes the temporary branch associated with the pull request (if it was created).

0 commit comments

Comments
 (0)