Skip to content

Commit 2f83f08

Browse files
authored
Merge pull request #156 from LibraryCarpentry/update/workflows
Update Workflows to Version 0.18.3
2 parents 7c04db9 + c611e04 commit 2f83f08

File tree

9 files changed

+1137
-167
lines changed

9 files changed

+1137
-167
lines changed

.github/workflows/README.md

Lines changed: 180 additions & 66 deletions
Large diffs are not rendered by default.
Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
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+
trigger-build-deploy:
212+
name: "Trigger Build and Deploy Workflow"
213+
runs-on: ubuntu-latest
214+
needs: update-renv-cache
215+
if: |
216+
needs.update-renv-cache.result == 'success' ||
217+
needs.check-renv.outputs.renv-cache-available == 'true'
218+
steps:
219+
- uses: actions/checkout@v4
220+
221+
- name: "Trigger Build and Deploy Workflow"
222+
env:
223+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
224+
run: |
225+
gh workflow run docker_build_deploy.yaml --ref main
226+
shell: bash
227+
continue-on-error: true
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
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+
paths-ignore:
8+
- '.github/workflows/**.yaml'
9+
- '.github/workbench-docker-version.txt'
10+
schedule:
11+
- cron: '0 0 * * 2'
12+
workflow_dispatch:
13+
inputs:
14+
name:
15+
description: 'Who triggered this build?'
16+
required: true
17+
default: 'Maintainer (via GitHub)'
18+
CACHE_VERSION:
19+
description: 'Optional renv cache version override'
20+
required: false
21+
default: ''
22+
reset:
23+
description: 'Reset cached markdown files'
24+
required: true
25+
default: false
26+
type: boolean
27+
force-skip-manage-deps:
28+
description: 'Skip build-time dependency management'
29+
required: true
30+
default: false
31+
type: boolean
32+
33+
# only one build/deploy at a time
34+
concurrency:
35+
group: docker-build-deploy
36+
cancel-in-progress: true
37+
38+
jobs:
39+
preflight:
40+
name: "Preflight: Schedule, Push, or PR?"
41+
runs-on: ubuntu-latest
42+
outputs:
43+
do-build: ${{ steps.build-check.outputs.do-build }}
44+
renv-needed: ${{ steps.build-check.outputs.renv-needed }}
45+
renv-cache-hashsum: ${{ steps.build-check.outputs.renv-cache-hashsum }}
46+
workbench-container-file-exists: ${{ steps.wb-vers.outputs.workbench-container-file-exists }}
47+
wb-vers: ${{ steps.wb-vers.outputs.container-version }}
48+
last-wb-vers: ${{ steps.wb-vers.outputs.last-container-version }}
49+
workbench-update: ${{ steps.wb-vers.outputs.workbench-update }}
50+
env:
51+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52+
steps:
53+
- name: "Should we run build and deploy?"
54+
id: build-check
55+
uses: carpentries/actions/build-preflight@main
56+
57+
- name: "Checkout Lesson"
58+
if: steps.build-check.outputs.do-build == 'true'
59+
uses: actions/checkout@v4
60+
61+
- name: "Get container version info"
62+
id: wb-vers
63+
if: steps.build-check.outputs.do-build == 'true'
64+
uses: carpentries/actions/container-version@main
65+
with:
66+
WORKBENCH_TAG: ${{ vars.WORKBENCH_TAG }}
67+
renv-needed: ${{ steps.build-check.outputs.renv-needed }}
68+
token: ${{ secrets.GITHUB_TOKEN }}
69+
70+
full-build:
71+
name: "Build Full Site"
72+
runs-on: ubuntu-latest
73+
needs: preflight
74+
if: |
75+
always() &&
76+
needs.preflight.outputs.do-build == 'true' &&
77+
needs.preflight.outputs.workbench-update != 'true'
78+
env:
79+
RENV_EXISTS: ${{ needs.preflight.outputs.renv-needed }}
80+
RENV_HASH: ${{ needs.preflight.outputs.renv-cache-hashsum }}
81+
permissions:
82+
checks: write
83+
contents: write
84+
pages: write
85+
id-token: write
86+
container:
87+
image: ghcr.io/carpentries/workbench-docker:${{ vars.WORKBENCH_TAG || 'latest' }}
88+
env:
89+
WORKBENCH_PROFILE: "ci"
90+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
91+
RENV_PATHS_ROOT: /home/rstudio/lesson/renv
92+
RENV_PROFILE: "lesson-requirements"
93+
RENV_CONFIG_EXTERNAL_LIBRARIES: "/usr/local/lib/R/site-library"
94+
volumes:
95+
- ${{ github.workspace }}:/home/rstudio/lesson
96+
options: --cpus 1
97+
steps:
98+
- uses: actions/checkout@v4
99+
100+
- name: "Debugging Info"
101+
run: |
102+
cd /home/rstudio/lesson
103+
echo "Current Directory: $(pwd)"
104+
echo "RENV_HASH is $RENV_HASH"
105+
ls -lah /home/rstudio/.workbench
106+
ls -lah $(pwd)
107+
Rscript -e 'sessionInfo()'
108+
shell: bash
109+
110+
- name: "Mark Repository as Safe"
111+
run: |
112+
git config --global --add safe.directory $(pwd)
113+
shell: bash
114+
115+
- name: "Setup Lesson Dependencies"
116+
id: build-container-deps
117+
uses: carpentries/actions/build-container-deps@main
118+
with:
119+
CACHE_VERSION: ${{ vars.CACHE_VERSION || github.event.inputs.CACHE_VERSION || '' }}
120+
WORKBENCH_TAG: ${{ vars.WORKBENCH_TAG || 'latest' }}
121+
LESSON_PATH: ${{ vars.LESSON_PATH || '/home/rstudio/lesson' }}
122+
role-to-assume: ${{ secrets.AWS_GH_OIDC_ARN }}
123+
aws-region: ${{ secrets.AWS_GH_OIDC_REGION }}
124+
token: ${{ secrets.GITHUB_TOKEN }}
125+
126+
- name: "Run Container and Build Site"
127+
id: build-and-deploy
128+
uses: carpentries/actions/build-and-deploy@main
129+
with:
130+
reset: ${{ github.event.inputs.reset || 'false' }}
131+
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' }}
132+
133+
update-container-version:
134+
name: "Update container version used"
135+
runs-on: ubuntu-latest
136+
needs: [preflight]
137+
permissions:
138+
actions: write
139+
contents: write
140+
pull-requests: write
141+
id-token: write
142+
if: |
143+
needs.preflight.outputs.do-build == 'true' &&
144+
(
145+
needs.preflight.outputs.workbench-container-file-exists == 'false' ||
146+
needs.preflight.outputs.workbench-update == 'true'
147+
)
148+
steps:
149+
- name: "Record container version used"
150+
uses: carpentries/actions/record-container-version@main
151+
with:
152+
CONTAINER_VER: ${{ needs.preflight.outputs.wb-vers }}
153+
token: ${{ secrets.GITHUB_TOKEN }}
154+
role-to-assume: ${{ secrets.AWS_GH_OIDC_ARN }}
155+
aws-region: ${{ secrets.AWS_GH_OIDC_REGION }}

0 commit comments

Comments
 (0)