Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
sorinvoicu committed Feb 16, 2024
0 parents commit 17e6846
Show file tree
Hide file tree
Showing 21 changed files with 552 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
^dv.templates\.Rproj$
^\.Rproj\.user$
^.*\.Rproj$
^LICENSE\.md$
^LICENSE$
^\.github
_pkgdown.yml
workflows.md
45 changes: 45 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
name: Check 📦

on:
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
branches:
- main
push:
branches:
- main
workflow_call:

concurrency:
group: check-test-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
check-test:
name: ${{ vars.CI_IMAGE }}
runs-on: ubuntu-latest
container:
image: ${{ vars.CI_IMAGE }}

steps:
- name: Checkout project ⬇️
uses: actions/checkout@v4

- name: Check 📦
run: |
options(crayon.enabled = TRUE)
devtools::check(error_on="error", args=c("--no-tests"))
shell: Rscript {0}

- name: Test 🧪
if: >
!contains(github.event.commits[0].message, '[skip ci-tests]') && github.event.pull_request.draft == false
run: |
options(crayon.enabled = TRUE)
devtools::test()
shell: Rscript {0}
60 changes: 60 additions & 0 deletions .github/workflows/gitleaks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
name: Gitleaks 🌧️

on:
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
branches:
- main
push:
branches:
- main
workflow_call:
inputs:
gitleaks-version:
description: Gitleaks executable version.
required: false
type: string
default: "8.18.2"

concurrency:
group: gitleaks-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
gitleaks:
name: ${{ vars.CI_IMAGE }}
runs-on: ubuntu-latest
container:
image: ${{ vars.CI_IMAGE }}

steps:
- name: Checkout project ⬇️
uses: actions/checkout@v4

- name: Normalize inputs 📐
shell: bash
run: |
gitleaks_version_input="${{ inputs.gitleaks-version }}"
echo "GITLEAKS_VERSION=${gitleaks_version_input:-8.18.2}" >> $GITHUB_ENV
- name: Install gitleaks 💧
run: |
cd /tmp
wget -q \
"https://github.com/zricethezav/gitleaks/releases/download/v${GITLEAKS_VERSION}/gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz" \
-O gitleaks.tar.gz || \
(echo "Error downloading gitleaks ${GITLEAKS_VERSION} tarball" && exit 1)
tar -xvzf gitleaks.tar.gz || \
(echo "Error unarchiving gitleaks ${GITLEAKS_VERSION} tarball" && exit 1)
mv gitleaks /usr/bin/. || \
(echo "Error moving gitleaks for /usr/bin" && exit 1)
shell: bash

- name: Run gitleaks 🌧️
run: gitleaks -v detect --no-git --source .
shell: bash
43 changes: 43 additions & 0 deletions .github/workflows/lintr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
name: Lintr 🔍

on:
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
branches:
- main
push:
branches:
- main
workflow_call:
inputs:
lintr-error-on-lint:
description: Raise lintr error when lints found.
required: false
default: true
type: boolean

concurrency:
group: lint-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
lintr:
name: ${{ vars.CI_IMAGE }}
runs-on: ubuntu-latest
container:
image: ${{ vars.CI_IMAGE }}

steps:
- name: Checkout project ⬇️
uses: actions/checkout@v4

- name: Lintr 🔍
run: lintr::lint_package()
shell: Rscript {0}
env:
LINTR_ERROR_ON_LINT: ${{ inputs.lintr-error-on-lint }}
49 changes: 49 additions & 0 deletions .github/workflows/pkgdown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
name: Pkgdown 📖

on:
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
branches:
- main
push:
branches:
- main
workflow_call:

concurrency:
group: pkgdown-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
pkgdown:
name: ${{ vars.CI_IMAGE }}
runs-on: ubuntu-latest
container:
image: ${{ vars.CI_IMAGE }}

steps:
- name: Checkout project ⬇️
uses: actions/checkout@v4

- name: Build site 🔧
run: pkgdown::build_site()
shell: Rscript {0}

- name: Checkout gh-pages branch ⬇️
uses: actions/checkout@v4
with:
path: gh-pages
ref: gh-pages

- name: Deploy to GitHub pages 📰
if: (github.event_name == 'push') && (github.ref_name == 'main')
uses: JamesIves/[email protected]
with:
clean: true
branch: gh-pages
folder: docs
55 changes: 55 additions & 0 deletions .github/workflows/roxygen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
name: Roxygen 📄

on:
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
branches:
- main
push:
branches:
- main
workflow_call:

concurrency:
group: roxygen-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
roxygen:
name: ${{ vars.CI_IMAGE }}
runs-on: ubuntu-latest
container:
image: ${{ vars.CI_IMAGE }}

steps:
- name: Checkout project ⬇️
uses: actions/checkout@v4
with:
path: ${{ github.event.repository.name }}

