Skip to content

Commit

Permalink
Use Quarto and Typst
Browse files Browse the repository at this point in the history
  • Loading branch information
walkowif committed May 13, 2024
1 parent de03d13 commit ccf9abd
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 258 deletions.
15 changes: 4 additions & 11 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
name: ${{ matrix.package.name }}
container:
image: rocker/verse:4.1.2
image: rocker/verse:4.4.0
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
strategy:
Expand All @@ -21,14 +21,10 @@ jobs:
package:
- name: aragog
report_pkg_dir: ./tests/packages/aragog
report_template_path: ./template.Rmd
report_rmarkdown_format: pdf_document
additional_tlmgr_packages: "courier ec fancyhdr"
report_template_path: ./template.qmd
- name: buckbeak
report_pkg_dir: ./tests/packages/buckbeak
report_template_path: ./tests/packages/buckbeak/validation-template.Rmd
report_rmarkdown_format: html_document
additional_tlmgr_packages: "courier ec"
report_template_path: ./tests/packages/buckbeak/validation-template.qmd

steps:
- name: Checkout ${{ matrix.package.name }}
Expand All @@ -40,14 +36,11 @@ jobs:
with:
report_pkg_dir: ${{ matrix.package.report_pkg_dir }}
report_template_path: ${{ matrix.package.report_template_path }}
report_output_prefix: validation_report
report_rmarkdown_format: ${{ matrix.package.report_rmarkdown_format }}
additional_tlmgr_packages: ${{ matrix.package.additional_tlmgr_packages }}

- name: Upload ${{ matrix.package.name }} validation report
uses: actions/upload-artifact@v4
if: success()
with:
name: ${{ matrix.package.name }} validation report
path: ${{ steps.validation.outputs.report_output_filename }}
path: validation_report.pdf
if-no-files-found: error
9 changes: 3 additions & 6 deletions .github/workflows/test_no_cache.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
name: ${{ matrix.package.name }}
container:
image: rocker/verse:4.1.2
image: rocker/verse:4.4.0
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
strategy:
Expand All @@ -21,8 +21,7 @@ jobs:
package:
- name: buckbeak
report_pkg_dir: ./tests/packages/buckbeak
report_template_path: ./tests/packages/buckbeak/validation-template.Rmd
report_rmarkdown_format: html_document
report_template_path: ./tests/packages/buckbeak/validation-template.qmd

steps:
- name: Checkout ${{ matrix.package.name }}
Expand All @@ -34,14 +33,12 @@ jobs:
with:
report_pkg_dir: ${{ matrix.package.report_pkg_dir }}
report_template_path: ${{ matrix.package.report_template_path }}
report_output_prefix: validation_report
report_rmarkdown_format: ${{ matrix.package.report_rmarkdown_format }}
no_cache: true

