Skip to content

Commit

Permalink
First open-source commit
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau-lilly committed Feb 27, 2024
0 parents commit c014dbb
Show file tree
Hide file tree
Showing 30 changed files with 868 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
^LICENSE\.md$
^.*\.Rproj$
^\.Rproj\.user$
^main$
^pull_request$
^packages\.json$
^\.lintr$
^\.git$
^\.github$
^_pkgdown\.yml$
^docs$
^pkgdown$
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
38 changes: 38 additions & 0 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
on:
push:
branches: [main]
pull_request:
branches: [main]

name: check

jobs:
check:
runs-on: ubuntu-latest

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check

- name: Git config
run: |
git config --global user.email "actions@github.com"
git config --global user.name "GitHub Actions"
- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
30 changes: 30 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
on:
push:
branches: [main]
pull_request:
branches: [main]

name: lint

jobs:
lint:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::lintr
needs: lint

- name: Lint
run: lintr::lint_package()
shell: Rscript {0}
env:
LINTR_ERROR_ON_LINT: true
48 changes: 48 additions & 0 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
release:
types: [published]
workflow_dispatch:

name: pkgdown

jobs:
pkgdown:
runs-on: ubuntu-latest
# Only restrict concurrency for non-PR jobs
concurrency:
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::pkgdown, local::.
needs: website

- name: Build site
run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
shell: Rscript {0}

- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/github-pages-deploy-action@v4.5.0
with:
clean: false
branch: gh-pages
folder: docs
50 changes: 50 additions & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: test-coverage

jobs:
test-coverage:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr
needs: coverage

- name: Test coverage
run: |
covr::codecov(
quiet = FALSE,
clean = FALSE,
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
)
shell: Rscript {0}

- name: Show testthat output
if: always()
run: |
## --------------------------------------------------------------------
find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v4
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
docs
6 changes: 6 additions & 0 deletions .lintr
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
linters: linters_with_defaults(
infix_spaces_linter = NULL,
object_length_linter = NULL,
object_name_linter = NULL,
object_usage_linter = NULL)
exclusions: list("inst/pipelines/use_targets.R", "R/class_database.R")
31 changes: 31 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Package: r.releases.utils
Title: Utilities for An R Universe of Package Releases
Description: Utilities for an R universe of package releases.
Version: 0.0.0.9000
License: MIT + file LICENSE
URL:
https://r-releases.github.io/r.releases.utils/,
https://github.com/r-releases/r.releases.utils
BugReports: https://github.com/r-releases/r.releases.utils/issues
Authors@R: c(
person(
given = c("William", "Michael"),
family = "Landau",
role = c("aut", "cre"),
email = "will.landau.oss@gmail.com",
comment = c(ORCID = "0000-0003-1878-3253")
),
person(
family = "Eli Lilly and Company",
role = "cph"
))
Depends:
R (>= 3.5.0)
Imports:
gh,
jsonlite
Encoding: UTF-8
Language: en-US
Config/testthat/edition: 3
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
2 changes: 2 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
YEAR: 2024
COPYRIGHT HOLDER: Eli Lilly and Company
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# MIT License

Copyright (c) 2024 Eli Lilly and Company

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
8 changes: 8 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Generated by roxygen2: do not edit by hand

export(assert_package)
export(build_universe)
export(review_pull_request)
export(review_pull_requests)
importFrom(gh,gh)
importFrom(jsonlite,read_json)
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# r.releases.utils 0.0.0.9000 (development)

* First version.
43 changes: 43 additions & 0 deletions R/assert_package.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#' @title Validate a package entry.
#' @export
#' @keywords internal
#' @description Validate a package entry.
#' @return An character string if there is a problem with the package entry,
#' otherwise `NULL` if there are no issues.
assert_package <- function(path) {
if (!is_character_scalar(path)) {
return("Invalid package file path.")
}
if (!file.exists(path)) {
return(paste("file", shQuote(path), "does not exist."))
}
name <- basename(path)
url <- try(readLines(path, warn = FALSE), silent = TRUE)
if (inherits(url, "try-error")) {
return(paste("Problem reading file", shQuote(path)))
}
assert_package_contents(name = name, url = url)
}

assert_package_contents <- function(name, url) {
good_package_name <- grepl(
pattern = "^[a-zA-Z][a-zA-Z0-9.]*[a-zA-Z0-9]$",
x = name
)
if (!isTRUE(good_package_name)) {
return(paste("Found invalid package name: ", shQuote(name)))
}
if (!is_character_scalar(url)) {
return("Invalid package URL.")
}
good_url <- grepl(
pattern = "^https?://[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,3}(/\\S*)?$",
x = url
)
if (!isTRUE(good_url)) {
return(
paste("Found malformed URL", shQuote(url), "of package", shQuote(name))
)
}
NULL
}
39 changes: 39 additions & 0 deletions R/build_universe.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#' @title Build the universe.
#' @export
#' @keywords internal
#' @description Create the `r-universe` `packages.json` file
#' from constituent text files with URLs.
#' @return NULL (invisibly)
#' @param input Character of length 1, directory path with the
#' text file listings of R releases.
#' @param output Character of length 1, file path where the
#' `r-universe` `packages.json` file will be written.
build_universe <- function(input = getwd(), output = "packages.json") {
assert_character_scalar(input, "invalid input")
assert_character_scalar(output, "invalid output")
assert_file(input)
packages <- list.files(input, all.files = FALSE, full.names = TRUE)
for (package in packages) {
result <- assert_package(package)
if (!is.null(result)) {
stop(result, call. = FALSE)
}
}
urls <- vapply(
X = packages,
FUN = readLines,
FUN.VALUE = character(1L),
USE.NAMES = FALSE,
warn = FALSE
)
out <- data.frame(
package = basename(packages),
url = urls,
branch = "*release"
)
if (!file.exists(dirname(output))) {
dir.create(dirname(output))
}
jsonlite::write_json(x = out, path = output)
invisible()
}
7 changes: 7 additions & 0 deletions R/package.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#' r.releases.utils: Utilities for an R universe of package releases.
#' @description Utilities for an R universe of package releases..
#' @name r.releases.utils-package
#' @family help
#' @importFrom gh gh
#' @importFrom jsonlite read_json
NULL
Loading

0 comments on commit c014dbb

Please sign in to comment.