Skip to content

Commit 4fb2199

Browse files
Update Workflows to Version 1.0.1 (#53)
Co-authored-by: connoraird <61978554+connoraird@users.noreply.github.com> Co-authored-by: connoraird <c.aird@ucl.ac.uk>
1 parent d31abc4 commit 4fb2199

12 files changed

Lines changed: 994 additions & 153 deletions

.github/workflows/README.md

Lines changed: 68 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
# Carpentries Workflows
1+
# Workflow Documentation
22

3-
This directory contains workflows to be used for Lessons using the {sandpaper}
4-
lesson infrastructure. Two of these workflows require R (`sandpaper-main.yaml`
5-
and `pr-receive.yaml`) and the rest are bots to handle pull request management.
3+
## Managing Workflow Updates
64

7-
These workflows will likely change as {sandpaper} evolves, so it is important to
8-
keep them up-to-date. To do this in your lesson you can do the following in your
9-
R console:
5+
By using prebuilt Docker containers that are managed by the Carpentries core Workbench maintainers, these workflows are designed
6+
to be rarely updated.
7+
8+
However, is important to be able to keep them up-to-date when appropriate.
9+
You can do this locally using your own R and Workbench installation, or via the "04 Maintain: Update Workflow Files"
10+
(`update-workflows.yaml`) GitHub Action.
11+
12+
### Updating locally
13+
14+
In a terminal/git bash, navigate to the lesson folder where you want to update the workflows.
15+
16+
Then, start an R session and:
1017

1118
```r
1219
# Install/Update sandpaper
@@ -16,21 +23,31 @@ install.packages("sandpaper")
1623

1724
# update the workflows in your lesson
1825
library("sandpaper")
19-
update_github_workflows()
26+
sandpaper::update_github_workflows()
27+
quit()
2028
```
2129

22-
Inside this folder, you will find a file called `sandpaper-version.txt`, which
23-
will contain a version number for sandpaper. This will be used in the future to
24-
alert you if a workflow update is needed.
30+
And then in a bash prompt/git bash terminal:
2531

26-
What follows are the descriptions of the workflow files:
32+
```bash
33+
git add .github/workflows
34+
git commit -m "Manual update to docker workflows"
35+
git push origin main
36+
```
2737

28-
## Deployment
38+
> [!NOTE]
39+
> For non-renv lessons, this is all the setup you need!
40+
>
41+
> For renv-enabled lessons:
42+
>
43+
> - Cancel any "01 Maintain: Build and Deploy Site" workflow currently running
44+
> - Run the "02 Maintain: Check for Updated Packages" workflow and merge any PR opened to update the renv lockfile
45+
> - This should automatically run the "03 Maintain: Apply Package Cache" workflow to install packages and build the cache
46+
> - A successful cache build should then trigger the "01 Maintain: Build and Deploy Site" workflow
2947
30-
### 01 Build and Deploy (sandpaper-main.yaml)
48+
### Updating using GitHub
3149

32-
This is the main driver that will only act on the main branch of the repository.
33-
This workflow does the following:
50+
#### Official lessons
3451

3552
1. checks out the lesson
3653
2. provisions the following resources
@@ -40,7 +57,10 @@ This workflow does the following:
4057
- lesson dependencies if needed (stored in a cache)
4158
3. builds the lesson via `sandpaper:::ci_deploy()`
4259

43-
#### Caching
60+
To update the workflows, either:
61+
62+
- wait for the scheduled run of the "04 Maintain: Update Workflow Files" at approximately midnight every Tuesday
63+
- go to the Actions tab on GitHub, click "04 Maintain: Update Workflow Files" on the left, then "Run Workflow" on the right
4464

4565
This workflow has two caches; one cache is for the lesson infrastructure and
4666
the other is for the lesson dependencies if the lesson contains rendered
@@ -52,19 +72,20 @@ and invalidate the failing cache](https://github.blog/changelog/2022-10-20-manag
5272
or by setting the `CACHE_VERSION` secret to the current date (which will
5373
invalidate all of the caches).
5474

55-
## Updates
75+
#### Your own lessons
76+
77+
This presumes you:
5678

57-
### Setup Information
79+
- already have a lesson repository available on GitHub
80+
- have enabled workflows in the lesson repo
81+
- have set up a SANDPAPER_WORKFLOW personal access token (PAT) in the lesson repo
5882

5983
These workflows run on a schedule and at the maintainer's request. Because they
6084
create pull requests that update workflows/require the downstream actions to run,
6185
they need a special repository/organization secret token called
6286
`SANDPAPER_WORKFLOW` and it must have the `public_repo` and `workflow` scope.
6387

64-
This can be an individual user token, OR it can be a trusted bot account. If you
65-
have a repository in one of the official Carpentries accounts, then you do not
66-
need to worry about this token being present because the Carpentries Core Team
67-
will take care of supplying this token.
88+
Once set up, run the "04 Maintain: Update Workflow Files" (`update-workflows.yaml`) action.
6889

6990
If you want to use your personal account: you can go to
7091
<https://github.com/settings/tokens/new?scopes=public_repo,workflow&description=Sandpaper%20Token>
@@ -75,7 +96,7 @@ create or edit the `SANDPAPER_WORKFLOW` secret, pasting in the generated token.
7596
If you do not specify your token correctly, the runs will not fail and they will
7697
give you instructions to provide the token for your repository.
7798

78-
### 02 Maintain: Update Workflow Files (update-workflow.yaml)
99+
## Package Caches for RMarkdown Lessons
79100

80101
The {sandpaper} repository was designed to do as much as possible to separate
81102
the tools from the content. For local builds, this is true, but
@@ -86,17 +107,18 @@ This workflow ensures that the workflow files are up-to-date. The way it work is
86107
to download the update-workflows.sh script from GitHub and run it. The script
87108
will do the following:
88109

89-
1. check the recorded version of sandpaper against the current version on github
90-
2. update the files if there is a difference in versions
110+
### Caching
91111

92-
After the files are updated, if there are any changes, they are pushed to a
93-
branch called `update/workflows` and a pull request is created. Maintainers are
94-
encouraged to review the changes and accept the pull request if the outputs
95-
are okay.
112+
The two cache management workflows are separated to ensure that once you have a successful build with a working renv cache, this
113+
cache is stored and will be reused by the Workbench Docker container.
114+
This means that lesson builds will be faster once an renv cache is created and reused by the Docker container.
96115

97-
This update is run weekly or on demand.
116+
Another major bonus of this setup is that you can keep using this cache indefinitely to build your lesson.
117+
This is important if you need very specific versions of R packages ("pinning").
98118

99-
### 03 Maintain: Update Package Cache (update-cache.yaml)
119+
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
120+
that your lesson still builds with the new packages.
121+
If all looks good, re-run the "03 Maintain: Apply Package Cache" workflow, and this will write a new renv cache file to GitHub.
100122

101123
For lessons that have generated content, we use {renv} to ensure that the output
102124
is stable. This is controlled by a single lockfile which documents the packages
@@ -125,8 +147,8 @@ diagram and the below sections:
125147

126148
### Pre Flight Pull Request Validation (pr-preflight.yaml)
127149

128-
This workflow runs every time a pull request is created and its purpose is to
129-
validate that the pull request is okay to run. This means the following things:
150+
This workflow runs every time a pull request is created and its purpose is to validate that the pull request is okay to run.
151+
This means the following things:
130152

131153
1. The pull request does not contain modified workflow files
132154
2. If the pull request contains modified workflow files, it does not contain
@@ -140,25 +162,24 @@ Once the checks are finished, a comment is issued to the pull request, which
140162
will allow maintainers to determine if it is safe to run the
141163
"Receive Pull Request" workflow from new contributors.
142164

143-
### Receive Pull Request (pr-receive.yaml)
165+
### Receive Pull Request (docker_pr_receive.yaml)
144166

145167
**Note of caution:** This workflow runs arbitrary code by anyone who creates a
146168
pull request. GitHub has safeguarded the token used in this workflow to have no
147169
privileges in the repository, but we have taken precautions to protect against
148170
spoofing.
149171

150-
This workflow is triggered with every push to a pull request. If this workflow
151-
is already running and a new push is sent to the pull request, the workflow
152-
running from the previous push will be cancelled and a new workflow run will be
153-
started.
172+
This workflow is triggered with every push to a pull request.
173+
If this workflow is already running and a new push is sent to the pull request, the workflow running from the previous push will
174+
be cancelled and a new workflow run will be started.
154175

155176
The first step of this workflow is to check if it is valid (e.g. that no
156177
workflow files have been modified). If there are workflow files that have been
157178
modified, a comment is made that indicates that the workflow is not run. If
158179
both a workflow file and lesson content is modified, an error will occur.
159180

160-
The second step (if valid) is to build the generated content from the pull
161-
request. This builds the content and uploads three artifacts:
181+
The second step (if valid) is to build the generated content from the pull request.
182+
This builds the content and uploads three artifacts:
162183

163184
1. The pull request number (pr)
164185
2. A summary of changes after the rendering process (diff)
@@ -171,26 +192,23 @@ The artifacts produced are used by the next workflow.
171192

172193
### Comment on Pull Request (pr-comment.yaml)
173194

174-
This workflow is triggered if the `pr-receive.yaml` workflow is successful.
195+
This workflow is triggered if the `docker_pr_receive.yaml` workflow is successful.
175196
The steps in this workflow are:
176197

177-
1. Test if the workflow is valid and comment the validity of the workflow to the
178-
pull request.
179-
2. If it is valid: create an orphan branch with two commits: the current state
180-
of the repository and the proposed changes.
198+
1. Test if the workflow is valid and comment the validity of the workflow to the pull request.
199+
2. If it is valid: create an orphan branch with two commits: the current state of the repository and the proposed changes.
181200
3. If it is valid: update the pull request comment with the summary of changes
182201

183-
Importantly: if the pull request is invalid, the branch is not created so any
184-
malicious code is not published.
202+
Importantly: if the pull request is invalid, the branch is not created so any malicious code is not published.
185203

186204
From here, the maintainer can request changes from the author and eventually
187205
either merge or reject the PR. When this happens, if the PR was valid, the
188206
preview branch needs to be deleted.
189207

190208
### Send Close PR Signal (pr-close-signal.yaml)
191209

192-
Triggered any time a pull request is closed. This emits an artifact that is the
193-
pull request number for the next action
210+
Triggered any time a pull request is closed.
211+
This emits an artifact that is the pull request number for the next action.
194212

195213
### Remove Pull Request Branch (pr-post-remove-branch.yaml)
196214

0 commit comments

Comments
 (0)