-
-
Notifications
You must be signed in to change notification settings - Fork 400
132 lines (118 loc) · 3.87 KB
/
Copy pathdocker_apply_cache.yaml
File metadata and controls
132 lines (118 loc) · 3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
name: "03 Maintain: Apply Package Cache"
on:
workflow_dispatch:
inputs:
name:
description: 'Who triggered this build?'
required: true
default: 'Maintainer (via GitHub)'
pull_request:
types:
- closed
jobs:
preflight:
name: "Preflight: PR or Manual Trigger?"
runs-on: ubuntu-latest
outputs:
do-apply: ${{ steps.check.outputs.merged_or_manual }}
steps:
- name: "Should we run cache application?"
id: check
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ||
("${{ github.event.action }}" == "closed" && "${{ github.event.pull_request.merged }}" == "true") ]]; then
echo "merged_or_manual=true" >> $GITHUB_OUTPUT
else
echo "This was not a manual trigger and no PR was merged. No action taken."
echo "merged_or_manual=false" >> $GITHUB_OUTPUT
fi
check-renv:
name: "Check If We Need {renv}"
runs-on: ubuntu-latest
needs: preflight
if: ${{ needs.preflight.outputs.do-apply == 'true' }}
outputs:
renv-needed: ${{ steps.check-for-renv.outputs.exists }}
steps:
- name: "Checkout Lesson"
uses: actions/checkout@v4
- name: "Check for renv"
id: check-for-renv
run: |
if [[ -d renv ]]; then
echo "exists=true" >> $GITHUB_OUTPUT
fi
prepare:
name: "Grab renv.lock hash"
runs-on: ubuntu-latest
needs: check-renv
if: ${{ needs.check-renv.outputs.renv-needed == 'true' }}
outputs:
renv-cache-hashsum: ${{ steps.set-hash.outputs.renv-cache-hashsum }}
steps:
- uses: actions/checkout@v4
- name: Calculate renv hash
id: set-hash
run: |
echo "renv-cache-hashsum=${{ hashFiles('renv/profiles/lesson-requirements/renv.lock') }}" >> $GITHUB_OUTPUT
update-renv-cache:
name: "Update renv Cache"
if: |
github.event_name == 'workflow_dispatch' ||
(
github.event.pull_request.merged == true &&
contains(
join(github.event.pull_request.labels.*.name, ','),
'type: package cache'
)
)
runs-on: ubuntu-latest
needs: prepare
permissions:
checks: write
contents: write
pages: write
container:
image: carpentries/workbench-docker:${{ vars.WORKBENCH_TAG || 'latest' }}
env:
WORKBENCH_PROFILE: "ci"
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
RENV_PATHS_ROOT: /home/rstudio/lesson/renv
RENV_PROFILE: "lesson-requirements"
RENV_VERSION: ${{ needs.prepare.outputs.renv-cache-hashsum }}
RENV_CONFIG_EXTERNAL_LIBRARIES: "/usr/local/lib/R/site-library"
volumes:
- ${{ github.workspace }}:/home/rstudio/lesson
options: --cpus 2
steps:
- name: "Checkout Lesson"
uses: actions/checkout@v4
- name: Current env
run: env | sort
- name: Debugging Info
run: |
echo "Current Directory: $(pwd)"
ls -lah /home/rstudio/.workbench
ls -lah $(pwd)
Rscript -e 'sessionInfo()'
- name: Mark Repository as Safe
run: |
git config --global --add safe.directory $(pwd)
- name: "Ensure sandpaper is loadable"
run: |
.libPaths()
library(sandpaper)
shell: Rscript {0}
- name: Setup Lesson Dependencies
run: |
Rscript /home/rstudio/.workbench/setup_lesson_deps.R
- name: Fortify renv Cache
run: |
Rscript /home/rstudio/.workbench/fortify_renv_cache.R
- name: Cache renv Directory
uses: actions/cache@v4
with:
path: /home/rstudio/lesson/renv
key: ${{ runner.os }}-${{ inputs.cache-version }}-renv-${{ needs.prepare.outputs.renv-cache-hashsum }}
restore-keys:
${{ runner.os }}-${{ inputs.cache-version }}-renv-