Skip to content

Commit e52e6bd

Browse files
avallecamgithub-actions[bot]
authored andcommitted
[actions] update sandpaper workflow to version 1.0.0
1 parent d447009 commit e52e6bd

File tree

10 files changed

+1108
-226
lines changed

10 files changed

+1108
-226
lines changed

.github/workflows/README.md

Lines changed: 190 additions & 128 deletions
Large diffs are not rendered by default.
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
name: "03 Maintain: Apply Package Cache"
2+
description: "Generate the package cache for the lesson after a pull request has been merged or via manual trigger, and cache in S3 or GitHub"
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
name:
7+
description: 'Who triggered this build?'
8+
required: true
9+
default: 'Maintainer (via GitHub)'
10+
pull_request:
11+
types:
12+
- closed
13+
branches:
14+
- main
15+
16+
# queue cache runs
17+
concurrency:
18+
group: docker-apply-cache
19+
cancel-in-progress: false
20+
21+
jobs:
22+
preflight:
23+
name: "Preflight: PR or Manual Trigger?"
24+
runs-on: ubuntu-latest
25+
outputs:
26+
do-apply: ${{ steps.check.outputs.merged_or_manual }}
27+
steps:
28+
- name: "Should we run cache application?"
29+
id: check
30+
run: |
31+
if [[ "${{ github.event_name }}" == "workflow_dispatch" ||
32+
("${{ github.ref }}" == "refs/heads/main" && "${{ github.event.action }}" == "closed" && "${{ github.event.pull_request.merged }}" == "true") ]]; then
33+
echo "merged_or_manual=true" >> $GITHUB_OUTPUT
34+
else
35+
echo "This was not a manual trigger and no PR was merged. No action taken."
36+
echo "merged_or_manual=false" >> $GITHUB_OUTPUT
37+
fi
38+
shell: bash
39+
40+
check-renv:
41+
name: "Check If We Need {renv}"
42+
runs-on: ubuntu-latest
43+
needs: preflight
44+
if: needs.preflight.outputs.do-apply == 'true'
45+
permissions:
46+
id-token: write
47+
outputs:
48+
renv-needed: ${{ steps.check-for-renv.outputs.renv-needed }}
49+
renv-cache-hashsum: ${{ steps.check-for-renv.outputs.renv-cache-hashsum }}
50+
renv-cache-available: ${{ steps.check-for-renv.outputs.renv-cache-available }}
51+
steps:
52+
- name: "Check for renv"
53+
id: check-for-renv
54+
uses: carpentries/actions/renv-checks@main
55+
with:
56+
role-to-assume: ${{ secrets.AWS_GH_OIDC_ARN }}
57+
aws-region: ${{ secrets.AWS_GH_OIDC_REGION }}
58+
WORKBENCH_TAG: ${{ vars.WORKBENCH_TAG || 'latest' }}
59+
token: ${{ secrets.GITHUB_TOKEN }}
60+
61+
no-renv-cache-used:
62+
name: "No renv cache used"
63+
runs-on: ubuntu-latest
64+
needs: check-renv
65+
if: needs.check-renv.outputs.renv-needed != 'true'
66+
steps:
67+
- name: "No renv cache needed"
68+
run: echo "No renv cache needed for this lesson"
69+
70+
renv-cache-available:
71+
name: "renv cache available"
72+
runs-on: ubuntu-latest
73+
needs: check-renv
74+
if: needs.check-renv.outputs.renv-cache-available == 'true'
75+
steps:
76+
- name: "renv cache available"
77+
run: echo "renv cache available for this lesson"
78+
79+
update-renv-cache:
80+
name: "Update renv Cache"
81+
runs-on: ubuntu-latest
82+
needs: check-renv
83+
if: |
84+
needs.check-renv.outputs.renv-needed == 'true' &&
85+
needs.check-renv.outputs.renv-cache-available != 'true' &&
86+
(
87+
github.event_name == 'workflow_dispatch' ||
88+
(
89+
github.event.pull_request.merged == true &&
90+
(
91+
(
92+
contains(
93+
join(github.event.pull_request.labels.*.name, ','),
94+
'type: package cache'
95+
) &&
96+
github.event.pull_request.head.ref == 'update/packages'
97+
)
98+
||
99+
(
100+
contains(
101+
join(github.event.pull_request.labels.*.name, ','),
102+
'type: workflows'
103+
) &&
104+
github.event.pull_request.head.ref == 'update/workflows'
105+
)
106+
||
107+
(
108+
contains(
109+
join(github.event.pull_request.labels.*.name, ','),
110+
'type: docker version'
111+
) &&
112+
github.event.pull_request.head.ref == 'update/workbench-docker-version'
113+
)
114+
)
115+
)
116+
)
117+
permissions:
118+
checks: write
119+
contents: write
120+
pages: write
121+
id-token: write
122+
container:
123+
image: ghcr.io/carpentries/workbench-docker:${{ vars.WORKBENCH_TAG || 'latest' }}
124+
env:
125+
WORKBENCH_PROFILE: "ci"
126+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
127+
RENV_PATHS_ROOT: /home/rstudio/lesson/renv
128+
RENV_PROFILE: "lesson-requirements"
129+
RENV_VERSION: ${{ needs.check-renv.outputs.renv-cache-hashsum }}
130+
RENV_CONFIG_EXTERNAL_LIBRARIES: "/usr/local/lib/R/site-library"
131+
volumes:
132+
- ${{ github.workspace }}:/home/rstudio/lesson
133+
options: --cpus 2
134+
steps:
135+
- uses: actions/checkout@v4
136+
137+
- name: "Debugging Info"
138+
run: |
139+
echo "Current Directory: $(pwd)"
140+
ls -lah /home/rstudio/.workbench
141+
ls -lah $(pwd)
142+
Rscript -e 'sessionInfo()'
143+
shell: bash
144+
145+
- name: "Mark Repository as Safe"
146+
run: |
147+
git config --global --add safe.directory $(pwd)
148+
shell: bash
149+
150+
- name: "Ensure sandpaper is loadable"
151+
run: |
152+
.libPaths()
153+
library(sandpaper)
154+
shell: Rscript {0}
155+
156+
- name: "Setup Lesson Dependencies"
157+
run: |
158+
Rscript /home/rstudio/.workbench/setup_lesson_deps.R
159+
shell: bash
160+
161+
- name: "Fortify renv Cache"
162+
run: |
163+
Rscript /home/rstudio/.workbench/fortify_renv_cache.R
164+
shell: bash
165+
166+
- name: "Get Container Version Used"
167+
id: wb-vers
168+
uses: carpentries/actions/container-version@main
169+
with:
170+
WORKBENCH_TAG: ${{ vars.WORKBENCH_TAG }}
171+
renv-needed: ${{ needs.check-renv.outputs.renv-needed }}
172+
token: ${{ secrets.GITHUB_TOKEN }}
173+
174+
- name: "Validate Current Org and Workflow"
175+
id: validate-org-workflow
176+
uses: carpentries/actions/validate-org-workflow@main
177+
with:
178+
repo: ${{ github.repository }}
179+
workflow: ${{ github.workflow }}
180+
181+
- name: "Configure AWS credentials via OIDC"
182+
id: aws-creds
183+
env:
184+
role-to-assume: ${{ secrets.AWS_GH_OIDC_ARN }}
185+
aws-region: ${{ secrets.AWS_GH_OIDC_REGION }}
186+
if: |
187+
steps.validate-org-workflow.outputs.is_valid == 'true' &&
188+
env.role-to-assume != '' &&
189+
env.aws-region != ''
190+
uses: aws-actions/configure-aws-credentials@v5.0.0
191+
with:
192+
role-to-assume: ${{ env.role-to-assume }}
193+
aws-region: ${{ env.aws-region }}
194+
output-credentials: true
195+
196+
- name: "Upload cache object to S3"
197+
id: upload-cache
198+
uses: carpentries/actions-cache@frog-matchedkey-1
199+
with:
200+
accessKey: ${{ steps.aws-creds.outputs.aws-access-key-id }}
201+
secretKey: ${{ steps.aws-creds.outputs.aws-secret-access-key }}
202+
sessionToken: ${{ steps.aws-creds.outputs.aws-session-token }}
203+
bucket: workbench-docker-caches
204+
path: |
205+
/home/rstudio/lesson/renv
206+
/usr/local/lib/R/site-library
207+
key: ${{ github.repository }}/${{ steps.wb-vers.outputs.container-version }}_renv-${{ needs.check-renv.outputs.renv-cache-hashsum }}
208+
restore-keys:
209+
${{ github.repository }}/${{ steps.wb-vers.outputs.container-version }}_renv-
210+
211+
record-cache-result:
212+
name: "Record Caching Status"
213+
runs-on: ubuntu-latest
214+
needs: [check-renv, update-renv-cache]
215+
if: always()
216+
env:
217+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
218+
steps:
219+
- name: "Record cache result"
220+
221+
run: |
222+
echo "${{ needs.update-renv-cache.result == 'success' || needs.check-renv.outputs.renv-cache-available == 'true' || 'false' }}" > ${{ github.workspace }}/apply-cache-result
223+
shell: bash
224+
225+
- name: "Upload cache result"
226+
uses: actions/upload-artifact@v4
227+
with:
228+
name: apply-cache-result
229+
path: ${{ github.workspace }}/apply-cache-result
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
name: "01 Maintain: Build and Deploy Site"
2+
description: "Build and deploy the lesson site using the carpentries/workbench-docker container"
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
- 'l10n_main'
8+
paths-ignore:
9+
- '.github/workflows/**.yaml'
10+
- '.github/workbench-docker-version.txt'
11+
schedule:
12+
- cron: '0 0 * * 2'
13+
workflow_run:
14+
workflows: ["03 Maintain: Apply Package Cache"]
15+
types:
16+
- completed
17+
workflow_dispatch:
18+
inputs:
19+
name:
20+
description: 'Who triggered this build?'
21+
required: true
22+
default: 'Maintainer (via GitHub)'
23+
CACHE_VERSION:
24+
description: 'Optional renv cache version override'
25+
required: false
26+
default: ''
27+
reset:
28+
description: 'Reset cached markdown files'
29+
required: true
30+
default: false
31+
type: boolean
32+
force-skip-manage-deps:
33+
description: 'Skip build-time dependency management'
34+
required: true
35+
default: false
36+
type: boolean
37+
38+
# only one build/deploy at a time
39+
concurrency:
40+
group: docker-build-deploy
41+
cancel-in-progress: true
42+
43+
jobs:
44+
preflight:
45+
name: "Preflight: Schedule, Push, or PR?"
46+
runs-on: ubuntu-latest
47+
outputs:
48+
do-build: ${{ steps.build-check.outputs.do-build }}
49+
renv-needed: ${{ steps.build-check.outputs.renv-needed }}
50+
renv-cache-hashsum: ${{ steps.build-check.outputs.renv-cache-hashsum }}
51+
workbench-container-file-exists: ${{ steps.wb-vers.outputs.workbench-container-file-exists }}
52+
wb-vers: ${{ steps.wb-vers.outputs.container-version }}
53+
last-wb-vers: ${{ steps.wb-vers.outputs.last-container-version }}
54+
workbench-update: ${{ steps.wb-vers.outputs.workbench-update }}
55+
env:
56+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57+
steps:
58+
- name: "Should we run build and deploy?"
59+
id: build-check
60+
uses: carpentries/actions/build-preflight@main
61+
62+
- name: "Checkout Lesson"
63+
if: steps.build-check.outputs.do-build == 'true'
64+
uses: actions/checkout@v4
65+
66+
- name: "Get container version info"
67+
id: wb-vers
68+
if: steps.build-check.outputs.do-build == 'true'
69+
uses: carpentries/actions/container-version@main
70+
with:
71+
WORKBENCH_TAG: ${{ vars.WORKBENCH_TAG }}
72+
renv-needed: ${{ steps.build-check.outputs.renv-needed }}
73+
token: ${{ secrets.GITHUB_TOKEN }}
74+
75+
full-build:
76+
name: "Build Full Site"
77+
runs-on: ubuntu-latest
78+
needs: preflight
79+
if: |
80+
needs.preflight.outputs.do-build == 'true' &&
81+
needs.preflight.outputs.workbench-update != 'true'
82+
env:
83+
RENV_EXISTS: ${{ needs.preflight.outputs.renv-needed }}
84+
RENV_HASH: ${{ needs.preflight.outputs.renv-cache-hashsum }}
85+
permissions:
86+
checks: write
87+
contents: write
88+
pages: write
89+
id-token: write
90+
container:
91+
image: ghcr.io/carpentries/workbench-docker:${{ vars.WORKBENCH_TAG || 'latest' }}
92+
env:
93+
WORKBENCH_PROFILE: "ci"
94+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
95+
RENV_PATHS_ROOT: /home/rstudio/lesson/renv
96+
RENV_PROFILE: "lesson-requirements"
97+
RENV_CONFIG_EXTERNAL_LIBRARIES: "/usr/local/lib/R/site-library"
98+
volumes:
99+
- ${{ github.workspace }}:/home/rstudio/lesson
100+
options: --cpus 1
101+
steps:
102+
- uses: actions/checkout@v4
103+
104+
- name: "Debugging Info"
105+
run: |
106+
cd /home/rstudio/lesson
107+
echo "Current Directory: $(pwd)"
108+
echo "RENV_HASH is $RENV_HASH"
109+
ls -lah /home/rstudio/.workbench
110+
ls -lah $(pwd)
111+
Rscript -e 'sessionInfo()'
112+
shell: bash
113+
114+
- name: "Mark Repository as Safe"
115+
run: |
116+
git config --global --add safe.directory $(pwd)
117+
shell: bash
118+
119+
- name: "Setup Lesson Dependencies"
120+
id: build-container-deps
121+
uses: carpentries/actions/build-container-deps@main
122+
with:
123+
CACHE_VERSION: ${{ vars.CACHE_VERSION || github.event.inputs.CACHE_VERSION || '' }}
124+
WORKBENCH_TAG: ${{ vars.WORKBENCH_TAG || 'latest' }}
125+
LESSON_PATH: ${{ vars.LESSON_PATH || '/home/rstudio/lesson' }}
126+
role-to-assume: ${{ secrets.AWS_GH_OIDC_ARN }}
127+
aws-region: ${{ secrets.AWS_GH_OIDC_REGION }}
128+
token: ${{ secrets.GITHUB_TOKEN }}
129+
130+
- name: "Run Container and Build Site"
131+
id: build-and-deploy
132+
uses: carpentries/actions/build-and-deploy@main
133+
with:
134+
reset: ${{ vars.BUILD_RESET || github.event.inputs.reset || 'false' }}
135+
skip-manage-deps: ${{ github.event.inputs.force-skip-manage-deps == 'true' || steps.build-container-deps.outputs.renv-cache-available || steps.build-container-deps.outputs.backup-cache-used || 'false' }}
136+
lang-code: ${{ vars.LANG_CODE || '' }}
137+
138+
update-container-version:
139+
name: "Update container version used"
140+
runs-on: ubuntu-latest
141+
needs: [preflight]
142+
permissions:
143+
actions: write
144+
contents: write
145+
pull-requests: write
146+
id-token: write
147+
if: |
148+
needs.preflight.outputs.do-build == 'true' &&
149+
(
150+
needs.preflight.outputs.workbench-container-file-exists == 'false' ||
151+
needs.preflight.outputs.workbench-update == 'true'
152+
)
153+
steps:
154+
- name: "Record container version used"
155+
uses: carpentries/actions/record-container-version@main
156+
with:
157+
CONTAINER_VER: ${{ needs.preflight.outputs.wb-vers }}
158+
AUTO_MERGE: ${{ vars.AUTO_MERGE_CONTAINER_VERSION_UPDATE || 'true' }}
159+
token: ${{ secrets.GITHUB_TOKEN }}
160+
role-to-assume: ${{ secrets.AWS_GH_OIDC_ARN }}
161+
aws-region: ${{ secrets.AWS_GH_OIDC_REGION }}

0 commit comments

Comments
 (0)