Skip to content

Feature documentation: add examples for gitlab #2915

@Danny-dK

Description

@Danny-dK

I had some trouble figuring out how to use this package with gitlab. Resources seem to be a bit low on how to do this (but I'm also very much a n00b, so could just be me).

Suggestion for minimal information to add to https://pkgdown.r-lib.org/articles/pkgdown.html:


If you are using GitLab, after running pkgdown::build_site(), create another file and call it .gitlab-ci.yml. Adjust the contents to include:

image: rocker/tidyverse

before_script:
  - apt-get update

create-pages: 
  script:
    - mkdir .public
    - cp -r docs/* .public
    - mv .public public
  pages: true  
  rules:
    - if: $CI_COMMIT_BRANCH == "main"

If you used an override so that pkgdown uses a different folder than docs (i.e. pkgdown::build_site(override = list(destination = "inst/site"))) then make sure to adjust the cp folder in the gitlab yaml file accordingly (cp -r inst/site/* .public). Push the docs folder or the chosen override folder and both yaml files to gitlab. Gitlab will recognize the yaml file and start a pipeline job. Once done, you have your page.

Naturally, you can also run the built_site() within gitlab by providing in the gitlab yaml what to do (hence no need to do it locally):

image: rocker/tidyverse

before_script:
  - apt-get update
  - R -e 'install.packages("devtools")'
  - R -e 'install.packages(c("knitr", "markdown", "rmarkdown", "pkgdown", "usethis"))'

create-pages: 
  script:
    - R -e 'usethis::use_pkgdown()'
    - R -e 'pkgdown::build_site()'
    - mkdir .public
    - cp -r docs/* .public
    - mv .public public
  pages: true  
  rules:
    - if: $CI_COMMIT_BRANCH == "main"

push the yaml file to gitlab and your good to go.

Of note is that the general image reference used in README.md (or anywhere else) seems to get overriden by pkgdown in GitLab (see https://stackoverflow.com/a/71205146). Instead of for example:

# dplyr <a href="https://dplyr.tidyverse.org"><img src="man/figures/logo.png" align="right" height="138" /></a>

use

# dplyr <a href="https://dplyr.tidyverse.org"><img src="man/figures/logo.png" align="right" height="138" style="float:right; height:138px;" /></a>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions