Skip to content

Commit

Permalink
Feature: Select a prefix for the validation report (#55)
Browse files Browse the repository at this point in the history
* tlmgr fails if it is not updated on runtime

* Some more enhancements

* Couple 'o bugfixes

* Composite actions are silly

* Remove docker references

* Get basename of output file
  • Loading branch information
cicdguy authored Mar 3, 2022
1 parent 307945b commit 824c7d8
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 40 deletions.
6 changes: 4 additions & 2 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.1
image: rocker/verse:4.1.2
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
strategy:
Expand All @@ -35,10 +35,12 @@ jobs:
uses: actions/checkout@v2

- name: Generate validation report for ${{ matrix.package.name }}
id: validation
uses: ./
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 }}

Expand All @@ -47,5 +49,5 @@ jobs:
if: success()
with:
name: ${{ matrix.package.name }} validation report
path: validation_report.*
path: ${{ steps.validation.outputs.report_output_filename }}
if-no-files-found: error
6 changes: 4 additions & 2 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.1
image: rocker/verse:4.1.2
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
strategy:
Expand All @@ -30,9 +30,11 @@ jobs:

- name: Generate validation report for ${{ matrix.package.name }}
uses: ./
id: validation
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

Expand All @@ -41,5 +43,5 @@ jobs:
if: success()
with:
name: ${{ matrix.package.name }} validation report
path: validation_report.*
path: ${{ steps.validation.outputs.report_output_filename }}
if-no-files-found: error
15 changes: 0 additions & 15 deletions Dockerfile

This file was deleted.

42 changes: 28 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# thevalidatoR
<img src='https://raw.githubusercontent.com/insightsengineering/hex-stickers/main/PNG/thevalidatoR.png' align="right" height="131.5" />

<img src='https://raw.githubusercontent.com/insightsengineering/hex-stickers/main/PNG/thevalidatoR.png' align="right" height="131.5" />

[<img src="http://pharmaverse.org/shields/thevalidatoR.png">](https://pharmaverse.org)
[![SuperLinter](https://github.com/insightsengineering/thevalidatoR/actions/workflows/lint.yaml/badge.svg)](https://github.com/insightsengineering/thevalidatoR/actions/workflows/lint.yaml)
Expand Down Expand Up @@ -33,62 +33,72 @@ A Github Action that generates a validation report for an R package. The four ma
- Attach report as object to release

### Action Type

Composite

### Author

Roche

### Inputs

* `report_pkg_dir`:
- `report_pkg_dir`:

_Description_: Path to package's root

_Required_: `false`

_Default_: `.`

* `report_template_path`:
- `report_template_path`:

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

_Required_: `false`

_Default_: `template.Rmd`

* `report_rmarkdown_format`:
- `report_rmarkdown_format`:

_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`

* `additional_tlmgr_packages`:
- `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`

* `no_cache`:
- `no_cache`:

_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.

Expand All @@ -97,16 +107,19 @@ Roche
_Default_: `false`

### Outputs
None

- `report_output_filename`:

_Description_: Filename of the generated report.

<!-- END_ACTION_DOC -->

## How to use

To use this GitHub Action you will need to complete the following:

* Create a new file in your repository called `.github/workflows/r-pkg-validation.yml`
* Copy the template over (and edit if you wish to modify it)
- Create a new file in your repository called `.github/workflows/r-pkg-validation.yml`
- Copy the template over (and edit if you wish to modify it)

### Quickstart

Expand Down Expand Up @@ -138,6 +151,7 @@ jobs:
uses: actions/checkout@v2

- name: Build report 🏗
id: validation
uses: insightsengineering/thevalidatoR@main
# see parameters above for custom templates and other formats

Expand All @@ -146,14 +160,14 @@ jobs:
if: success()
uses: svenstaro/upload-release-action@v2
with:
file: ./validation_report.pdf
asset_name: validation-report.pdf
file: ${{ steps.validation.outputs.report_output_filename }}
asset_name: ${{ steps.validation.outputs.report_output_filename }}
repo_token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.ref }}
overwrite: false
```
### V1.0 Examples
### V1.0 Examples
#### rbmi
Expand Down
19 changes: 18 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ inputs:
`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.
Expand All @@ -38,6 +45,10 @@ 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 Down Expand Up @@ -86,6 +97,7 @@ runs:
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

Expand All @@ -94,12 +106,17 @@ runs:
shell: bash

- name: Run report generator
run: ${GITHUB_ACTION_PATH}/report-generator.R
id: report-generator
run: |
${GITHUB_ACTION_PATH}/report-generator.R
filename=$(basename $(cat /tmp/report_file_path.txt))
echo "::set-output name=output-filename::${filename}"
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 }}
27 changes: 22 additions & 5 deletions report-generator.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ cat(sprintf("Current dir is: '%s'", getwd()))
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")
disable_install_dev_deps <- tolower(Sys.getenv("DISABLE_INSTALL_DEV_DEPS")) %in% c('yes', 'y', 't', 'true')
report_output_prefix <- Sys.getenv("INPUT_REPORT_OUTPUT_PREFIX", "")
disable_install_dev_deps <- tolower(
Sys.getenv("DISABLE_INSTALL_DEV_DEPS")
) %in% c("yes", "y", "t", "true")

# fail with meaningful message if REPORT_PKG_DIR does not appear to be a package
if (!file.exists(file.path(pkg_dir, "DESCRIPTION"))) {
desc_file <- file.path(pkg_dir, "DESCRIPTION")
if (!file.exists(desc_file)) {
stop(sprintf(
paste(sep = "\n",
"Could not find package at '%s'",
Expand All @@ -24,21 +28,34 @@ if (!file.exists(file.path(pkg_dir, "DESCRIPTION"))) {
}

# Install package dependencies
if (!disable_install_dev_deps){
if (!disable_install_dev_deps) {
options("remotes.git_credentials" = git2r::cred_user_pass(
username = "token",
password = remotes:::github_pat()
))
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 = "validation_report",
output_file = report_output_prefix,
output_format = report_format,
params = list(pkg_dir = pkg_dir)
)

cat(sprintf("Created report at: '%s'", report_file_path))
# 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))
2 changes: 1 addition & 1 deletion template.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ documentation of the installation of this package on an open source R environmen
- Traceability matrix of specifications (documented behaviours) and testing
- Risk assessment benchmarks

This report is fully automated, so is limited to assess whether unit tests and documentation are present and can execute without error. An assessment would be required that the tests and documentation are meaningful. Validation is system dependent, so specific to the validation environment environment used by this gh-action (see `https://github.com/insightsengineering/thevalidatoR/blob/main/Dockerfile` for the base dockerfile, and details in this document for the session info).
This report is fully automated, so is limited to assess whether unit tests and documentation are present and can execute without error. An assessment would be required that the tests and documentation are meaningful. Validation aims to be system independent as the underlying workflow is based on the ["composite"](https://docs.github.com/en/actions/creating-actions/creating-a-composite-action) type of Github Action.

# Installation environment and package

Expand Down

0 comments on commit 824c7d8

Please sign in to comment.