- name: Upload ${{ matrix.package.name }} validation report
uses: actions/upload-artifact@v4
if: success()
with:
name: ${{ matrix.package.name }} validation report
path: ${{ steps.validation.outputs.report_output_filename }}
path: validation_report.pdf
if-no-files-found: error
64 changes: 18 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[![SuperLinter](https://github.com/insightsengineering/thevalidatoR/actions/workflows/lint.yaml/badge.svg)](https://github.com/insightsengineering/thevalidatoR/actions/workflows/lint.yaml)
[![Test This Action](https://github.com/insightsengineering/thevalidatoR/actions/workflows/test.yaml/badge.svg)](https://github.com/insightsengineering/thevalidatoR/actions/workflows/test.yaml)

- [thevalidatoR](#thevalidator)
- [An R Package Validation Report](#an-r-package-validation-report)
- [Description](#description)
- [Action Type](#action-type)
Expand All @@ -19,99 +20,70 @@
- [admiral](#admiral)

<!-- BEGIN_ACTION_DOC -->
# An R Package Validation Report
# R Package Validation Report

### Description

A Github Action that generates a validation report for an R package. The four main steps are:

A Github Action that generates a validation report for an R package.
The four main steps are:
- Run `R CMD check` (check installation)
- Run `covr::package_coverage()` (check unit test coverage)
- Run `covtracer` (link documentation to unit tests)
- Place results into report
- _If valtools present - run valtools and also publish report?_ (to discuss)
- Attach report as object to release

### Action Type

Composite

### Author

Roche

### Inputs
* `report_pkg_dir`:

- `report_pkg_dir`:

_Description_: Path to package's root
_Description_: Path to package's root.

_Required_: `false`

_Default_: `.`

- `report_template_path`:

_Description_: File path of the R markdown template to use for the report. The default template is available [here.](./template.Rmd)
* `report_template_path`:

_Required_: `false`

_Default_: `template.Rmd`

- `report_rmarkdown_format`:
_Description_: File path of the R markdown template to use for the report.
The default template is available [here.](./template.qmd)

_Description_: The output format to use when rendering the report. Value is used by `rmarkdown::render`'s `output_format` parameter.

_Required_: `false`

_Default_: `pdf_document`
_Default_: `./template.qmd`

- `report_output_prefix`:
* `no_cache`:

_Description_: The output filename prefix for the validation report. If left blank, it defaults to the following convention: `<package name>-<package version>-validation-report`.

_Required_: `false`

_Default_: `""`

- `additional_tlmgr_packages`:

_Description_: Additional tex packages to install with tlmgr.

_Required_: `false`

_Default_: `courier ec`

- `no_cache`:

_Description_: Disable github action R dependency caching.
_Description_: Disable github action R dependency caching

_Required_: `false`

_Default_: `false`

- `cache_version`:
* `cache_version`:

_Description_: Version of the cache. To clean cache bump this version.

_Required_: `false`

_Default_: `v1`

- `disable_install_dev_deps`:
* `disable_install_dev_deps`:

_Description_: Disable installation of dev dependencies while
building the report.

_Description_: Disable installation of dev dependencies while building the report.

_Required_: `false`

_Default_: `false`

### Outputs

- `report_output_filename`:

_Description_: Filename of the generated report.

None
<!-- END_ACTION_DOC -->

## How to use
Expand Down
72 changes: 19 additions & 53 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: R Package Validation Report
author: Roche
description: A Github Action that generates a validation report for an R package.
description: |
A Github Action that generates a validation report for an R package.
inputs:
report_pkg_dir:
Expand All @@ -10,27 +11,9 @@ inputs:
report_template_path:
description: |
File path of the R markdown template to use for the report.
The default template is available [here.](./template.Rmd)
The default template is available [here.](./template.qmd)
required: false
default: "./template.Rmd"
report_rmarkdown_format:
description: |
The file format of the validation report. See `rmarkdown::render`'s
`output_format` parameter for accepted values.
required: false
default: "all"
report_output_prefix:
description: >
The output filename prefix for the validation report. If left blank,
it defaults to the following convention:
`<package name>-<package version>-validation-report`.
required: false
default: ""
additional_tlmgr_packages:
description: |
Additional tex packages to install with tlmgr.
required: false
default: "courier ec"
default: "./template.qmd"
no_cache:
description: "Disable github action R dependency caching"
required: false
Expand All @@ -45,10 +28,6 @@ inputs:
building the report.
required: false
default: "false"
outputs:
report_output_filename:
description: Filename of the generated report.
value: ${{ steps.report-generator.outputs.output-filename }}
branding: # https://feathericons.com/
icon: "award"
color: "blue"
Expand All @@ -68,13 +47,6 @@ runs:
cat ~/.Rprofile
shell: bash

- name: Set tlmgr cache folder
if: "contains(inputs.no_cache, 'false')"
id: texlive_version
run: |
echo "TEX_LIVE_VERSION=$(tlmgr --version |tail -1 |awk '{print $NF}')" >> $GITHUB_OUTPUT
shell: bash

- name: Cache R packages
if: "contains(inputs.no_cache, 'false')"
uses: actions/cache@v4
Expand All @@ -83,40 +55,34 @@ runs:
key: ${{ inputs.cache_version }}-${{ runner.os }}-${{ steps.r_version.outputs.R_VERSION }}-${{ hashFiles('DESCRIPTION') }}
restore-keys: ${{ inputs.cache_version }}-${{ runner.os }}-${{ steps.r_version.outputs.R_VERSION }}

- name: Cache Tex packages
if: "contains(inputs.no_cache, 'false')"
uses: actions/cache@v4
with:
path: /home/runner/work/_temp/TinyTeX
key: ${{ inputs.cache_version }}-${{ runner.os }}-${{ steps.texlive_version.outputs.TEX_LIVE_VERSION }}-${{ hashFiles(inputs.report_template_path) }}
restore-keys: ${{ inputs.cache_version }}-${{ runner.os }}-${{ steps.texlive_version.outputs.TEX_LIVE_VERSION }}

- name: Install dependencies
run: |
${GITHUB_ACTION_PATH}/dependencies.R
export PATH=${RUNNER_TEMP}/TinyTeX/bin/x86_64-linux:${PATH}
echo "PATH=${PATH}" >> $GITHUB_ENV
tlmgr path add
tlmgr update --self
[ ! -f "./template.Rmd" ] && cp ${GITHUB_ACTION_PATH}/template.Rmd . || echo "./template.Rmd Already exists"
shell: bash

- name: Install additional tex packages
run: tlmgr install ${{ inputs.additional_tlmgr_packages }}
[ ! -f "./template.qmd" ] && cp ${GITHUB_ACTION_PATH}/template.qmd . || echo "./template.qmd already exists"
if [[ "$(echo -e "$(quarto --version)\n1.4.0" | sort -V | head -1)" == "1.4.0" ]]; then
echo "✅ Quarto CLI version sufficient (>= 1.4.0)"
echo "Quarto CLI version: $(quarto --version)"
else
echo "❌ Quarto CLI version insufficient (< 1.4.0)"
echo "Downloading Quarto CLI..."
# Install newer version of Quarto CLI.
export QUARTO_VERSION="1.4.554"
apt-get update
apt-get install -qy wget
wget https://github.com/quarto-dev/quarto-cli/releases/download/v${QUARTO_VERSION}/quarto-${QUARTO_VERSION}-linux-amd64.deb
dpkg -i quarto-${QUARTO_VERSION}-linux-amd64.deb
echo "New Quarto CLI version: $(quarto --version)"
fi
shell: bash

- name: Run report generator
id: report-generator
run: |
${GITHUB_ACTION_PATH}/report-generator.R
filename=$(basename $(cat /tmp/report_file_path.txt))
echo "output-filename=${filename}" >> $GITHUB_OUTPUT
shell: bash
env:
# Composite action doesn't set inputs as env vars.
# We need to do this manually...
INPUT_REPORT_PKG_DIR: ${{ inputs.report_pkg_dir }}
INPUT_REPORT_TEMPLATE_PATH: ${{ inputs.report_template_path }}
INPUT_REPORT_RMARKDOWN_FORMAT: ${{ inputs.report_rmarkdown_format }}
INPUT_REPORT_OUTPUT_PREFIX: ${{ inputs.report_output_prefix }}
DISABLE_INSTALL_DEV_DEPS: ${{ inputs.disable_install_dev_deps }}
28 changes: 2 additions & 26 deletions dependencies.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,5 @@ lapply(github_packages, remotes::install_github)
options(repos = c("https://cloud.r-project.org/"))
ncores <- parallel::detectCores(all.tests = FALSE, logical = TRUE)
if (!require("git2r")) install.packages("git2r", upgrade = "never", Ncpus = ncores)
if (!require("kableExtra")) install.packages("kableExtra", upgrade = "never", Ncpus = ncores)
if (!require("tinytex")) install.packages("tinytex", upgrade = "never", Ncpus = ncores)

# Conditionally install TinyTex
if(!dir.exists(paste(Sys.getenv("RUNNER_TEMP"), "TinyTeX", sep="/"))) {
# nolint start
tinytex_installer <- '
export TINYTEX_DIR=${RUNNER_TEMP}/TinyTeX
wget -qO- "https://raw.githubusercontent.com/yihui/tinytex/master/tools/install-unx.sh" | sh -s - --admin --no-path
mkdir -p ${RUNNER_TEMP}/TinyTeX
cp -r ~/.TinyTeX/. ${RUNNER_TEMP}/TinyTeX
rm -rf ~/.TinyTeX
${RUNNER_TEMP}/TinyTeX/bin/*/tlmgr path add
tlmgr update --self
tlmgr install latex-bin luatex xetex ae bibtex context inconsolata listings makeindex metafont mfware parskip pdfcrop tex tools url xkeyval
'
# nolint end
system(tinytex_installer)
tinytex::r_texmf()
permission_update <- '
chown -R root:staff ${RUNNER_TEMP}/TinyTeX
chmod -R g+w ${RUNNER_TEMP}/TinyTeX
chmod -R g+wx ${RUNNER_TEMP}/TinyTeX/bin
'
system(permission_update)
}
if (!require("quarto")) install.packages("quarto", upgrade = "never", Ncpus = ncores)
if (!require("tinytable")) install.packages("tinytable", upgrade = "never", Ncpus = ncores)
32 changes: 6 additions & 26 deletions report-generator.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ git_safe_dir <- system(
sprintf("git config --global --add safe.directory '%s'", getwd())
)

cat(paste0("INPUT_REPORT_PKG_DIR = ", Sys.getenv("INPUT_REPORT_PKG_DIR", ".")))

# Get the action inputs from preset env vars
pkg_dir <- normalizePath(Sys.getenv("INPUT_REPORT_PKG_DIR", "."))
template_path <- Sys.getenv("INPUT_REPORT_TEMPLATE_PATH", "/template.Rmd")
report_format <- Sys.getenv("INPUT_REPORT_RMARKDOWN_FORMAT", "all")
report_output_prefix <- Sys.getenv("INPUT_REPORT_OUTPUT_PREFIX", "")
template_path <- Sys.getenv("INPUT_REPORT_TEMPLATE_PATH", "./template.qmd")
disable_install_dev_deps <- tolower(
Sys.getenv("DISABLE_INSTALL_DEV_DEPS")
) %in% c("yes", "y", "t", "true")
Expand Down Expand Up @@ -41,26 +41,6 @@ if (!disable_install_dev_deps) {
devtools::install_dev_deps(pkg_dir, upgrade = "never")
}

# Set the output file name
if (report_output_prefix == "") {
desc <- read.dcf(desc_file)
pkg_name <- toString(desc[, "Package"])
pkg_version <- toString(desc[, "Version"])
report_output_prefix <- paste0(
pkg_name, "-", pkg_version, "-validation-report"
)
}

# allow rmarkdown to choose appropriate file extension for output format
report_file_path <- rmarkdown::render(
template_path,
output_dir = getwd(), # create report wherever R script was called
output_file = report_output_prefix,
output_format = report_format,
params = list(pkg_dir = pkg_dir)
)

# Create a tmp file which contains the final report filename
writeLines(report_file_path, "/tmp/report_file_path.txt")

cat(sprintf("Created report at: '%s'\n\n", report_file_path))
library(quarto)
cat(paste0("Running Quarto render for template: ", template_path))
quarto_render(template_path, output_file = "validation_report.pdf")
Loading

0 comments on commit ccf9abd

Please sign in to comment.