So I have a {targets} pipeline which runs on GitHub Actions. The required packages are recorded with {renv} and the whole thing runs in a docker container. Because I would prefer to have a long image build time and a short image run time, renv builds the library when the docker container is built so everything is available at runtime. The actual pipeline is not part of the image - it is checked out at runtime.
Here's the problem - if I run any R code in the GitHub workflow before using 'actions/checkout', renv works fine. But if I run anything after 'actions/checkout' renv can't find the library and instead needs to reinstall everything.
Dockerfile
FROM rocker/verse:4.3.0
ENV RENV_VERSION 0.17.3
RUN R -e "install.packages('remotes', repos = c(CRAN = 'https://cloud.r-project.org'))"
RUN R -e "remotes::install_github('rstudio/renv@${RENV_VERSION}')"
WORKDIR /project
COPY renv.lock renv.lock
ENV RENV_PATHS_LIBRARY renv/library
RUN R -e "renv::restore()"
GitHub Workflow
on:
push:
branches:
- main
- master
pull_request:
branches:
- main
- master
schedule:
- cron: '0 13 * * 0,2,4'
name: targets
jobs:
targets:
runs-on: ubuntu-latest
container:
image: (above image)
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
LANG: en_US.UTF-8
steps:
- name: Test if renv works
shell: Rscript {0}
run: renv::restore() # Works - up to date with lock file
- uses: actions/checkout@v3
- name: Test if renv works after checkout
shell: Rscript {0}
run: renv::restore() # Fails - reinstalls library from lockfile
My first thought was that the working directory was being changed, but that's not the case (and, in retrospect, shouldn't matter if the environment variable is set). My second thought was that by checking out the repo I am replacing the renv.lock file. But, these are the same and even if they were a little bit different it doesn't explain why it installs every package again. Totally at a loss for what is happening here.