Skip to content

Commit a991d41

Browse files
Update renv workflow for branch and PR permissions
Signed-off-by: Diogo Ribeiro <[email protected]>
1 parent 5d280d1 commit a991d41

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

.github/workflows/renv-update.yml

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
1-
# .github/workflows/renv-bootstrap-or-restore.yml
21
name: Bootstrap or Restore renv
32

43
on:
54
workflow_dispatch:
65
schedule:
76
- cron: "0 6 * * 1" # Mondays 06:00 UTC
87

8+
# ✅ allow the workflow to push a branch and open a PR
9+
permissions:
10+
contents: write
11+
pull-requests: write
12+
913
jobs:
1014
renv:
1115
runs-on: ubuntu-latest
1216
steps:
13-
- uses: actions/checkout@v5
14-
with: { fetch-depth: 0 }
17+
- uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
# ✅ let create-pull-request manage its own credentials
21+
persist-credentials: false
1522

1623
- uses: r-lib/actions/setup-r@v2
1724
with:
@@ -22,14 +29,25 @@ jobs:
2229

2330
- name: Bootstrap or restore
2431
id: renv
32+
shell: bash
2533
run: |
2634
Rscript - <<'RSCRIPT'
2735
if (!file.exists("renv.lock")) {
2836
message("No renv.lock found — bootstrapping…")
2937
renv::init(bare = TRUE)
30-
# Optionally install dev deps here, e.g.:
38+
# Optionally install dev deps here:
3139
# renv::install(c("devtools","roxygen2","testthat"))
3240
renv::snapshot(prompt = FALSE)
41+
# keep renv out of package tarballs
42+
rb <- ".Rbuildignore"
43+
add_line <- function(pat) {
44+
if (!file.exists(rb) || !any(grepl(pat, readLines(rb), perl=TRUE))) {
45+
cat(pat, file = rb, sep = "\n", append = TRUE)
46+
}
47+
}
48+
add_line("^renv($|/)")
49+
add_line("^renv\\.lock$")
50+
add_line("^\\.Rprofile$")
3351
cat("BOOTSTRAPPED=1\n", file = Sys.getenv("GITHUB_OUTPUT"), append = TRUE)
3452
} else {
3553
message("renv.lock found — restoring…")
@@ -40,13 +58,14 @@ jobs:
4058
4159
- name: Create PR with initial lockfile
4260
if: steps.renv.outputs.BOOTSTRAPPED == '1'
43-
uses: peter-evans/create-pull-request@v7
61+
uses: peter-evans/create-pull-request@v6
4462
with:
4563
commit-message: "chore(renv): initialize renv and add lockfile"
4664
title: "chore(renv): bootstrap renv"
4765
body: "Initial `renv` setup: adds `.Rprofile`, `renv/activate.R`, and `renv.lock`."
4866
branch: "chore/renv-bootstrap"
4967
labels: dependencies,R
5068
reviewers: diogoribeiro7
51-
69+
signoff: false
70+
# uses the workflow GITHUB_TOKEN automatically; no PAT needed
5271

0 commit comments

Comments
 (0)