Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: New GHA checks for the case of missing suggested packages #1952

Merged
merged 10 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 119 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,122 @@ jobs:
- uses: ./.github/workflows/check
with:
results: ${{ runner.os }}-r${{ matrix.config.r }}

suggests-matrix:
runs-on: ubuntu-20.04
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}

name: Collect suggests deps

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: ./.github/workflows/rate-limit
with:
token: ${{ secrets.GITHUB_TOKEN }}

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

- id: set-matrix
uses: ./.github/workflows/dep-matrix-suggests

check-matrix:
runs-on: ubuntu-22.04
needs: suggests-matrix

name: Check deps

if: ${{ needs.matrix.outputs.matrix != '' }}

steps:
- name: Install json2yaml
run: |
sudo npm install -g json2yaml

- name: Check matrix definition
run: |
matrix='${{ needs.matrix.outputs.matrix }}'
echo $matrix
echo $matrix | jq .
echo $matrix | json2yaml

rcc-suggests:
needs:
- suggests-matrix
- rcc-smoke

runs-on: ubuntu-22.04

name: Without ${{ matrix.package }}

if: ${{ needs.suggests-matrix.outputs.matrix != '' }}

# Begin custom: services
# End custom: services

strategy:
fail-fast: false
matrix: ${{fromJson(needs.suggests-matrix.outputs.matrix)}}

steps:
- uses: actions/checkout@v3

- uses: ./.github/workflows/custom/before-install
if: hashFiles('.github/workflows/custom/before-install/action.yml') != ''

- uses: ./.github/workflows/install
with:
install-r: false
cache-version: rcc-dev-${{ matrix.package }}-1
needs: check
extra-packages: "any::rcmdcheck any::remotes ."
token: ${{ secrets.GITHUB_TOKEN }}

- name: Remove ${{ matrix.package }} and all strong dependencies
run: |
pkg <- "${{ matrix.package }}"
pkgs <- tools::package_dependencies(pkg, reverse = TRUE)[[1]]
installed <- rownames(utils::installed.packages())
to_remove <- c(pkg, intersect(pkgs, installed))
print(to_remove)
remove.packages(to_remove)
shell: Rscript {0}

- name: Session info
run: |
options(width = 100)
if (!requireNamespace("sessioninfo", quietly = TRUE)) install.packages("sessioninfo")
pkgs <- installed.packages()[, "Package"]
sessioninfo::session_info(pkgs, include_base = TRUE)
shell: Rscript {0}

- uses: ./.github/workflows/custom/after-install
if: hashFiles('.github/workflows/custom/after-install/action.yml') != ''

- name: Define _R_CHECK_FORCE_SUGGESTS_
run: |
cat('_R_CHECK_FORCE_SUGGESTS_=false\n', file = Sys.getenv("GITHUB_ENV"), append = TRUE)
shell: Rscript {0}

- name: Must allow NOTEs, even with _R_CHECK_FORCE_SUGGESTS_
run: |
if (Sys.getenv("RCMDCHECK_ERROR_ON") %in% c("", "note")) {
cat('RCMDCHECK_ERROR_ON="warning"\n', file = Sys.getenv("GITHUB_ENV"), append = TRUE)
}
shell: Rscript {0}

- name: Check env vars
run: |
print(Sys.getenv('_R_CHECK_FORCE_SUGGESTS_'))
print(Sys.getenv('RCMDCHECK_ERROR_ON'))
shell: Rscript {0}

- uses: ./.github/workflows/check
with:
results: ${{ matrix.package }}
56 changes: 56 additions & 0 deletions .github/workflows/dep-matrix-suggests/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: "Actions to compute a matrix with all suggested packages"
outputs:
matrix:
description: "Generated matrix"
value: ${{ steps.set-matrix.outputs.matrix }}

runs:
using: "composite"
steps:
- id: set-matrix
run: |
get_deps <- function() {
# Determine package dependencies
if (!requireNamespace("desc", quietly = TRUE)) {
install.packages("desc")
}

deps_df <- desc::desc_get_deps()
deps_df_optional <- deps_df$package[deps_df$type %in% c("Suggests", "Enhances")]
deps_df_hard <- deps_df$package[deps_df$type %in% c("Depends", "Imports", "LinkingTo")]

packages <- sort(deps_df_optional)
packages <- intersect(packages, rownames(available.packages()))

# Too big to fail, or can't be avoided:
off_limits <- c("testthat", "rmarkdown", "rcmdcheck", deps_df_hard)
off_limits_dep <- unlist(tools::package_dependencies(off_limits, recursive = TRUE, which = "strong"))
setdiff(packages, c(off_limits, off_limits_dep))
}

if (Sys.getenv("GITHUB_BASE_REF") != "") {
print(Sys.getenv("GITHUB_BASE_REF"))
diff <- system("git diff ${{ github.event.pull_request.base.sha }}... | egrep '^[+][^+]' | grep ::", intern = TRUE)
writeLines(diff)
if (length(diff) == 0) {
writeLines("No changes using :: found, not checking without suggested packages")
packages <- character()
} else {
packages <- get_deps()
}
} else {
packages <- get_deps()
}

if (length(packages) > 0) {
json <- paste0(
'{"package":[',
paste0('"', packages, '"', collapse = ","),
']}'
)
writeLines(json)
writeLines(paste0("matrix=", json), Sys.getenv("GITHUB_OUTPUT"))
} else {
writeLines("Package list empty!")
}
shell: Rscript {0}