diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..9cd7a9ca --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +.git +.Rproj.user +publish +src +renv/library diff --git a/.github/workflows/test_refs_PR.yml b/.github/workflows/test_refs_PR.yml new file mode 100644 index 00000000..7444555c --- /dev/null +++ b/.github/workflows/test_refs_PR.yml @@ -0,0 +1,25 @@ +name: Env var on PR + +on: + pull_request: + branches: + - main + +jobs: + build-website: + runs-on: ubuntu-latest + name: "test env var in PR" + env: + GITHUB_PAT: ${{ secrets.GITHUB_PAT }} + steps: + - name: Checkout repo + uses: actions/checkout@v2 + - name: test + run: | + echo 'GitHub actions:' $GITHUB_ACTIONS + echo 'Event name:' $GITHUB_EVENT_NAME + echo 'ref:' $GITHUB_REF + echo 'ref name:' $GITHUB_REF_NAME + echo 'base ref:' $GITHUB_BASE_REF + echo 'head ref:' $GITHUB_HEAD_REF + echo 'repo:' $GITHUB_REPOSITORY diff --git a/.github/workflows/update-website-test.yml b/.github/workflows/update-website-test.yml new file mode 100644 index 00000000..c7ac762f --- /dev/null +++ b/.github/workflows/update-website-test.yml @@ -0,0 +1,23 @@ +name: On merge to main, build the protocol and add it to the website "Log RECENT_MERGED_BRANCH_NAME" + +on: + push: + branches: + - main + +jobs: + build-website: + runs-on: ubuntu-latest + name: "add protocol to website" + env: + GITHUB_PAT: ${{ secrets.GITHUB_PAT }} + steps: + - name: Checkout repo + uses: actions/checkout@v2 + - uses: tonynguyenit18/github-action-custom-vars@v1 + - name: test + run: | + echo 'GitHub actions:' $GITHUB_ACTIONS + echo 'Event name:' $GITHUB_EVENT_NAME + echo 'ref:' $GITHUB_REF + echo 'recent merged branch:' $RECENT_MERGED_BRANCH_NAME diff --git a/.zenodo.json b/.zenodo.json index fe70320d..2e3d4299 100644 --- a/.zenodo.json +++ b/.zenodo.json @@ -1,40 +1,40 @@ { - "title": "Source code of protocols of the Research Institute for Nature and Forest (INBO)", - "description": "This archive provides the source code of protocols used at the Research Institute for Nature and Forest (INBO), Brussels, Belgium (www.inbo.be). The protocols are written in R markdown and are compiled as html using the bookdown package. The website with the compiled protocols (including older versions) is at https://protocols.inbo.be.", - "license": "cc-by", - "upload_type": "other", - "access_right": "open", - "creators": [ - { - "name": "Van Calster, Hans", - "affiliation": "Research Institute for Nature and Forest", - "orcid": "0000-0001-8595-8426" - }, - { - "name": "De Bie, Els", - "affiliation": "Research Institute for Nature and Forest", - "orcid": "0000-0001-7679-743X" - }, - { - "name": "Onkelinx, Thierry", - "affiliation": "Research Institute for Nature and Forest", - "orcid": "0000-0001-8804-4216" - }, - { - "name": "Vanderhaeghe, Floris", - "affiliation": "Research Institute for Nature and Forest", - "orcid": "0000-0002-6378-6229" - } - ], - "keywords": [ - "open protocol", - "open science", - "research institute", - "nature", - "forest", - "environment", - "markdown", - "Flanders", - "Belgium" - ] + "title": "Source code of protocols of the Research Institute for Nature and Forest (INBO)", + "description": "This archive provides the source code of protocols used at the Research Institute for Nature and Forest (INBO), Brussels, Belgium (www.inbo.be<\/a>). The protocols are written in R markdown and are compiled as html using the bookdown package. The website with the compiled protocols (including older versions) is at https://protocols.inbo.be<\/a>.", + "license": "cc-by", + "upload_type": "other", + "access_right": "open", + "creators": [ + { + "name": "Van Calster, Hans", + "affiliation": "Research Institute for Nature and Forest", + "orcid": "0000-0001-8595-8426" + }, + { + "name": "De Bie, Els", + "affiliation": "Research Institute for Nature and Forest", + "orcid": "0000-0001-7679-743X" + }, + { + "name": "Onkelinx, Thierry", + "affiliation": "Research Institute for Nature and Forest", + "orcid": "0000-0001-8804-4216" + }, + { + "name": "Vanderhaeghe, Floris", + "affiliation": "Research Institute for Nature and Forest", + "orcid": "0000-0002-6378-6229" + } + ], + "keywords": [ + "open protocol", + "open science", + "research institute", + "nature", + "forest", + "environment", + "markdown", + "Flanders", + "Belgium" + ] } diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..347286c7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,97 @@ +FROM rocker/verse + +ARG BUILD_DATE +ARG VCS_REF +LABEL org.label-schema.build-date=$BUILD_DATE \ +org.label-schema.name="RStable" \ +org.label-schema.description="A docker image with stable versions of R and a bunch of packages used to check and publish protocols." \ +org.label-schema.license="MIT" \ +org.label-schema.url="e.g. https://www.inbo.be/" \ +org.label-schema.vcs-ref=$VCS_REF \ +org.label-schema.vcs-url="https://github.com/inbo/protocolsource" \ +org.label-schema.vendor="Research Institute for Nature and Forest" \ +maintainer="Hans Van Calster " + +## for apt to be noninteractive +ENV DEBIAN_FRONTEND noninteractive +ENV DEBCONF_NONINTERACTIVE_SEEN true + +## Install nano +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + nano + +COPY docker/Rprofile.site $R_HOME/etc/Rprofile.site + +## Install wget +#RUN apt-get update \ +# && apt-get install -y --no-install-recommends \ +# wget + +## Install pandoc +RUN wget https://github.com/jgm/pandoc/releases/download/2.7.3/pandoc-2.7.3-1-amd64.deb \ + && dpkg -i pandoc-2.7.3-1-amd64.deb \ + && rm pandoc-2.7.3-1-amd64.deb + +## Install git depencencies +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ +# git \ + openssh-client + +## Install curl dependencies +#RUN apt-get update \ +# && apt-get install -y --no-install-recommends \ +# libcurl4-openssl-dev + +## Install ggplot2 dependencies +#RUN apt-get update \ +# && apt-get install -y --no-install-recommends \ +# libfreetype6-dev + +## Install rgdal dependencies +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + gdal-bin \ + libgdal-dev \ + libproj-dev \ + proj-bin + +## Install openssl dependencies +#RUN apt-get update \ +# && apt-get install -y --no-install-recommends \ +# libssl-dev + +## Install systemfonts dependencies +#RUN apt-get update \ +# && apt-get install -y --no-install-recommends \ +# libfontconfig1-dev + +## Install textshaping dependencies +#RUN apt-get update \ +# && apt-get install -y --no-install-recommends \ +# libharfbuzz-dev libfribidi-dev + +## Install V8 dependencies +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + libv8-dev + +## Install xml2 dependencies +#RUN apt-get update \ +# && apt-get install -y --no-install-recommends \ +# libxml2-dev + +WORKDIR /github/workspace + +RUN R -e "install.packages('renv', repos = c(CRAN = 'https://cloud.r-project.org'))" +RUN R -e "renv::consent(provided = TRUE)" +COPY renv.lock renv.lock +RUN R -e "renv::restore()" +RUN R -e "renv::isolate()" + +COPY docker/entrypoint_website.sh /entrypoint_website.sh +COPY docker/entrypoint_update.sh /entrypoint_update.sh +COPY docker/entrypoint_check.sh /entrypoint_check.sh + +ENTRYPOINT ["/entrypoint_check.sh"] diff --git a/NEWS.md b/NEWS.md index 39b76bfb..db99893a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +## Version 2022.01 + +- Protocol code: sfp-401-nl +- Title: Klassieke vegetatieopname in een proefvlak aan de hand van visuele inschattingen van bedekking van soorten in (semi-)terrestrische vegetatie + \ No newline at end of file +--> diff --git a/build_push.sh b/build_push.sh new file mode 100644 index 00000000..1e639415 --- /dev/null +++ b/build_push.sh @@ -0,0 +1,47 @@ +#to be used on protocolsource (change entrypoint below in Dockerfile to run other parts) + +docker build --tag=inbo/protocols . + +#entrypoint_check +docker run --rm --env GITHUB_REPOSITORY="ElsLommelen/protocolsource" --env BRANCH_SOURCE="dockertests" --env PROTOCOL_CODE="sfp-401-nl" --env INPUT_TOKEN inbo/protocols +#INPUT_TOKEN is als omgevingsvariabele toegevoegd op laptop + +#entrypoint_update +docker run --rm --env GITHUB_REPOSITORY="ElsLommelen/protocolsource" --env BRANCH_SOURCE="dockertests" --env PROTOCOL_CODE="sfp-401-nl" --env INPUT_TOKEN inbo/protocols + +#entrypoint_website +docker run --rm --env GITHUB_REPOSITORY_SOURCE="ElsLommelen/protocolsource" --env BRANCH_SOURCE="dockertests" --env GITHUB_REPOSITORY_DEST="ElsLommelen/protocols" --env INPUT_TOKEN --env GITHUB_ACTIONS=true --env GITHUB_EVENT_NAME=push --env GITHUB_REF=refs/heads/main --env PROTOCOL_CODE="sfp-401-nl" inbo/protocols + + + +#examples +docker build --no-cache --tag=inbobmk/checklist . + +docker build --tag=inbobmk/checklist . + +docker push inbobmk/checklist + +# run on branch +docker run --rm --env GITHUB_REPOSITORY="inbo/checklist" --env GITHUB_SHA=$(git rev-parse HEAD) --env INPUT_TOKEN=$GITHUB_PAT --env INPUT_PATH="." --env ORCID_TOKEN=$ORCID_TOKEN --env CODECOV_TOKEN=$CODECOV_TOKEN inbobmk/checklist +docker run --rm -it --entrypoint=/bin/bash --env GITHUB_REPOSITORY="inbo/checklist" --env GITHUB_SHA=$(git rev-parse HEAD) --env INPUT_TOKEN=$GITHUB_PAT --env INPUT_PATH="." --env ORCID_TOKEN=$ORCID_TOKEN --env CODECOV_TOKEN=$CODECOV_TOKEN inbobmk/checklist + +# run on main +docker run --rm --env GITHUB_REPOSITORY="inbo/checklist" --env GITHUB_SHA=$(git rev-parse HEAD) --env GITHUB_PAT=$GITHUB_PAT --env INPUT_PATH="." --env ORCID_TOKEN=$ORCID_TOKEN --env CODECOV_TOKEN=$CODECOV_TOKEN --env GITHUB_ACTIONS=true --env GITHUB_EVENT_NAME=push --env GITHUB_REF=refs/heads/main inbobmk/checklist + + + +#zinvolle env uit github +GITHUB_BASE_REF: name of target branch of the PR +GITHUB_EVENT_NAME: name of the event that triggered the workflow run +GITHUB_HEAD_REF: source branch of the PR +GITHUB_REF: full ref of branch or tag that triggered the workflow run (best niet gebruiken bij PR) +GITHUB_REF_NAME: short ref name of branch or tag that triggered the workflow run +GITHUB_REPOSITORY: owner and repository name, bv. inbo/protocolsource + +#aan te passen env +BRANCH_SOURCE (on PR) -> GITHUB_HEAD_REF +BRANCH_SOURCE (on push) -> GITHUB_REF_NAME +PROTOCOL_CODE -> BRANCH_SOURCE (zie hierboven) +INPUT_TOKEN??? +GITHUB_REPOSITORY_SOURCE -> GITHUB_REPOSITORY +GITHUB_REPOSITORY_DEST: meegeven als env! diff --git a/docker/Rprofile.site b/docker/Rprofile.site new file mode 100644 index 00000000..69f17930 --- /dev/null +++ b/docker/Rprofile.site @@ -0,0 +1,48 @@ +options( + papersize = "a4", + tab.width = 2, + width = 80, + help_type = "html", + keep.source.pkgs = TRUE, + xpinch = 300, + ypinch = 300, + yaml.eval.expr = TRUE, + repos = c( + CRAN = "https://cloud.r-project.org/", + INLA = "https://inla.r-inla-download.org/R/stable", + inbo = "https://inbo.r-universe.dev" + ), + install.packages.check.source = "yes", + install.packages.compile.from.source = "always", + inbo_required = c("checklist", "fortunes", "remotes", "INBOmd", "INBOtheme") +) + +if ("checklist" %in% rownames(utils::installed.packages())) { + options( + lintr.linter_file = system.file("lintr", package = "checklist") + ) +} + +if ( + interactive() && + !all(getOption("inbo_required") %in% rownames(utils::installed.packages())) +) { + warning( + c( + "\n", + rep("^", getOption("width")), + "\nThis R installation lacks some required INBO packages.", + "\nPlease install them using the code below:\n", + "\ninstall.packages(c(", + paste0( + "\"", + getOption("inbo_required")[ + !getOption("inbo_required") %in% rownames(utils::installed.packages()) + ], + "\"", collapse = ", " + ), + "))\n\n", + rep("^", getOption("width")) + ) + ) +} diff --git a/docker/check_all.R b/docker/check_all.R new file mode 100644 index 00000000..49861050 --- /dev/null +++ b/docker/check_all.R @@ -0,0 +1,20 @@ +# bundled checks for protocols +library(protocolhelper) +check_all <- function(protocol_code) { + #protocol_code <- Sys.getenv("PROTOCOL_CODE") + fail <- FALSE + tryCatch( + protocolhelper::check_frontmatter(protocol_code), + error = function(e) e, + finally = fail <- TRUE + ) + tryCatch( + protocolhelper::check_structure(protocol_code), + error = function(e) e, + finally = fail <- TRUE + ) + if (fail) { + stop("\nThe source code failed some checks. Please check the error message above.\n") + } +} +check_all(Sys.getenv("PROTOCOL_CODE")) diff --git a/docker/entrypoint_check.sh b/docker/entrypoint_check.sh new file mode 100755 index 00000000..7d4bf2a4 --- /dev/null +++ b/docker/entrypoint_check.sh @@ -0,0 +1,62 @@ +#!/bin/sh -l + +echo '\nGetting the code...\n' +git clone --quiet https://$INPUT_TOKEN@github.com/$GITHUB_REPOSITORY check +cd check +git checkout $BRANCH_SOURCE +#ls -a +rm .Rprofile + +echo '\nSession info\n' +Rscript -e 'sessioninfo::session_info()' + +#echo '\nChecking if branch is up to date with main...\n' +#main_in_branch=$(git merge-base $BRANCH_SOURCE main) +#echo $main_in_branch +#git checkout main +#git pull +#head_main=$(git rev-parse HEAD) +#echo $head_main +#if [ $main_in_branch != $head_main ]; then +# echo '\nThis branch does not contain the latest version of the main branch. Please merge the main branch into this branch first\n'; +# exit 1 +#fi + +echo '\nUpdate version number...\n' +git config --global user.email "info@inbo.be" +git config --global user.name "INBO" +UPDATED=$(Rscript -e 'protocolhelper::update_version_number("'$PROTOCOL_CODE'")') +echo 'output updated:' $UPDATED +if [ "$UPDATED" = "[1] TRUE" ]; then + # remake the last commit without deletion of .Rprofile +# MESSAGE=$(git log -1 --pretty=%B) +# git reset --soft HEAD^ +# git reset HEAD .Rprofile +# git commit --message="$MESSAGE" + + git push -f + echo '\ncommit with new version pushed\n' +fi + +echo '\nChecking protocols specific tests...\n' +#git checkout $BRANCH_SOURCE +#rm .Rprofile +ls -a + +Rscript "docker/check_all.R" +#Rscript --no-save --no-restore -e 'check_all("'$PROTOCOL_CODE'")' +if [ $? -ne 0 ]; then + echo '\nThe source code failed some checks. Please check the error message above.\n'; + exit 1 +fi + +# Rscript 'protocolhelper::check_frontmatter("'$PROTOCOL_CODE'")' +# test1=$? +# Rscript -e 'protocolhelper::check_structure("'$PROTOCOL_CODE'")' +# test2=$? +# +# if [ $test1 -ne 0 ] || [ $test2 -ne 0 ]; then +# #echo $error1 +# echo '\nThe source code failed some checks. Please check the error message above.\n'; +# exit 1 +# fi diff --git a/docker/entrypoint_update.sh b/docker/entrypoint_update.sh new file mode 100644 index 00000000..229cebbd --- /dev/null +++ b/docker/entrypoint_update.sh @@ -0,0 +1,25 @@ +#!/bin/sh -l + +echo '\nGetting the code...\n' +git clone --branch=$BRANCH_SOURCE https://$INPUT_TOKEN@github.com/$GITHUB_REPOSITORY /update +git config --global user.email "info@inbo.be" +git config --global user.name "INBO" +cd /update + +rm .Rprofile + +echo '\nSession info\n' +Rscript -e 'sessioninfo::session_info()' + +echo '\nUpdating zenodo...\n' +Rscript --no-save --no-restore -e 'protocolhelper:::update_zenodo()' +git add .zenodo.json +git commit --message="update .zenodo.json" + +echo '\nUpdating general NEWS.md...\n' +Rscript --no-save --no-restore -e 'protocolhelper:::update_news_release("'$PROTOCOL_CODE'")' +git add NEWS.md +git commit --message="update general NEWS.md" + +echo 'git push' +git push -f diff --git a/docker/entrypoint_website.sh b/docker/entrypoint_website.sh new file mode 100755 index 00000000..3acbf70b --- /dev/null +++ b/docker/entrypoint_website.sh @@ -0,0 +1,66 @@ +#!/bin/sh -l + +echo '\nGetting the code...\n' +git clone --quiet https://$INPUT_TOKEN@github.com/$GITHUB_REPOSITORY_SOURCE /render +cd /render +git checkout $BRANCH_SOURCE +git config --global user.email "info@inbo.be" +git config --global user.name "INBO" + +rm .Rprofile + +echo '\nSession info\n' +#Rscript -e "renv::restore()" +Rscript -e 'sessioninfo::session_info()' + +echo '\nAdd tag to merge commit protocolsource...\n' +echo 'GitHub actions:' $GITHUB_ACTIONS +echo 'Event name:' $GITHUB_EVENT_NAME +echo 'ref:' $GITHUB_REF +git rev-parse --abbrev-ref origin/HEAD | sed 's/origin\///' | xargs git checkout +Rscript --no-save --no-restore -e 'protocolhelper:::set_tags("'$PROTOCOL_CODE'")' +git push --follow-tags + +# look up tag names and tag messages to push to repo protocols later +# (not possible to run set_tags() when not in protocolsource anymore) +TAGNAME_GENERAL=$(git tag -l protocols-* --points-at) +TAGNAME_SPECIFIC=$(git tag -l s*p* --points-at) +TAGMESSAGE_GENERAL=$(git for-each-ref refs/tags/$TAGNAME_GENERAL --format='%(contents)') +TAGMESSAGE_SPECIFIC=$(git for-each-ref refs/tags/$TAGNAME_SPECIFIC --format='%(contents)') + +echo 'tagname general:' $TAGNAME_GENERAL +echo 'tag message general:' $TAGMESSAGE_GENERAL +echo 'tagname specific:' $TAGNAME_SPECIFIC +echo 'tag message specific:' $TAGMESSAGE_SPECIFIC + +echo 'Rendering the Rmarkdown files...\n' +#rm .Rprofile +Rscript -e "protocolhelper:::render_release()" +if [ $? -ne 0 ]; then + echo '\nRendering failed. Please check the error message above.\n'; + exit 1 +else + echo '\nAll Rmarkdown files rendered successfully\n' +fi + +echo 'Publishing the rendered files...\n' +git clone --quiet --depth=1 --single-branch --branch=main https://$INPUT_TOKEN@github.com/$GITHUB_REPOSITORY_DEST /destiny +#git config --global user.email "info@inbo.be" +#git config --global user.name "INBO" + +cp -R /render/publish/. /destiny/. +cd /destiny +ls -a + +git config user.name +git config user.email +git add --all +git commit --message="Add new protocol" +git push -f https://$INPUT_TOKEN@github.com/$GITHUB_REPOSITORY_DEST + +git rev-parse --abbrev-ref origin/HEAD | sed 's/origin\///' | xargs git checkout +git tag -a $TAGNAME_GENERAL -m "$TAGMESSAGE_GENERAL" +git tag -a $TAGNAME_SPECIFIC -m "$TAGMESSAGE_SPECIFIC" +git push --follow-tags + +echo '\nNew version published...' diff --git a/docker/render.R b/docker/render.R new file mode 100755 index 00000000..7577d710 --- /dev/null +++ b/docker/render.R @@ -0,0 +1 @@ +protocolhelper:::render_release() diff --git a/src/thematic/4_vegetation/sfp-401-nl_vegopname-terrest/index.Rmd b/src/thematic/4_vegetation/sfp-401-nl_vegopname-terrest/index.Rmd index 716649a5..56182068 100644 --- a/src/thematic/4_vegetation/sfp-401-nl_vegopname-terrest/index.Rmd +++ b/src/thematic/4_vegetation/sfp-401-nl_vegopname-terrest/index.Rmd @@ -1,14 +1,20 @@ --- -title: Klassieke vegetatieopname in een proefvlak aan de hand van visuele inschattingen van bedekking van soorten in (semi-)terrestrische vegetatie -subtitle: +title: Klassieke vegetatieopname in een proefvlak aan de hand van visuele inschattingen + van bedekking van soorten in (semi-)terrestrische vegetatie +subtitle: null author: - - name: Els De Bie - orcid: 0000-0001-7679-743X -date: "`r Sys.Date()`" -reviewers: [Hans Van Calster,Lieve Vriens,Jan Wouters,Wouter Van Gompel,Els Lommelen] +- name: Els De Bie + orcid: 0000-0001-7679-743X +date: '2022-07-18' +reviewers: +- Hans Van Calster +- Lieve Vriens +- Jan Wouters +- Wouter Van Gompel +- Els Lommelen file_manager: Hans Van Calster protocol_code: sfp-401-nl -version_number: "2021.01" +version_number: '2021.01' language: nl theme: vegetation params: @@ -16,28 +22,31 @@ params: plot_length_openveg_m: 3 plot_width_forest_m: 16 plot_length_forest_m: 16 - plot_shape: "vierkant" + plot_shape: vierkant height_herbshrublayer_openveg_m: 0.8 height_herbshrublayer_forest_m: 2 height_shrubtreelayer_openveg_m: 6 height_shrubtreelayer_forest_m: 8 - species_list: ["vaatplanten", "mossen", "lichenen"] - phenology_values: "standaard inbo-fenologiecodes" - coverscale_species: "Londo origineel" - coverscale_structure: "inbo-structuur-schaal" + species_list: + - vaatplanten + - mossen + - lichenen + phenology_values: standaard inbo-fenologiecodes + coverscale_species: Londo origineel + coverscale_structure: inbo-structuur-schaal site: bookdown::bookdown_site -output: +output: bookdown::gitbook: split_by: none - split_bib: FALSE - template: !expr protocolhelper::protocol_css() + split_bib: false + template: css/gitbook.html css: css/inbo_rapport.css config: - toc: - before: | - - after: | -
  • + toc: + before: | + + after:
  • --- ```{=html}