Skip to content

Commit

Permalink
ci: Refactor dep-suggests-matrix, avoid killing base and recommended …
Browse files Browse the repository at this point in the history
…packages
  • Loading branch information
krlmlr committed Aug 2, 2024
1 parent 40b7d25 commit 6da8130
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 57 deletions.
1 change: 1 addition & 0 deletions .github/dep-suggests-matrix.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"package":["bit64","DBI","debugme","DiagrammeR","dplyr","formattable","ggplot2","lubridate","nanotime","nycflights13","palmerpenguins","scales","stringi","units","vdiffr"]}
5 changes: 4 additions & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ jobs:
- uses: ./.github/workflows/versions-matrix
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository

- uses: ./.github/workflows/dep-suggests-matrix
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository

- uses: ./.github/workflows/update-snapshots
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository

Expand Down Expand Up @@ -212,7 +215,7 @@ jobs:
use-public-rspm: true

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

check-suggests-matrix:
runs-on: ubuntu-22.04
Expand Down
56 changes: 0 additions & 56 deletions .github/workflows/dep-matrix-suggests/action.yml

This file was deleted.

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

runs:
using: "composite"
steps:
- name: Install json2yaml
run: |
sudo npm install -g json2yaml
shell: bash

- id: set-matrix
run: |
matrix=$(cat .github/dep-suggests-matrix.json || echo '{"package":[]}')
echo $matrix | jq .
echo $matrix | json2yaml
echo "matrix=$matrix" | tee -a $GITHUB_OUTPUT
shell: bash
42 changes: 42 additions & 0 deletions .github/workflows/dep-suggests-matrix/action.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# FIXME: Dynamic lookup by parsing https://svn.r-project.org/R/tags/
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")]
deps_df_base <- unlist(tools::standard_package_names(), use.names = FALSE)

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, deps_df_base)
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"))
has_diff <- (system("git diff ${{ github.event.pull_request.base.sha }}... | egrep '^[+][^+]' | grep -q ::") == 0)
if (has_diff) {
system("git diff ${{ github.event.pull_request.base.sha }}... | egrep '^[+][^+]' | grep -q ::")
packages <- get_deps()
} else {
writeLines("No changes using :: found, not checking without suggested packages")
packages <- character()
}
} else {
packages <- get_deps()
}

json <- paste0(
'{"package":[',
if (length(packages) > 0) paste0('"', packages, '"', collapse = ","),
']}'
)
writeLines(json, ".github/dep-suggests-matrix.json")
writeLines(json)
13 changes: 13 additions & 0 deletions .github/workflows/dep-suggests-matrix/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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: |
Rscript ./.github/workflows/dep-suggests-matrix/action.R
shell: bash

0 comments on commit 6da8130

Please sign in to comment.