- name: Generate man pages 📄
run: |
Rscript -e 'roxygen2::roxygenize()'
if [[ -n $(git status -s | grep -E "man|DESCRIPTION") ]]
then
ROXYGEN_VERSION="$(Rscript -e 'packageVersion("roxygen2")' | awk '{print $NF}')"
echo "⚠️ Manuals are not up-to-date with roxygen comments!"
echo "Here are the differences:"
git diff man/* DESCRIPTION
echo -e "\n Please rerun the following command on your workstation and push your changes"
echo "--------------------------------------------------------------------"
echo "roxygen2::roxygenize('.')"
echo "--------------------------------------------------------------------"
echo "ℹ️ roxygen2 version that was used in this workflow: $ROXYGEN_VERSION"
echo "Please ensure that the 'RoxygenNote' field in the DESCRIPTION file matches this version"
exit 1
else
echo "👍 Manuals are up-to-date with roxygen comments"
fi
shell: bash
working-directory: ${{ github.event.repository.name }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.Rproj.user
_snaps/
docs/
21 changes: 21 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Package: dv.templates
Title: Provides reusable functionality for R and CI/CD
Version: 0.0.0.9100
Authors@R: c(
person("Boehringer Ingelheim International GmbH", role = c("cph", "fnd")),
person("Sorin", "Voicu", , "[email protected]", role = c("aut", "cre"))
)
Description: Provides reusable functionality for R and CI/CD.
License: Apache License 2.0
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
Imports:
shiny,
stringr
Suggests:
knitr,
testthat (>= 2.0),
shinytest2
VignetteBuilder:
knitr
RoxygenNote: 7.3.0
13 changes: 13 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2024 Boehringer Ingelheim International GmbH

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Generated by roxygen2: do not edit by hand

export(hello)
export(run_app)
40 changes: 40 additions & 0 deletions R/hello.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#' Personal greeting
#'
#' @description Greet a person and appropriately capitalize their name.
#'
#' @param name Your name (character string; e.g. "john doe").
#'
#' @return A character string, capitalized to title case.
#' @export
#'
#' @examples
#' hello("james bond")
hello <- function(name = "your name") {
name <- stringr::str_to_title(name)
print(paste("Hello,", name))
}

#' Personal greeting as a Shiny app
#'
#' @description Greet a person and appropriately capitalize their name
#' as a Shiny app.
#'
#' @return Shiny app showcasing the personal greeting feature.
#' @export
#'
run_app <- function() {
ui <- shiny::fluidPage(
shiny::textInput("name", "What is your name?"),
shiny::actionButton("greet", "Greet"),
shiny::textOutput("greeting")
)

server <- function(input, output, session) {
output$greeting <- shiny::renderText({
shiny::req(input$greet)
hello(shiny::isolate(input$name))
})
}

shiny::shinyApp(ui, server)
}
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<img src="inst/repo-logo.svg" align="right" height="138" alt="" />

# dv.templates

[![Build status](https://github.com/boehringer-ingelheim/dv.templates/actions/workflows/check.yml/badge.svg)](https://github.com/boehringer-ingelheim/dv.templates/actions/workflows/check.yml?query=workflow)
[![Build status](https://github.com/boehringer-ingelheim/dv.templates/actions/workflows/gitleaks.yml/badge.svg)](https://github.com/boehringer-ingelheim/dv.templates/actions/workflows/gitleaks.yml?query=workflow)
[![Build status](https://github.com/boehringer-ingelheim/dv.templates/actions/workflows/lintr.yml/badge.svg)](https://github.com/boehringer-ingelheim/dv.templates/actions/workflows/lintr.yml?query=workflow)
[![Build status](https://github.com/boehringer-ingelheim/dv.templates/actions/workflows/pkgdown.yml/badge.svg)](https://github.com/boehringer-ingelheim/dv.templates/actions/workflows/pkgdown.yml?query=workflow)
[![Build status](https://github.com/boehringer-ingelheim/dv.templates/actions/workflows/roxygen.yml/badge.svg)](https://github.com/boehringer-ingelheim/dv.templates/actions/workflows/roxygen.yml?query=workflow)

An R package template with built-in GitHub Actions-based CI/CD workflows.

### Usage

All CI/CD jobs are defined in the [.github/workflows](https://github.com/boehringer-ingelheim/dv.templates/blob/main/.github/workflows) directory in the form of GitHub Action workflows. These can be modified per your requirements, but are designed and implemented to follow best practices and to ensure the highest quality standards for your package.

👉 For more information on workflows, please refer to the [Workflows documentation](./workflows.md).
9 changes: 9 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
url: https://boehringer-ingelheim.github.io/dv.templates/

template:
bootstrap: 5

navbar:
right:
- icon: fa-github
href: https://github.com/boehringer-ingelheim/dv.templates
Loading

0 comments on commit 17e6846

Please sign in to comment.