1- # .github/workflows/renv-update .yml
2- name : Update R dependencies ( renv)
1+ # .github/workflows/renv-bootstrap-or-restore .yml
2+ name : Bootstrap or Restore renv
33
44on :
5- schedule :
6- - cron : " 0 6 * * 1" # Mondays at 06:00 UTC
75 workflow_dispatch :
6+ schedule :
7+ - cron : " 0 6 * * 1" # Mondays 06:00 UTC
88
99jobs :
10- renv-update :
10+ renv :
1111 runs-on : ubuntu-latest
1212 steps :
1313 - uses : actions/checkout@v4
14- with :
15- fetch-depth : 0
14+ with : { fetch-depth: 0 }
1615
1716 - uses : r-lib/actions/setup-r@v2
1817 with :
@@ -21,19 +20,33 @@ jobs:
2120 - name : Install renv
2221 run : Rscript -e 'install.packages("renv", repos="https://cloud.r-project.org")'
2322
24- - name : Restore library
25- run : Rscript -e 'renv::restore(prompt = FALSE)'
23+ - name : Bootstrap or restore
24+ id : renv
25+ run : |
26+ Rscript - <<'RSCRIPT'
27+ if (!file.exists("renv.lock")) {
28+ message("No renv.lock found — bootstrapping…")
29+ renv::init(bare = TRUE)
30+ # Optionally install dev deps here, e.g.:
31+ # renv::install(c("devtools","roxygen2","testthat"))
32+ renv::snapshot(prompt = FALSE)
33+ cat("BOOTSTRAPPED=1\n", file = Sys.getenv("GITHUB_OUTPUT"), append = TRUE)
34+ } else {
35+ message("renv.lock found — restoring…")
36+ renv::restore(prompt = FALSE)
37+ cat("BOOTSTRAPPED=0\n", file = Sys.getenv("GITHUB_OUTPUT"), append = TRUE)
38+ }
39+ RSCRIPT
2640
27- - name : Update lockfile
28- run : Rscript -e 'renv::update(); renv::snapshot(prompt = FALSE, force = TRUE)'
29-
30- - name : Create PR if changed
41+ - name : Create PR with initial lockfile
42+ if : steps.renv.outputs.BOOTSTRAPPED == '1'
3143 uses : peter-evans/create-pull-request@v6
3244 with :
33- commit-message : " chore(renv): update R dependencies and lockfile"
34- title : " chore(renv): update R dependencies "
35- body : " Automated weekly update of R packages via renv."
36- branch : " chore/renv-update "
45+ commit-message : " chore(renv): initialize renv and add lockfile"
46+ title : " chore(renv): bootstrap renv "
47+ body : " Initial `renv` setup: adds `.Rprofile`, `renv/activate.R`, and ` renv.lock` ."
48+ branch : " chore/renv-bootstrap "
3749 labels : dependencies,R
3850 reviewers : diogoribeiro7
51+
3952
0 commit comments