Skip to content

Commit b218a05

Browse files
jt14dengithub-actions[bot]
authored andcommitted
[actions] update sandpaper workflow to version v1.0.4
1 parent 577da69 commit b218a05

12 files changed

Lines changed: 1111 additions & 246 deletions

‎.github/workflows/README.md‎

Lines changed: 243 additions & 128 deletions
Large diffs are not rendered by default.
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
name: "03 Maintain: Apply Package Cache"
2+
description: "Build and publish the lesson dependency image after a pull request has been merged or via manual trigger"
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
name:
7+
description: 'Who triggered this build?'
8+
required: true
9+
default: 'Maintainer (via GitHub)'
10+
force-dependency-image-rebuild:
11+
description: 'Rebuild the dependency image layer even if one already exists?'
12+
required: false
13+
default: false
14+
type: boolean
15+
prune-keep-count:
16+
description: 'How many existing dependency image layers to keep?'
17+
required: false
18+
default: 1
19+
type: number
20+
pull_request:
21+
types:
22+
- closed
23+
branches:
24+
- main
25+
26+
# queue cache runs
27+
concurrency:
28+
group: docker-apply-cache
29+
cancel-in-progress: false
30+
31+
jobs:
32+
preflight:
33+
name: "Preflight: PR or Manual Trigger?"
34+
runs-on: ubuntu-latest
35+
outputs:
36+
do-apply: ${{ steps.check.outputs.merged_or_manual }}
37+
steps:
38+
- name: "Should we run cache application?"
39+
id: check
40+
run: |
41+
if [[ "${{ github.event_name }}" == "workflow_dispatch" ||
42+
("${{ github.ref }}" == "refs/heads/main" && "${{ github.event.action }}" == "closed" && "${{ github.event.pull_request.merged }}" == "true") ]]; then
43+
echo "merged_or_manual=true" >> $GITHUB_OUTPUT
44+
else
45+
echo "This was not a manual trigger and no PR was merged. No action taken."
46+
echo "merged_or_manual=false" >> $GITHUB_OUTPUT
47+
fi
48+
shell: bash
49+
50+
check-renv:
51+
name: "Check If We Need {renv}"
52+
runs-on: ubuntu-latest
53+
needs: preflight
54+
if: needs.preflight.outputs.do-apply == 'true'
55+
outputs:
56+
renv-needed: ${{ steps.check-for-renv.outputs.renv-needed }}
57+
renv-cache-hashsum: ${{ steps.check-for-renv.outputs.renv-cache-hashsum }}
58+
steps:
59+
- name: "Check for renv"
60+
id: check-for-renv
61+
uses: carpentries/actions/renv-checks@v1
62+
with:
63+
WORKBENCH_TAG: ${{ vars.WORKBENCH_TAG || 'latest' }}
64+
skip-cache-check: true
65+
66+
no-renv-cache-used:
67+
name: "No renv package dependency image needed"
68+
runs-on: ubuntu-latest
69+
needs: check-renv
70+
if: needs.check-renv.outputs.renv-needed != 'true'
71+
steps:
72+
- name: "No dependency image needed"
73+
run: echo "No renv dependency image needed for this lesson"
74+
75+
update-renv-cache:
76+
name: "Publish renv package dependency image"
77+
runs-on: ubuntu-latest
78+
needs: check-renv
79+
if: needs.check-renv.outputs.renv-needed == 'true'
80+
permissions:
81+
contents: read
82+
packages: write
83+
steps:
84+
- uses: actions/checkout@v6
85+
86+
- name: "Get Container Version Used"
87+
id: wb-vers
88+
uses: carpentries/actions/container-version@v1
89+
with:
90+
WORKBENCH_TAG: ${{ vars.WORKBENCH_TAG }}
91+
renv-needed: ${{ needs.check-renv.outputs.renv-needed }}
92+
token: ${{ secrets.GITHUB_TOKEN }}
93+
94+
- name: Log in to GHCR
95+
uses: docker/login-action@v4
96+
with:
97+
registry: ghcr.io
98+
username: ${{ github.actor }}
99+
password: ${{ secrets.GITHUB_TOKEN }}
100+
101+
- name: Set dependency image tags
102+
id: image
103+
env:
104+
IMAGE_OWNER: ${{ github.repository_owner }}
105+
IMAGE_NAME: ${{ github.event.repository.name }}
106+
WB_VERSION: ${{ steps.wb-vers.outputs.container-version }}
107+
RENV_HASH: ${{ needs.check-renv.outputs.renv-cache-hashsum }}
108+
run: |
109+
set -euo pipefail
110+
exact_image="ghcr.io/${IMAGE_OWNER}/${IMAGE_NAME}-deps:${WB_VERSION}_renv-${RENV_HASH}"
111+
latest_image="ghcr.io/${IMAGE_OWNER}/${IMAGE_NAME}-deps:latest"
112+
113+
# lowercaseify
114+
echo "exact_image=${exact_image,,}" >> "$GITHUB_OUTPUT"
115+
echo "latest_image=${latest_image,,}" >> "$GITHUB_OUTPUT"
116+
shell: bash
117+
118+
- name: Check for existing dependency image tag
119+
id: image-exists
120+
env:
121+
EXACT_IMAGE: ${{ steps.image.outputs.exact_image }}
122+
run: |
123+
set -euo pipefail
124+
if docker manifest inspect "${EXACT_IMAGE}" >/dev/null 2>&1; then
125+
echo "exists=true" >> "$GITHUB_OUTPUT"
126+
echo "## ⚠️ Dependency image already exists" >> $GITHUB_STEP_SUMMARY
127+
echo "Dependency image already exists for this renv hash: ${EXACT_IMAGE}" >> $GITHUB_STEP_SUMMARY
128+
echo "Dependency image already exists for this renv hash: ${EXACT_IMAGE}"
129+
else
130+
echo "exists=false" >> "$GITHUB_OUTPUT"
131+
echo "No existing dependency image found for this renv hash: ${EXACT_IMAGE}"
132+
fi
133+
shell: bash
134+
135+
- name: Build and push dependency image layer
136+
id: build-push-deps-layer
137+
if: |
138+
steps.image-exists.outputs.exists != 'true' ||
139+
(
140+
github.event_name == 'workflow_dispatch' &&
141+
github.event.inputs.force-dependency-image-rebuild == 'true'
142+
)
143+
uses: carpentries/actions/build-dependency-image@v1
144+
with:
145+
workbench-tag: ${{ vars.WORKBENCH_TAG || 'latest' }}
146+
github-token: ${{ secrets.GITHUB_TOKEN }}
147+
github-repository: ${{ github.repository }}
148+
github-sha: ${{ github.sha }}
149+
exact-image: ${{ steps.image.outputs.exact_image }}
150+
latest-image: ${{ steps.image.outputs.latest_image }}
151+
build-context: ${{ github.workspace }}
152+
153+
prune-dependency-images:
154+
name: "Prune Dependency Images"
155+
runs-on: ubuntu-latest
156+
needs: check-renv
157+
permissions:
158+
contents: read
159+
packages: write
160+
steps:
161+
- name: Prune any old dependency image layers
162+
uses: carpentries/actions/prune-dependency-images@v1
163+
if: needs.check-renv.outputs.renv-needed == 'true'
164+
with:
165+
github-token: ${{ secrets.GITHUB_TOKEN }}
166+
owner: ${{ github.repository_owner }}
167+
owner-type: ${{ github.event.repository.owner.type }}
168+
repository: ${{ github.event.repository.name }}
169+
package-name: ${{ github.event.repository.name }}-deps
170+
keep-count: ${{ github.event.inputs.prune-keep-count }}
171+
continue-on-error: true
172+
173+
record-cache-result:
174+
name: "Record Caching Status"
175+
runs-on: ubuntu-latest
176+
needs: [check-renv, update-renv-cache]
177+
if: always()
178+
env:
179+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
180+
steps:
181+
- name: "Record cache result"
182+
run: |
183+
echo "${{ needs.check-renv.outputs.renv-needed != 'true' || needs.update-renv-cache.result == 'success' }}" > ${{ github.workspace }}/apply-cache-result
184+
shell: bash
185+
186+
- name: "Upload cache result"
187+
uses: actions/upload-artifact@v7
188+
with:
189+
name: apply-cache-result
190+
path: ${{ github.workspace }}/apply-cache-result
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
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+
- '.devcontainer'
12+
schedule:
13+
- cron: '0 0 * * 2'
14+
workflow_run:
15+
workflows: ["03 Maintain: Apply Package Cache"]
16+
types:
17+
- completed
18+
workflow_dispatch:
19+
inputs:
20+
name:
21+
description: 'Who triggered this build?'
22+
required: true
23+
default: 'Maintainer (via GitHub)'
24+
CACHE_VERSION:
25+
description: 'Optional renv cache version override'
26+
required: false
27+
default: ''
28+
reset:
29+
description: 'Reset cached markdown files'
30+
required: true
31+
default: false
32+
type: boolean
33+
force-skip-manage-deps:
34+
description: 'Skip build-time dependency management'
35+
required: true
36+
default: false
37+
type: boolean
38+
39+
# only one build/deploy at a time
40+
concurrency:
41+
group: docker-build-deploy-${{ github.event_name }}
42+
cancel-in-progress: true
43+
44+
jobs:
45+
preflight:
46+
name: "Preflight: Schedule, Push, or PR?"
47+
runs-on: ubuntu-latest
48+
outputs:
49+
do-build: ${{ steps.build-check.outputs.do-build }}
50+
renv-needed: ${{ steps.build-check.outputs.renv-needed }}
51+
renv-cache-hashsum: ${{ steps.build-check.outputs.renv-cache-hashsum }}
52+
dependency-image-ref: ${{ steps.build-check.outputs.dependency-image-ref }}
53+
workbench-container-file-exists: ${{ steps.wb-vers.outputs.workbench-container-file-exists }}
54+
wb-vers: ${{ steps.wb-vers.outputs.container-version }}
55+
last-wb-vers: ${{ steps.wb-vers.outputs.last-container-version }}
56+
workbench-update: ${{ steps.wb-vers.outputs.workbench-update }}
57+
env:
58+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59+
steps:
60+
- name: "Should we run build and deploy?"
61+
id: build-check
62+
uses: carpentries/actions/build-preflight@v1
63+
64+
- name: "Checkout Lesson"
65+
if: steps.build-check.outputs.do-build == 'true'
66+
uses: actions/checkout@v6
67+
68+
- name: "Get container version info"
69+
id: wb-vers
70+
if: steps.build-check.outputs.do-build == 'true'
71+
uses: carpentries/actions/container-version@v1
72+
with:
73+
WORKBENCH_TAG: ${{ vars.WORKBENCH_TAG }}
74+
renv-needed: ${{ steps.build-check.outputs.renv-needed }}
75+
token: ${{ secrets.GITHUB_TOKEN }}
76+
77+
full-build:
78+
name: "Build Full Site"
79+
runs-on: ubuntu-latest
80+
needs: preflight
81+
if: |
82+
needs.preflight.outputs.do-build == 'true' &&
83+
needs.preflight.outputs.workbench-update != 'true'
84+
env:
85+
RENV_EXISTS: ${{ needs.preflight.outputs.renv-needed }}
86+
RENV_HASH: ${{ needs.preflight.outputs.renv-cache-hashsum }}
87+
permissions:
88+
checks: write
89+
contents: write
90+
pages: write
91+
container:
92+
image: ${{ needs.preflight.outputs.dependency-image-ref }}
93+
env:
94+
WORKBENCH_PROFILE: "ci"
95+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
96+
RENV_PATHS_ROOT: /home/rstudio/lesson/renv
97+
RENV_PROFILE: "lesson-requirements"
98+
RENV_CONFIG_EXTERNAL_LIBRARIES: "/usr/local/lib/R/site-library"
99+
WORKBENCH_OVERLAY_CUSTOMIZATION: ${{ vars.WORKBENCH_OVERLAY_CUSTOMIZATION || '' }}
100+
volumes:
101+
- ${{ github.workspace }}:/home/rstudio/lesson
102+
options: --cpus 1
103+
steps:
104+
- uses: actions/checkout@v6
105+
106+
- name: "Debugging Info"
107+
run: |
108+
cd /home/rstudio/lesson
109+
echo "Current Directory: $(pwd)"
110+
echo "RENV_HASH is $RENV_HASH"
111+
ls -lah /home/rstudio/.workbench
112+
ls -lah $(pwd)
113+
Rscript -e 'sessionInfo()'
114+
shell: bash
115+
116+
- name: "Mark Repository as Safe"
117+
run: |
118+
git config --global --add safe.directory $(pwd)
119+
shell: bash
120+
121+
- name: "Run Container and Build Site"
122+
id: build-and-deploy
123+
uses: carpentries/actions/build-and-deploy@v1
124+
with:
125+
reset: ${{ vars.BUILD_RESET || github.event.inputs.reset || 'false' }}
126+
skip-manage-deps: ${{ github.event.inputs.force-skip-manage-deps == 'true' || contains(needs.preflight.outputs.dependency-image-ref, '-deps:') }}
127+
lang-code: ${{ vars.LANG_CODE || '' }}
128+
129+
update-container-version:
130+
name: "Update container version used"
131+
runs-on: ubuntu-latest
132+
needs: [preflight]
133+
permissions:
134+
actions: write
135+
contents: write
136+
pull-requests: write
137+
id-token: write
138+
if: |
139+
needs.preflight.outputs.do-build == 'true' &&
140+
(
141+
needs.preflight.outputs.workbench-container-file-exists == 'false' ||
142+
needs.preflight.outputs.workbench-update == 'true'
143+
)
144+
steps:
145+
- name: "Record container version used"
146+
uses: carpentries/actions/record-container-version@v1
147+
with:
148+
CONTAINER_VER: ${{ needs.preflight.outputs.wb-vers }}
149+
OMIT_PR: ${{ vars.OMIT_PR_CONTAINER_VERSION_UPDATE || 'false' }}
150+
AUTO_MERGE: ${{ vars.AUTO_MERGE_CONTAINER_VERSION_UPDATE || 'false' }}
151+
token: ${{ secrets.GITHUB_TOKEN }}
152+
role-to-assume: ${{ secrets.AWS_GH_OIDC_ARN }}
153+
aws-region: ${{ secrets.AWS_GH_OIDC_REGION }}

0 commit comments

Comments
 (0)