Skip to content

Commit ddb8dad

Browse files
authored
Merge pull request #3 from adamancer/update-workflows-version-0.16.12
Update Workflows to Version 0.16.12
2 parents 5e647cb + 30d38f9 commit ddb8dad

10 files changed

Lines changed: 126 additions & 91 deletions

.github/workflows/README.md

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This directory contains workflows to be used for Lessons using the {sandpaper}
44
lesson infrastructure. Two of these workflows require R (`sandpaper-main.yaml`
5-
and `pr-recieve.yaml`) and the rest are bots to handle pull request management.
5+
and `pr-receive.yaml`) and the rest are bots to handle pull request management.
66

77
These workflows will likely change as {sandpaper} evolves, so it is important to
88
keep them up-to-date. To do this in your lesson you can do the following in your
@@ -43,11 +43,14 @@ This workflow does the following:
4343
#### Caching
4444

4545
This workflow has two caches; one cache is for the lesson infrastructure and
46-
the other is for the the lesson dependencies if the lesson contains rendered
46+
the other is for the lesson dependencies if the lesson contains rendered
4747
content. These caches are invalidated by new versions of the infrastructure and
4848
the `renv.lock` file, respectively. If there is a problem with the cache,
49-
manual invaliation is necessary and can be done by setting the `CACHE_VERSION`
50-
secret to the current date.
49+
manual invaliation is necessary. You will need maintain access to the repository
50+
and you can either go to the actions tab and [click on the caches button to find
51+
and invalidate the failing cache](https://github.blog/changelog/2022-10-20-manage-caches-in-your-actions-workflows-from-web-interface/)
52+
or by setting the `CACHE_VERSION` secret to the current date (which will
53+
invalidate all of the caches).
5154

5255
## Updates
5356

@@ -56,15 +59,15 @@ secret to the current date.
5659
These workflows run on a schedule and at the maintainer's request. Because they
5760
create pull requests that update workflows/require the downstream actions to run,
5861
they need a special repository/organization secret token called
59-
`SANDPAPER_WORKFLOW` and it must have the `repo` and `workflow` scope.
62+
`SANDPAPER_WORKFLOW` and it must have the `public_repo` and `workflow` scope.
6063

6164
This can be an individual user token, OR it can be a trusted bot account. If you
6265
have a repository in one of the official Carpentries accounts, then you do not
6366
need to worry about this token being present because the Carpentries Core Team
6467
will take care of supplying this token.
6568

6669
If you want to use your personal account: you can go to
67-
<https://github.com/settings/tokens/new?scopes=repo,workflow&description=Sandpaper%20Token>
70+
<https://github.com/settings/tokens/new?scopes=public_repo,workflow&description=Sandpaper%20Token>
6871
to create a token. Once you have created your token, you should copy it to your
6972
clipboard and then go to your repository's settings > secrets > actions and
7073
create or edit the `SANDPAPER_WORKFLOW` secret, pasting in the generated token.
@@ -86,24 +89,25 @@ will do the following:
8689
1. check the recorded version of sandpaper against the current version on github
8790
2. update the files if there is a difference in versions
8891

89-
After the files are updated, a pull request is created if there are any changes.
90-
Maintainers are encouraged to review the changes and accept the pull request.
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.
9196

92-
This update is run ~~weekly or~~ on demand.
97+
This update is run weekly or on demand.
9398

94-
TODO:
95-
- perform check if a pull request exists before creating pull request
96-
97-
### 03 Maintain: Update Pacakge Cache (update-cache.yaml)
99+
### 03 Maintain: Update Package Cache (update-cache.yaml)
98100

99101
For lessons that have generated content, we use {renv} to ensure that the output
100102
is stable. This is controlled by a single lockfile which documents the packages
101-
needed for the lesson and the version numbers.
103+
needed for the lesson and the version numbers. This workflow is skipped in
104+
lessons that do not have generated content.
102105

103106
Because the lessons need to remain current with the package ecosystem, it's a
104107
good idea to make sure these packages can be updated periodically. The
105-
update cache workflow will do this by checking for updates, applying them and
106-
creating a pull request with _only the lockfile changed_.
108+
update cache workflow will do this by checking for updates, applying them in a
109+
branch called `updates/packages` and creating a pull request with _only the
110+
lockfile changed_.
107111

108112
From here, the markdown documents will be rebuilt and you can inspect what has
109113
changed based on how the packages have updated.
@@ -136,13 +140,18 @@ Once the checks are finished, a comment is issued to the pull request, which
136140
will allow maintainers to determine if it is safe to run the
137141
"Receive Pull Request" workflow from new contributors.
138142

139-
### Recieve Pull Request (pr-recieve.yaml)
143+
### Receive Pull Request (pr-receive.yaml)
140144

141145
**Note of caution:** This workflow runs arbitrary code by anyone who creates a
142146
pull request. GitHub has safeguarded the token used in this workflow to have no
143147
priviledges in the repository, but we have taken precautions to protect against
144148
spoofing.
145149

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.
154+
146155
The first step of this workflow is to check if it is valid (e.g. that no
147156
workflow files have been modified). If there are workflow files that have been
148157
modified, a comment is made that indicates that the workflow is not run. If
@@ -156,13 +165,13 @@ request. This builds the content and uploads three artifacts:
156165
3. The rendered files (build)
157166

158167
Because this workflow builds generated content, it follows the same general
159-
process as the sandpaper-main workflow with the same caching mechanisms.
168+
process as the `sandpaper-main` workflow with the same caching mechanisms.
160169

161170
The artifacts produced are used by the next workflow.
162171

163172
### Comment on Pull Request (pr-comment.yaml)
164173

165-
This workflow is triggered if the `pr-recieve.yaml` workflow is successful.
174+
This workflow is triggered if the `pr-receive.yaml` workflow is successful.
166175
The steps in this workflow are:
167176

168177
1. Test if the workflow is valid and comment the validity of the workflow to the
@@ -172,7 +181,7 @@ The steps in this workflow are:
172181
3. If it is valid: update the pull request comment with the summary of changes
173182

174183
Importantly: if the pull request is invalid, the branch is not created so any
175-
malicious code is not published.
184+
malicious code is not published.
176185

177186
From here, the maintainer can request changes from the author and eventually
178187
either merge or reject the PR. When this happens, if the PR was valid, the

.github/workflows/pr-close-signal.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@ on:
88
jobs:
99
send-close-signal:
1010
name: "Send closing signal"
11-
runs-on: ubuntu-latest
11+
runs-on: ubuntu-22.04
1212
if: ${{ github.event.action == 'closed' }}
1313
steps:
1414
- name: "Create PRtifact"
1515
run: |
1616
mkdir -p ./pr
1717
printf ${{ github.event.number }} > ./pr/NUM
1818
- name: Upload Diff
19-
uses: actions/upload-artifact@v2
19+
uses: actions/upload-artifact@v4
2020
with:
21-
name: pr
21+
name: pr
2222
path: ./pr
23-

.github/workflows/pr-comment.yaml

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,22 @@ on:
88
types:
99
- completed
1010

11+
concurrency:
12+
group: pr-${{ github.event.workflow_run.pull_requests[0].number }}
13+
cancel-in-progress: true
14+
15+
1116
jobs:
1217
# Pull requests are valid if:
1318
# - they match the sha of the workflow run head commit
1419
# - they are open
1520
# - no .github files were committed
1621
test-pr:
1722
name: "Test if pull request is valid"
18-
runs-on: ubuntu-latest
19-
if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }}
23+
runs-on: ubuntu-22.04
24+
if: >
25+
github.event.workflow_run.event == 'pull_request' &&
26+
github.event.workflow_run.conclusion == 'success'
2027
outputs:
2128
is_valid: ${{ steps.check-pr.outputs.VALID }}
2229
payload: ${{ steps.check-pr.outputs.payload }}
@@ -35,7 +42,7 @@ jobs:
3542
id: get-pr
3643
run: |
3744
unzip pr.zip
38-
echo "::set-output name=NUM::$(<./NR)"
45+
echo "NUM=$(<./NR)" >> $GITHUB_OUTPUT
3946
4047
- name: "Fail if PR number was not present"
4148
id: bad-pr
@@ -46,14 +53,17 @@ jobs:
4653
- name: "Get Invalid Hashes File"
4754
id: hash
4855
run: |
49-
echo "::set-output name=json::"$(curl -sL https://files.carpentries.org/invalid-hashes.json)
56+
echo "json<<EOF
57+
$(curl -sL https://files.carpentries.org/invalid-hashes.json)
58+
EOF" >> $GITHUB_OUTPUT
5059
- name: "Check PR"
5160
id: check-pr
5261
if: ${{ steps.dl.outputs.success == 'true' }}
5362
uses: carpentries/actions/check-valid-pr@main
5463
with:
5564
pr: ${{ steps.get-pr.outputs.NUM }}
5665
sha: ${{ github.event.workflow_run.head_sha }}
66+
headroom: 3 # if it's within the last three commits, we can keep going, because it's likely rapid-fire
5767
invalid: ${{ fromJSON(steps.hash.outputs.json)[github.repository] }}
5868
fail_on_error: true
5969

@@ -64,13 +74,15 @@ jobs:
6474
create-branch:
6575
name: "Create Git Branch"
6676
needs: test-pr
67-
runs-on: ubuntu-latest
77+
runs-on: ubuntu-22.04
6878
if: ${{ needs.test-pr.outputs.is_valid == 'true' }}
6979
env:
7080
NR: ${{ needs.test-pr.outputs.number }}
81+
permissions:
82+
contents: write
7183
steps:
7284
- name: 'Checkout md outputs'
73-
uses: actions/checkout@v2.3.4
85+
uses: actions/checkout@v4
7486
with:
7587
ref: md-outputs
7688
path: built
@@ -94,11 +106,11 @@ jobs:
94106
git config --local user.name "GitHub Actions"
95107
CURR_HEAD=$(git rev-parse HEAD)
96108
git checkout --orphan md-outputs-PR-${NR}
97-
git add -A
109+
git add -A
98110
git commit -m "source commit: ${CURR_HEAD}"
99-
ls -A | grep -v '^.git' | xargs rm -r
111+
ls -A | grep -v '^.git$' | xargs -I _ rm -r '_'
100112
cd ..
101-
unzip -d built built.zip
113+
unzip -o -d built built.zip
102114
cd built
103115
git add -A
104116
git commit --allow-empty -m "differences for PR #${NR}"
@@ -108,18 +120,20 @@ jobs:
108120
comment-pr:
109121
name: "Comment on Pull Request"
110122
needs: [test-pr, create-branch]
111-
runs-on: ubuntu-latest
123+
runs-on: ubuntu-22.04
112124
if: ${{ needs.test-pr.outputs.is_valid == 'true' }}
113125
env:
114126
NR: ${{ needs.test-pr.outputs.number }}
127+
permissions:
128+
pull-requests: write
115129
steps:
116130
- name: 'Download comment artifact'
117131
id: dl
118132
uses: carpentries/actions/download-workflow-artifact@main
119133
with:
120134
run: ${{ github.event.workflow_run.id }}
121135
name: 'diff'
122-
136+
123137
- if: ${{ steps.dl.outputs.success == 'true' }}
124138
run: unzip ${{ github.workspace }}/diff.zip
125139

@@ -128,19 +142,21 @@ jobs:
128142
if: ${{ steps.dl.outputs.success == 'true' }}
129143
uses: carpentries/actions/comment-diff@main
130144
with:
131-
pr: ${{ env.NR }}
145+
pr: ${{ env.NR }}
132146
path: ${{ github.workspace }}/diff.md
133147

134148
# Comment if the PR is open and matches the SHA, but the workflow files have
135149
# changed
136150
comment-changed-workflow:
137151
name: "Comment if workflow files have changed"
138152
needs: test-pr
139-
runs-on: ubuntu-latest
153+
runs-on: ubuntu-22.04
140154
if: ${{ always() && needs.test-pr.outputs.is_valid == 'false' }}
141155
env:
142156
NR: ${{ github.event.workflow_run.pull_requests[0].number }}
143157
body: ${{ needs.test-pr.outputs.msg }}
158+
permissions:
159+
pull-requests: write
144160
steps:
145161
- name: 'Check for spoofing'
146162
id: dl
@@ -166,4 +182,3 @@ jobs:
166182
with:
167183
pr: ${{ env.NR }}
168184
body: ${{ env.body }}
169-

.github/workflows/pr-post-remove-branch.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ on:
99
jobs:
1010
delete:
1111
name: "Delete branch from Pull Request"
12-
runs-on: ubuntu-latest
12+
runs-on: ubuntu-22.04
1313
if: >
14-
${{ github.event.workflow_run.event == 'pull_request' &&
15-
github.event.workflow_run.conclusion == 'success' }}
14+
github.event.workflow_run.event == 'pull_request' &&
15+
github.event.workflow_run.conclusion == 'success'
16+
permissions:
17+
contents: write
1618
steps:
1719
- name: 'Download artifact'
1820
uses: carpentries/actions/download-workflow-artifact@main
@@ -23,7 +25,7 @@ jobs:
2325
id: get-pr
2426
run: |
2527
unzip pr.zip
26-
echo "::set-output name=NUM::$(<./NUM)"
28+
echo "NUM=$(<./NUM)" >> $GITHUB_OUTPUT
2729
- name: 'Remove branch'
2830
uses: carpentries/actions/remove-branch@main
2931
with:

.github/workflows/pr-preflight.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@ jobs:
1111
test-pr:
1212
name: "Test if pull request is valid"
1313
if: ${{ github.event.action != 'closed' }}
14-
runs-on: ubuntu-latest
14+
runs-on: ubuntu-22.04
1515
outputs:
1616
is_valid: ${{ steps.check-pr.outputs.VALID }}
17+
permissions:
18+
pull-requests: write
1719
steps:
1820
- name: "Get Invalid Hashes File"
1921
id: hash
2022
run: |
21-
echo "::set-output name=json::"$(curl -sL https://files.carpentries.org/invalid-hashes.json)
23+
echo "json<<EOF
24+
$(curl -sL https://files.carpentries.org/invalid-hashes.json)
25+
EOF" >> $GITHUB_OUTPUT
2226
- name: "Check PR"
2327
id: check-pr
2428
uses: carpentries/actions/check-valid-pr@main

0 commit comments

Comments
 (0)