Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix dockerfiler deps #1072

Merged
merged 6 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 27 additions & 30 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,45 @@ on:
branches:
- main
- master
- dev

name: pkgdown

jobs:
pkgdown:
runs-on: macOS-latest
runs-on: ubuntu-latest
# Only restrict concurrency for non-PR jobs
concurrency:
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-r@v1
- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-pandoc@v1

- name: Query dependencies
run: |
install.packages('remotes')
remotes::install_github("ThinkR-open/thinkrtemplate")
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
shell: Rscript {0}
- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- name: Restore R package cache
uses: actions/cache@v2
- uses: r-lib/actions/setup-r-dependencies@v2
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-

- name: Install dependencies
run: |
remotes::install_deps(dependencies = TRUE)
install.packages("pkgdown", type = "binary")
extra-packages: any::pkgdown, local::.
needs: website

- name: Install thinkrtemplate
run: install.packages("remotes");remotes::install_github("ThinkR-open/thinkrtemplate")
shell: Rscript {0}

- name: Install package
run: R CMD INSTALL .
- name: Build site
run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
shell: Rscript {0}

- name: Deploy package
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Actions"
Rscript -e 'options(pkgdown.internet = FALSE);pkgdown::deploy_to_branch(new_process = FALSE)'
- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/[email protected]
with:
clean: false
branch: gh-pages
folder: docs
50 changes: 50 additions & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: test-coverage

jobs:
test-coverage:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr
needs: coverage

- name: Test coverage
run: |
covr::codecov(
quiet = FALSE,
clean = FALSE,
install_path = file.path(Sys.getenv("RUNNER_TEMP"), "package")
)
shell: Rscript {0}

- name: Show testthat output
if: always()
run: |
## --------------------------------------------------------------------
find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v3
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
64 changes: 32 additions & 32 deletions R/add_dockerfiles_renv.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@ add_dockerfile_with_renv_ <- function(
document = FALSE,
...
# build_golem_from_source = TRUE,
) {
) {
check_dockerfiler_installed()
if (is.null(lockfile)) {
rlang::check_installed(
c("renv", "attachment"),
reason = "to build a Dockerfile with automatic renv.lock creation. Use the `lockfile` parameter to pass your own `renv.lock` file."
)
}



# Small hack to prevent warning from rlang::lang() in tests
# This should be managed in {attempt} later on
x <- suppressWarnings({
rlang::lang(print)
})

dir.create(output_dir)

# add output_dir in Rbuildignore if the output is inside the golem
if (normalizePath(dirname(output_dir)) == normalizePath(source_folder)) {
usethis_use_build_ignore(output_dir)
}

if (is.null(lockfile)) {
if (isTRUE(document)) {
cli_cat_line("You set `document = TRUE` and you did not pass your own renv.lock file,")
Expand All @@ -46,18 +46,18 @@ add_dockerfile_with_renv_ <- function(
cli_cat_line("")
cli_cat_line("In any case be sure to have no Error or Warning at `devtools::check()`")
}




lockfile <- attachment_create_renv_for_prod(
path = source_folder,
check_if_suggests_is_installed = FALSE, document = document,
output = file.path(output_dir, "renv.lock.prod"),
...
)
}

# fs_file_copy(
# path = lockfile,
# new_path = output_dir,
Expand All @@ -74,16 +74,16 @@ add_dockerfile_with_renv_ <- function(
expand = expand,
extra_sysreqs = extra_sysreqs
)

socle$write(as = file.path(output_dir, "Dockerfile_base"))


my_dock <- dockerfiler_Dockerfile()$new(FROM = tolower(tolower(paste0(golem::get_golem_name(), "_base"))))

my_dock$COPY("renv.lock.prod", "renv.lock")

my_dock$RUN("R -e 'renv::restore()'")

if (update_tar_gz) {
old_version <- list.files(path = output_dir, pattern = paste0(golem::get_golem_name(), "_*.*.tar.gz"), full.names = TRUE)
# file.remove(old_version)
Expand All @@ -100,7 +100,7 @@ add_dockerfile_with_renv_ <- function(
)
)
}

if (
isTRUE(
requireNamespace(
Expand Down Expand Up @@ -128,7 +128,7 @@ add_dockerfile_with_renv_ <- function(
stop("please install {pkgbuild}")
}
}

# we use an already built tar.gz file
my_dock$COPY(
from =
Expand Down Expand Up @@ -202,7 +202,7 @@ add_dockerfile_with_renv <- function(
)
base_dock
base_dock$write(as = file.path(output_dir, "Dockerfile"))

out <- sprintf(
"docker build -f Dockerfile_base --progress=plain -t %s .
docker build -f Dockerfile --progress=plain -t %s .
Expand All @@ -215,9 +215,9 @@ docker run -p %s:%s %s
tolower(paste0(golem::get_golem_name(), ":latest")),
port
)

cat(out, file = file.path(output_dir, "README"))

open_or_go_to(
where = file.path(output_dir, "README"),
open_file = open
Expand Down Expand Up @@ -308,7 +308,7 @@ add_dockerfile_with_renv_heroku <- function(
),
...
)

apps_h <- gsub(
"\\.",
"-",
Expand All @@ -318,34 +318,34 @@ add_dockerfile_with_renv_heroku <- function(
golem::get_golem_version()
)
)

readme_output <- fs_path(
output_dir,
"README"
)

write_there <- function(...) {
write(..., file = readme_output, append = TRUE)
}

write_there("From your command line, run:\n")

write_there(
sprintf(
"docker build -f Dockerfile_base --progress=plain -t %s .",
paste0(golem::get_golem_name(), "_base")
)
)

write_there(
sprintf(
"docker build -f Dockerfile --progress=plain -t %s .\n",
paste0(golem::get_golem_name(), ":latest")
)
)

write_there("Then, to push on heroku:\n")

write_there("heroku container:login")
write_there(
sprintf("heroku create %s", apps_h)
Expand All @@ -360,11 +360,11 @@ add_dockerfile_with_renv_heroku <- function(
sprintf("heroku open --app %s\n", apps_h)
)
write_there("> Be sure to have the heroku CLI installed.")

write_there(
sprintf("> You can replace %s with another app name.", apps_h)
)

# The open is deported here just to be sure
# That we open the README once it has been populated
open_or_go_to(
Expand Down
2 changes: 2 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ coverage:
default:
target: auto
threshold: 1%
informational: true
patch:
default:
target: auto
threshold: 1%
informational: true